tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_notification_serviceworker_show.html (1803B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test showNotification called within service 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_show_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("Showing notification");
     25  await NotificationTest.allowNotifications();
     26  let messagePromise = new Promise(r => navigator.serviceWorker.addEventListener("message", r, { once: true }));
     27  swr.active.postMessage("show");
     28  ok((await messagePromise).data.shown);
     29 
     30  await GleanTest.flush();
     31  let permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
     32  is(permissionCount, 1, "Notification first party show attempt counter should increment once.");
     33 
     34  info("Denying notification");
     35  await NotificationTest.denyNotifications();
     36  messagePromise = new Promise(r => navigator.serviceWorker.addEventListener("message", r, { once: true }));
     37  swr.active.postMessage("show");
     38  ok(!(await messagePromise).data.shown);
     39 
     40  await GleanTest.flush();
     41  permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
     42  is(permissionCount, 2, "Notification first party show attempt counter should increment once more.");
     43 });
     44 </script>
     45 </pre>
     46 </body>
     47 </html>