<!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>
