summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_force_process_selector.js
blob: 15157b240d7b814f74ad3ec1c04c9219750201da (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
"use strict";

const CONTENT_CREATED = "ipc:content-created";

// Make sure that BTU.withNewTab({ ..., forceNewProcess: true }) loads
// new tabs in their own process.
async function spawnNewAndTest(recur, pids) {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: "about:blank", forceNewProcess: true },
    async function (browser) {
      // Make sure our new browser is in its own process.
      let newPid = browser.frameLoader.remoteTab.osPid;
      ok(!pids.has(newPid), "new tab is in its own process: " + recur);
      pids.add(newPid);

      if (recur) {
        await spawnNewAndTest(recur - 1, pids);
      } else {
        await BrowserTestUtils.withNewTab(
          { gBrowser, url: "about:blank" },
          function (lastBrowser) {
            let lastPid = lastBrowser.frameLoader.remoteTab.osPid;
            ok(pids.has(lastPid), "final tab cannot be in its own process");
          }
        );
      }
    }
  );
}

add_task(async function test() {
  let curPid = gBrowser.selectedBrowser.frameLoader.remoteTab.osPid;
  let maxCount = Services.prefs.getIntPref("dom.ipc.processCount");

  // Use at least one more tab than max processes or at least 5 to make this
  // test interesting.
  await spawnNewAndTest(Math.max(maxCount + 1, 5), new Set([curPid]));
});