summaryrefslogtreecommitdiffstats
path: root/dom/notification/test/mochitest/test_notification_insecure_context.html
blob: cd3a22bc7fd226c024cb47b0a4e53ed5261d3006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE HTML>
<html>
<!--
Tests that Notification permissions are denied in insecure context.
https://bugzilla.mozilla.org/show_bug.cgi?id=1429432
-->
<head>
  <title>Notification permission in insecure context</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
  <p id="display"></p>
  <div id="content" style="display: none">
  </div>
  <pre id="test">
  <script class="testbody" type="text/javascript">
  SimpleTest.waitForExplicitFinish();

  // Add an allow permission for the mochitest origin to test this.
  let script = SpecialPowers.loadChromeScript(function() {
    /* eslint-env mozilla/chrome-script */
    let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin("http://mochi.test:8888");
    Services.perms.addFromPrincipal(principal, "desktop-notification", Services.perms.ALLOW_ACTION);
    addMessageListener("destroy", function() {
      Services.perms.removeFromPrincipal(principal, "desktop-notification");
    });
  });

  (async function runTest() {
    let response = await Notification.requestPermission();
    is(response, "denied", "Denied permission in insecure context");

    await SpecialPowers.pushPrefEnv({"set": [["dom.webnotifications.allowinsecure", true]]});

    response = await Notification.requestPermission();
    is(response, "granted", "Granted permission in insecure context with pref set");

    script.sendAsyncMessage("destroy");
    script.destroy();

    SimpleTest.finish();
  })();
  </script>
  </pre>
</body>
</html>