tor-browser

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

browser_subframesPreferUsed.js (2408B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 ok(
      5  Services.appinfo.fissionAutostart,
      6  "this test requires fission to function!"
      7 );
      8 
      9 function documentURL(origin, html) {
     10  let params = new URLSearchParams();
     11  params.append("html", html.trim());
     12  return `${origin}/document-builder.sjs?${params.toString()}`;
     13 }
     14 
     15 async function singleTest(preferUsed) {
     16  info(`running test with preferUsed=${preferUsed}`);
     17  await SpecialPowers.pushPrefEnv({
     18    set: [
     19      ["dom.ipc.processCount.webIsolated", 4],
     20      ["browser.tabs.remote.subframesPreferUsed", preferUsed],
     21    ],
     22  });
     23 
     24  const TEST_URL = documentURL(
     25    "https://example.com",
     26    `<iframe src=${JSON.stringify(
     27      documentURL("https://example.org", `<h1>iframe</h1>`)
     28    )}></iframe>`
     29  );
     30 
     31  await BrowserTestUtils.withNewTab(TEST_URL, async browser1 => {
     32    is(browser1.browsingContext.children.length, 1);
     33    let topProc1 = browser1.browsingContext.currentWindowGlobal.domProcess;
     34    let frameProc1 =
     35      browser1.browsingContext.children[0].currentWindowGlobal.domProcess;
     36    isnot(
     37      topProc1.childID,
     38      frameProc1.childID,
     39      "the frame should be in a separate process"
     40    );
     41 
     42    await BrowserTestUtils.withNewTab(TEST_URL, async browser2 => {
     43      is(browser2.browsingContext.children.length, 1);
     44      let topProc2 = browser2.browsingContext.currentWindowGlobal.domProcess;
     45      let frameProc2 =
     46        browser2.browsingContext.children[0].currentWindowGlobal.domProcess;
     47      isnot(
     48        topProc2.childID,
     49        frameProc2.childID,
     50        "the frame should be in a separate process"
     51      );
     52 
     53      // Compare processes used for the two tabs.
     54      isnot(
     55        topProc1.childID,
     56        topProc2.childID,
     57        "the toplevel windows should be loaded in separate processes"
     58      );
     59      if (preferUsed) {
     60        is(
     61          frameProc1.childID,
     62          frameProc2.childID,
     63          "the iframes should load in the same process with subframesPreferUsed"
     64        );
     65      } else {
     66        isnot(
     67          frameProc1.childID,
     68          frameProc2.childID,
     69          "the iframes should load in different processes without subframesPreferUsed"
     70        );
     71      }
     72    });
     73  });
     74 }
     75 
     76 add_task(async function test_preferUsed() {
     77  await singleTest(true);
     78 });
     79 
     80 add_task(async function test_noPreferUsed() {
     81  await singleTest(false);
     82 });