tor-browser

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

browser_cross_origin_embed.js (2723B)


      1 "use strict";
      2 
      3 const TEST_PATH_COM = getRootDirectory(gTestPath).replace(
      4  "chrome://mochitests/content",
      5  "https://example.com"
      6 );
      7 const TEST_PATH_ORG = getRootDirectory(gTestPath).replace(
      8  "chrome://mochitests/content",
      9  "https://example.org"
     10 );
     11 
     12 const GEO_URL =
     13  "http://mochi.test:8888/tests/dom/geolocation/test/mochitest/network_geolocation.sjs";
     14 
     15 add_task(async () => {
     16  await SpecialPowers.pushPrefEnv({
     17    set: [
     18      ["geo.provider.network.url", GEO_URL],
     19      ["geo.timeout", 4000],
     20    ],
     21  });
     22 
     23  await BrowserTestUtils.withNewTab(
     24    TEST_PATH_COM + "empty.html",
     25    async browser => {
     26      let notificationPopup = document.getElementById("notification-popup");
     27      let notificationShown = BrowserTestUtils.waitForPopupEvent(
     28        notificationPopup,
     29        "shown"
     30      );
     31 
     32      const notificationHidden = BrowserTestUtils.waitForPopupEvent(
     33        notificationPopup,
     34        "hidden"
     35      );
     36 
     37      let res = SpecialPowers.spawn(browser, [], () => {
     38        return new Promise(resolve =>
     39          content.navigator.geolocation.getCurrentPosition(
     40            () => resolve("allowed"),
     41            () => resolve("disallowed")
     42          )
     43        );
     44      });
     45 
     46      await notificationShown;
     47      notificationPopup
     48        .querySelector("button.popup-notification-primary-button")
     49        .click();
     50 
     51      await notificationHidden;
     52 
     53      let result = await res;
     54      is(result, "allowed", "Geolocation allowed");
     55 
     56      BrowserTestUtils.startLoadingURIString(
     57        browser,
     58        TEST_PATH_COM + "empty.html"
     59      );
     60      await BrowserTestUtils.browserLoaded(browser);
     61 
     62      const bc = await SpecialPowers.spawn(
     63        browser,
     64        [TEST_PATH_ORG + "empty.html"],
     65        async url => {
     66          const { document } = content;
     67          const embed = document.createElement("embed");
     68          embed.src = url;
     69          const promise = new Promise(resolve => {
     70            embed.addEventListener("load", resolve, { once: true });
     71          });
     72          document.body.appendChild(embed);
     73          await promise;
     74          return embed.browsingContext;
     75        }
     76      );
     77 
     78      notificationShown = BrowserTestUtils.waitForPopupEvent(
     79        notificationPopup,
     80        "shown"
     81      );
     82 
     83      res = SpecialPowers.spawn(bc, [], () => {
     84        return new Promise(resolve =>
     85          content.navigator.geolocation.getCurrentPosition(
     86            () => resolve("allowed"),
     87            () => resolve("disallowed")
     88          )
     89        );
     90      });
     91 
     92      result = await Promise.race([
     93        res,
     94        notificationShown.then(_ => {
     95          return "notification shown";
     96        }),
     97      ]);
     98      is(result, "disallowed", "Geolocation disallowed");
     99    }
    100  );
    101 });