dom/notification/test/mochitest/test_notification_crossorigin_iframe.html
author Ehsan Akhgari <ehsan@mozilla.com>
Fri, 16 Aug 2019 01:07:36 +0300
changeset 488363 9bee211ea1fa598a01d70db6c6535bfd96302227
parent 488358 476c9068a66937becf5950a0eb4829e981d6a723
permissions -rw-r--r--
Bug 1574019 follow-up: Actually fix the ESLint error CLOSED TREE Differential Revision: https://phabricator.services.mozilla.com//D42215

<!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.setBoolPref("notification.prompt.testing", true);
    await SpecialPowers.setBoolPref("notification.prompt.testing.allow", true);
    await SpecialPowers.setBoolPref("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) => {
      /* import-globals-from ../../../../testing/modules/Assert.jsm */
      let response = await this.content.Notification.requestPermission();
      Assert.equal(response, expectedResponse, msg);
    };

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

    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.clearUserPref("notification.prompt.testing");
    await SpecialPowers.clearUserPref("notification.prompt.testing.allow");
    await SpecialPowers.clearUserPref("dom.webnotifications.allowinsecure");

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