tor-browser

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

browser_data_document_crossOriginIsolated.js (2032B)


      1 "use strict";
      2 
      3 const DIRPATH = getRootDirectory(gTestPath).replace(
      4  "chrome://mochitests/content/",
      5  ""
      6 );
      7 const PATH = DIRPATH + "file_coop_coep.html";
      8 
      9 const ORIGIN = "https://test1.example.com";
     10 const URL = `${ORIGIN}/${PATH}`;
     11 
     12 add_task(async function () {
     13  await BrowserTestUtils.withNewTab(URL, async function (browser) {
     14    BrowserTestUtils.startLoadingURIString(browser, URL);
     15    await BrowserTestUtils.browserLoaded(browser);
     16 
     17    await SpecialPowers.spawn(browser, [ORIGIN], async origin => {
     18      is(
     19        content.window.origin,
     20        origin,
     21        `Opened a tab and navigated to ${origin}`
     22      );
     23 
     24      ok(
     25        content.window.crossOriginIsolated,
     26        `Should have been cross-origin-isolated env`
     27      );
     28 
     29      let hostIds = [];
     30      function createShadowDOMAndTriggerSlotChange(host) {
     31        var shadow = host.attachShadow({ mode: "closed" });
     32 
     33        let promise = new Promise(resolve => {
     34          shadow.addEventListener("slotchange", function () {
     35            hostIds.push(host.id);
     36            resolve();
     37          });
     38        });
     39 
     40        shadow.innerHTML = "<slot></slot>";
     41 
     42        host.appendChild(host.ownerDocument.createElement("span"));
     43 
     44        return promise;
     45      }
     46 
     47      let host1 = content.document.getElementById("host1");
     48 
     49      let dataDoc = content.document.implementation.createHTMLDocument();
     50      dataDoc.body.innerHTML = "<div id='host2'></div>";
     51      let host2 = dataDoc.body.firstChild;
     52 
     53      let host3 = content.document.getElementById("host3");
     54 
     55      let promises = [];
     56      promises.push(createShadowDOMAndTriggerSlotChange(host1));
     57      promises.push(createShadowDOMAndTriggerSlotChange(host2));
     58      promises.push(createShadowDOMAndTriggerSlotChange(host3));
     59 
     60      await Promise.all(promises);
     61 
     62      is(hostIds.length, 3, `Got 3 slot change events`);
     63      is(hostIds[0], "host1", `The first one was host1`);
     64      is(hostIds[1], "host2", `The second one was host2`);
     65      is(hostIds[2], "host3", `The third one was host3`);
     66    });
     67  });
     68 });