tor-browser

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

test_notificationclick_focus.html (2006B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=916893
      5 -->
      6 <head>
      7  <title>Bug 1144660 - Test client.focus() permissions on notification click</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=1114554">Bug 1114554</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 and click 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(result) {
     29      window.callback = null;
     30      document.body.removeChild(iframe);
     31      iframe = null;
     32      ok(result, "All tests passed.");
     33      await registration.unregister();
     34      resolve();
     35    };
     36    document.body.appendChild(iframe);
     37    await promise;
     38  }
     39 
     40  add_task(async function runTest() {
     41    await SpecialPowers.pushPrefEnv({"set": [
     42      // notificationclick_focus depends on this value
     43      ["dom.webnotifications.disable_open_click_delay", 1000],
     44    ]});
     45    await NotificationTest.allowNotifications();
     46    await MockAlertsService.register();
     47    await MockAlertsService.enableAutoClick();
     48    let registration = await navigator.serviceWorker.register(
     49      "notificationclick_focus.serviceworker.js",
     50      { scope: "notificationclick_focus.html" }
     51    );
     52    await waitForState(registration.installing, 'activated');
     53    await testFrame('notificationclick_focus.html', registration);
     54  });
     55 </script>
     56 </body>
     57 </html>