<!DOCTYPE HTML>
<html>
<!--
Tests that Notification permissions are denied in cross-origin iframes.
https://bugzilla.mozilla.org/show_bug.cgi?id=1560741
-->
<head>
  <title>Notification permission in cross-origin iframes</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();

  const kBlankURL = "https://example.com/tests/dom/notification/test/mochitest/blank.html";

  (async function runTest() {
    await SpecialPowers.pushPrefEnv({"set": [
      ["notification.prompt.testing", true],
      ["notification.prompt.testing.allow", true],
      ["dom.webnotifications.allowinsecure", true],
    ]});

    let iframe = document.createElement("iframe");
    iframe.src = kBlankURL;
    document.body.appendChild(iframe);
    await new Promise(resolve => {
      iframe.onload = resolve;
    });

    let checkRequest = async (expectedResponse, msg) => {
      let response = await this.content.Notification.requestPermission();
      Assert.equal(response, expectedResponse, msg);
    };

    await SpecialPowers.spawn(iframe,
                              ["denied", "Denied permission in cross-origin iframe"],
                              checkRequest);

    let checkPermission = async (expectedPermission, msg) => {
      let permission = this.content.Notification.permission;
      Assert.equal(permission, expectedPermission, msg);
    };

    await SpecialPowers.spawn(iframe,
                              ["denied", "Permission is denied in cross-origin iframe"],
                              checkPermission);

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

    await SpecialPowers.spawn(iframe,
                              ["granted", "Granted permission in cross-origin iframe with pref set"],
                              checkRequest);
    await SpecialPowers.spawn(iframe,
                              ["granted", "Permission is granted in cross-origin iframe with pref set"],
                              checkPermission);

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