test_notification_swr_worker_show.html (1893B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Test showNotification called within dedicated worker</title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <script src="NotificationTest.js"></script> 6 <script src="/tests/SimpleTest/GleanTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 <p id="display"></p> 9 <div id="content" style="display: none"></div> 10 <pre id="test"></pre> 11 <script> 12 add_task(async function test() { 13 await GleanTest.testResetFOG(); 14 15 info("Registering service worker"); 16 let swr = await navigator.serviceWorker.register("notification_empty_sw.js"); 17 await navigator.serviceWorker.ready; 18 19 SimpleTest.registerCleanupFunction(async () => { 20 await swr.unregister(); 21 navigator.serviceWorker.onmessage = null; 22 }); 23 24 info("Starting worker that will try and show the notification"); 25 let worker = new Worker("notification_show_dedicated.js"); 26 27 info("Showing notification"); 28 await NotificationTest.allowNotifications(); 29 let messagePromise = new Promise(r => worker.addEventListener("message", r, { once: true })); 30 worker.postMessage("show"); 31 ok((await messagePromise).data.shown); 32 33 await GleanTest.flush(); 34 let permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue(); 35 is(permissionCount, 1, "Notification first party show attempt counter should increment once."); 36 37 info("Denying notification"); 38 await NotificationTest.denyNotifications(); 39 messagePromise = new Promise(r => worker.addEventListener("message", r, { once: true })); 40 worker.postMessage("show"); 41 ok(!(await messagePromise).data.shown); 42 43 await GleanTest.flush(); 44 permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue(); 45 is(permissionCount, 2, "Notification first party show attempt counter should increment once more."); 46 }); 47 </script> 48 </pre> 49 </body> 50 </html>