tor-browser

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

browser_permissionsCrossOrigin.js (1707B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 const emptyURL =
      7  "https://example.com/browser/dom/quota/test/browser/empty.html";
      8 
      9 addTest(async function testNoPermissionPrompt() {
     10  registerPopupEventHandler("popupshowing", function () {
     11    ok(false, "Shouldn't show a popup this time");
     12  });
     13  registerPopupEventHandler("popupshown", function () {
     14    ok(false, "Shouldn't show a popup this time");
     15  });
     16  registerPopupEventHandler("popuphidden", function () {
     17    ok(false, "Shouldn't show a popup this time");
     18  });
     19 
     20  info("Creating tab");
     21 
     22  await BrowserTestUtils.withNewTab(emptyURL, async function (browser) {
     23    await new Promise(r => {
     24      SpecialPowers.pushPrefEnv(
     25        {
     26          set: [
     27            ["dom.security.featurePolicy.header.enabled", true],
     28            ["dom.security.featurePolicy.webidl.enabled", true],
     29          ],
     30        },
     31        r
     32      );
     33    });
     34 
     35    await SpecialPowers.spawn(browser, [], async function (host0) {
     36      let frame = content.document.createElement("iframe");
     37      // Cross origin src
     38      frame.src = "https://example.org/browser/dom/quota/test/empty.html";
     39      content.document.body.appendChild(frame);
     40      await ContentTaskUtils.waitForEvent(frame, "load");
     41 
     42      await content.SpecialPowers.spawn(frame, [], async function () {
     43        // Request a permission.
     44        const persistAllowed = await this.content.navigator.storage.persist();
     45        Assert.ok(
     46          !persistAllowed,
     47          "navigator.storage.persist() has been denied"
     48        );
     49      });
     50      content.document.body.removeChild(frame);
     51    });
     52  });
     53 
     54  unregisterAllPopupEventHandlers();
     55 });