test_notificationclose.html (1950B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1265841 5 --> 6 <head> 7 <title>Bug 1265841 - Test ServiceWorkerGlobalScope.notificationclose event.</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/dom/notification/test/mochitest/MockAlertsService.js"></script> 10 <script src="/tests/dom/notification/test/mochitest/NotificationTest.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1265841">Bug 1265841</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 </div> 18 <pre id="test"> 19 </pre> 20 <script src="/tests/dom/serviceworkers/test/utils.js"></script> 21 <script> 22 SimpleTest.requestFlakyTimeout("Mock alert service dispatches show, click, and close events."); 23 24 async function testFrame(src, registration) { 25 let { promise, resolve } = Promise.withResolvers(); 26 let iframe = document.createElement("iframe"); 27 iframe.src = src; 28 window.callback = async function(data) { 29 window.callback = null; 30 document.body.removeChild(iframe); 31 iframe = null; 32 ok(data.result, "Got notificationclose event with correct data."); 33 ok(!data.windowOpened, 34 "Shouldn't allow to openWindow in notificationclose"); 35 await registration.unregister(); 36 resolve(); 37 }; 38 document.body.appendChild(iframe); 39 await promise; 40 } 41 42 add_task(async function runTest() { 43 await NotificationTest.allowNotifications(); 44 await MockAlertsService.register(); 45 await MockAlertsService.enableAutoClick(); 46 let registration = await navigator.serviceWorker.register( 47 "notificationclose.serviceworker.js", 48 { scope: "notificationclose.html" } 49 ); 50 await waitForState(registration.installing, 'activated'); 51 await testFrame('notificationclose.html', registration); 52 }); 53 </script> 54 </body> 55 </html>