Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Bug 1114554 - Test ServiceWorkerGlobalScope.notificationclick event.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/dom/notification/test/mochitest/MockAlertsService.js"></script>
<script type="text/javascript" src="/tests/dom/notification/test/mochitest/NotificationTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script src="/tests/dom/serviceworkers/test/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 = async function(result) {
window.callback = null;
document.body.removeChild(iframe);
iframe = null;
ok(result, "Got notificationclick event with correct data.");
await registration.unregister();
SimpleTest.finish();
};
document.body.appendChild(iframe);
}
var registration;
async function runTest() {
try {
await NotificationTest.allowNotifications();
await MockAlertsService.register();
await MockAlertsService.enableAutoClick();
registration = await navigator.serviceWorker.register(
"notificationclick.js",
{ scope: "notificationclick.html" }
);
await waitForState(registration.installing, 'activated');
} catch (e) {
ok(false, "registration should have passed!");
SimpleTest.finish();
}
// 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],
]}, runTest);
</script>
</body>
</html>