gecko-dev/dom/workers/test/serviceworkers/test_notificationclick.html
Andrew Sutherland ab9e8a3643 Bug 1378949 - Fix SW notification tests that assumed activated SW to wait for activation. r=bkelly
Bug 1378949 found test_notificationclick_focus.html timing out because the
ServiceWorker activation raced the creation of an iframe document that wanted
to be controlled by the serviceworker.

The documents that wanted to be controlled had a half-hearted attempt at
dealing with this by using navigator.serviceWorker.ready, but that would only
work if the SW's attempted to claim the clients if they already existed, which
they did not.

This patch cleans up the defective test and its sibling tests that follow the
same idioms.

--HG--
extra : source : fb699d88bb80f27fbfd4805afc2e8feaa55964e0
2017-09-15 16:05:16 -04:00

67 lines
2.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=916893
-->
<head>
<title>Bug 1114554 - Test ServiceWorkerGlobalScope.notificationclick event.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/dom/tests/mochitest/notification/MockServices.js"></script>
<script type="text/javascript" src="/tests/dom/tests/mochitest/notification/NotificationTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1114554">Bug 1114554</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script src="utils.js"></script>
<script type="text/javascript">
SimpleTest.requestFlakyTimeout("Mock alert service dispatches show and click events.");
function testFrame(src) {
var iframe = document.createElement("iframe");
iframe.src = src;
window.callback = function(result) {
window.callback = null;
document.body.removeChild(iframe);
iframe = null;
ok(result, "Got notificationclick event with correct data.");
MockServices.unregister();
registration.unregister().then(function() {
SimpleTest.finish();
});
};
document.body.appendChild(iframe);
}
var registration;
function runTest() {
MockServices.register();
navigator.serviceWorker.register("notificationclick.js", { scope: "notificationclick.html" }).then(function(reg) {
registration = reg;
return waitForState(reg.installing, 'activated');
}, function(e) {
ok(false, "registration should have passed!");
}).then(() => {
// Now that we know the document will be controlled, create the frame.
testFrame('notificationclick.html');
});
};
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["dom.webnotifications.workers.enabled", true],
["dom.webnotifications.serviceworker.enabled", true],
["notification.prompt.testing", true],
]}, runTest);
</script>
</body>
</html>