tor-browser

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

test_notification_insecure_context.html (1368B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Tests that Notification permissions are denied in insecure context.
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=1429432
      6 -->
      7 <head>
      8  <title>Notification permission in insecure context</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13  <p id="display"></p>
     14  <div id="content" style="display: none">
     15  </div>
     16  <pre id="test">
     17  <script class="testbody" type="text/javascript">
     18  SimpleTest.waitForExplicitFinish();
     19 
     20  // Add an allow permission for the mochitest origin to test this.
     21  let script = SpecialPowers.loadChromeScript(function() {
     22    /* eslint-env mozilla/chrome-script */
     23    let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin("http://mochi.test:8888");
     24    Services.perms.addFromPrincipal(principal, "desktop-notification", Services.perms.ALLOW_ACTION);
     25    addMessageListener("destroy", function() {
     26      Services.perms.removeFromPrincipal(principal, "desktop-notification");
     27    });
     28  });
     29 
     30  (async function runTest() {
     31    let response = await Notification.requestPermission();
     32    is(response, "denied", "Denied permission in insecure context");
     33 
     34    script.sendAsyncMessage("destroy");
     35    script.destroy();
     36 
     37    SimpleTest.finish();
     38  })();
     39  </script>
     40  </pre>
     41 </body>
     42 </html>