summaryrefslogtreecommitdiffstats
path: root/dom/ipc/tests/browser_subframesPreferUsed.js
blob: f2f9ed25932ef3ae03a606bfc37fd585016b7594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

ok(
  Services.appinfo.fissionAutostart,
  "this test requires fission to function!"
);

function documentURL(origin, html) {
  let params = new URLSearchParams();
  params.append("html", html.trim());
  return `${origin}/document-builder.sjs?${params.toString()}`;
}

async function singleTest(preferUsed) {
  info(`running test with preferUsed=${preferUsed}`);
  await SpecialPowers.pushPrefEnv({
    set: [
      ["dom.ipc.processCount.webIsolated", 4],
      ["browser.tabs.remote.subframesPreferUsed", preferUsed],
    ],
  });

  const TEST_URL = documentURL(
    "https://example.com",
    `<iframe src=${JSON.stringify(
      documentURL("https://example.org", `<h1>iframe</h1>`)
    )}></iframe>`
  );

  await BrowserTestUtils.withNewTab(TEST_URL, async browser1 => {
    is(browser1.browsingContext.children.length, 1);
    let topProc1 = browser1.browsingContext.currentWindowGlobal.domProcess;
    let frameProc1 =
      browser1.browsingContext.children[0].currentWindowGlobal.domProcess;
    isnot(
      topProc1.childID,
      frameProc1.childID,
      "the frame should be in a separate process"
    );

    await BrowserTestUtils.withNewTab(TEST_URL, async browser2 => {
      is(browser2.browsingContext.children.length, 1);
      let topProc2 = browser2.browsingContext.currentWindowGlobal.domProcess;
      let frameProc2 =
        browser2.browsingContext.children[0].currentWindowGlobal.domProcess;
      isnot(
        topProc2.childID,
        frameProc2.childID,
        "the frame should be in a separate process"
      );

      // Compare processes used for the two tabs.
      isnot(
        topProc1.childID,
        topProc2.childID,
        "the toplevel windows should be loaded in separate processes"
      );
      if (preferUsed) {
        is(
          frameProc1.childID,
          frameProc2.childID,
          "the iframes should load in the same process with subframesPreferUsed"
        );
      } else {
        isnot(
          frameProc1.childID,
          frameProc2.childID,
          "the iframes should load in different processes without subframesPreferUsed"
        );
      }
    });
  });
}

add_task(async function test_preferUsed() {
  await singleTest(true);
});

add_task(async function test_noPreferUsed() {
  await singleTest(false);
});