2018-05-08 16:18:08 +03:00
|
|
|
function getBaseNumberOfProcesses() {
|
|
|
|
// We should have three processes for this test, the parent process and two
|
|
|
|
// content processes for the tabs craeted by this test.
|
|
|
|
let processCount = 3;
|
|
|
|
|
|
|
|
// If we run WebExtensions out-of-process (see bug 1190679), there might be
|
|
|
|
// additional processes for those, so let's add these to the base count to
|
|
|
|
// not have system WebExtensions cause test failures.
|
|
|
|
for (let i = 0; i < Services.ppmm.childCount; i++) {
|
|
|
|
if (Services.ppmm.getChildAt(i).remoteType === E10SUtils.EXTENSION_REMOTE_TYPE) {
|
|
|
|
processCount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return processCount;
|
|
|
|
}
|
|
|
|
|
2017-07-06 01:44:23 +03:00
|
|
|
function checkBaseProcessCount(description) {
|
2018-05-08 16:18:08 +03:00
|
|
|
const baseProcessCount = getBaseNumberOfProcesses();
|
2018-03-01 22:19:56 +03:00
|
|
|
const {childCount} = Services.ppmm;
|
2017-07-06 01:44:23 +03:00
|
|
|
// With preloaded activity-stream, process count is a bit undeterministic, so
|
|
|
|
// allow for some variation
|
2018-05-08 16:18:08 +03:00
|
|
|
const extraCount = baseProcessCount + 1;
|
|
|
|
ok(childCount === baseProcessCount || childCount === extraCount, `${description} (${baseProcessCount} or ${extraCount})`);
|
2017-07-06 01:44:23 +03:00
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
function processScript() {
|
2018-03-01 22:19:56 +03:00
|
|
|
if (Services.cpmm !== this) {
|
2015-02-20 04:13:02 +03:00
|
|
|
dump("Test failed: wrong global object\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
this.cpmm = Services.cpmm;
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
addMessageListener("ProcessTest:Reply", function listener(msg) {
|
|
|
|
removeMessageListener("ProcessTest:Reply", listener);
|
|
|
|
sendAsyncMessage("ProcessTest:Finished");
|
|
|
|
});
|
|
|
|
sendSyncMessage("ProcessTest:Loaded");
|
|
|
|
}
|
2018-08-04 00:33:38 +03:00
|
|
|
var processScriptURL = "data:,(" + processScript.toString() + ").call(this)";
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
function initTestScript() {
|
|
|
|
let init = initialProcessData;
|
|
|
|
if (init.test123 != "hello") {
|
|
|
|
dump("Initial data incorrect\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("ProcessTest:InitGood", init.test456.get("hi"));
|
|
|
|
}
|
2015-09-15 21:19:45 +03:00
|
|
|
var initTestScriptURL = "data:,(" + initTestScript.toString() + ")()";
|
2015-05-01 04:20:51 +03:00
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
var checkProcess = async function(mm) {
|
|
|
|
let { target } = await promiseMessage(mm, "ProcessTest:Loaded");
|
2015-03-06 03:13:02 +03:00
|
|
|
target.sendAsyncMessage("ProcessTest:Reply");
|
2017-06-22 13:51:42 +03:00
|
|
|
await promiseMessage(target, "ProcessTest:Finished");
|
2015-03-06 03:13:02 +03:00
|
|
|
ok(true, "Saw process finished");
|
2017-06-22 13:51:42 +03:00
|
|
|
};
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2015-03-06 03:13:02 +03:00
|
|
|
function promiseMessage(messageManager, message) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let listener = (msg) => {
|
|
|
|
messageManager.removeMessageListener(message, listener);
|
|
|
|
resolve(msg);
|
|
|
|
};
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2015-03-06 03:13:02 +03:00
|
|
|
messageManager.addMessageListener(message, listener);
|
|
|
|
})
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function(){
|
2017-05-03 13:00:20 +03:00
|
|
|
// We want to count processes in this test, so let's disable the pre-allocated process manager.
|
2017-06-22 13:51:42 +03:00
|
|
|
await SpecialPowers.pushPrefEnv({"set": [
|
2017-05-03 13:00:20 +03:00
|
|
|
["dom.ipc.processPrelaunch.enabled", false],
|
|
|
|
]});
|
|
|
|
})
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function(){
|
2017-02-21 13:27:27 +03:00
|
|
|
// This test is only relevant in e10s.
|
|
|
|
if (!gMultiProcessBrowser)
|
|
|
|
return;
|
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
Services.ppmm.releaseCachedProcesses();
|
2017-02-21 13:27:27 +03:00
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
await SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 5]]})
|
|
|
|
await SpecialPowers.pushPrefEnv({"set": [["dom.ipc.keepProcessesAlive.web", 5]]})
|
2017-02-21 13:27:27 +03:00
|
|
|
|
|
|
|
let tabs = [];
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2017-06-22 13:51:42 +03:00
|
|
|
tabs[i] = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
2017-02-21 13:27:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2018-03-19 05:16:49 +03:00
|
|
|
// FIXME: This should wait for the tab removal gets reflected to the
|
|
|
|
// process count (bug 1446726).
|
|
|
|
let sessionStorePromise = BrowserTestUtils.waitForSessionStoreUpdate(tabs[i]);
|
|
|
|
BrowserTestUtils.removeTab(tabs[i]);
|
|
|
|
await sessionStorePromise;
|
2017-02-21 13:27:27 +03:00
|
|
|
}
|
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
Services.ppmm.releaseCachedProcesses();
|
2017-07-06 01:44:23 +03:00
|
|
|
checkBaseProcessCount("Should get back to the base number of processes at this point");
|
2017-02-21 13:27:27 +03:00
|
|
|
})
|
|
|
|
|
2015-03-06 03:13:02 +03:00
|
|
|
// Test that loading a process script loads in all existing processes
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function() {
|
2015-03-06 03:13:02 +03:00
|
|
|
let checks = [];
|
2018-03-01 22:19:56 +03:00
|
|
|
for (let i = 0; i < Services.ppmm.childCount; i++)
|
|
|
|
checks.push(checkProcess(Services.ppmm.getChildAt(i)));
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
Services.ppmm.loadProcessScript(processScriptURL, false);
|
2017-06-22 13:51:42 +03:00
|
|
|
await Promise.all(checks);
|
2015-03-06 03:13:02 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Test that loading a process script loads in new processes
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function() {
|
2015-03-06 03:13:02 +03:00
|
|
|
// This test is only relevant in e10s
|
|
|
|
if (!gMultiProcessBrowser)
|
|
|
|
return;
|
|
|
|
|
2017-07-06 01:44:23 +03:00
|
|
|
checkBaseProcessCount("Should still be at the base number of processes at this point");
|
2015-03-06 03:13:02 +03:00
|
|
|
|
|
|
|
// Load something in the main process
|
2018-08-29 17:47:29 +03:00
|
|
|
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "about:robots");
|
2017-06-22 13:51:42 +03:00
|
|
|
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
let init = Services.ppmm.initialProcessData;
|
2015-05-01 04:20:51 +03:00
|
|
|
init.test123 = "hello";
|
|
|
|
init.test456 = new Map();
|
|
|
|
init.test456.set("hi", "bye");
|
|
|
|
|
2015-03-06 03:13:02 +03:00
|
|
|
// With no remote frames left we should be down to one process.
|
|
|
|
// However, stuff like remote thumbnails can cause a content
|
|
|
|
// process to exist nonetheless. This should be rare, though,
|
|
|
|
// so the test is useful most of the time.
|
2018-03-01 22:19:56 +03:00
|
|
|
if (Services.ppmm.childCount == 2) {
|
|
|
|
let mainMM = Services.ppmm.getChildAt(0);
|
2015-05-01 04:20:51 +03:00
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
let check = checkProcess(Services.ppmm);
|
|
|
|
Services.ppmm.loadProcessScript(processScriptURL, true);
|
2015-03-06 03:13:02 +03:00
|
|
|
|
|
|
|
// The main process should respond
|
2017-06-22 13:51:42 +03:00
|
|
|
await check;
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
check = checkProcess(Services.ppmm);
|
2015-03-06 03:13:02 +03:00
|
|
|
// Reset the default browser to start a new child process
|
|
|
|
gBrowser.updateBrowserRemoteness(gBrowser.selectedBrowser, true);
|
2018-08-29 17:47:29 +03:00
|
|
|
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "about:blank");
|
2017-06-22 13:51:42 +03:00
|
|
|
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2017-07-06 01:44:23 +03:00
|
|
|
checkBaseProcessCount("Should be back to the base number of processes at this point");
|
2015-03-06 03:13:02 +03:00
|
|
|
|
|
|
|
// The new process should have responded
|
2017-06-22 13:51:42 +03:00
|
|
|
await check;
|
2015-03-06 03:13:02 +03:00
|
|
|
|
2018-03-01 22:19:56 +03:00
|
|
|
Services.ppmm.removeDelayedProcessScript(processScriptURL);
|
2015-05-01 04:20:51 +03:00
|
|
|
|
|
|
|
let childMM;
|
2018-03-01 22:19:56 +03:00
|
|
|
childMM = Services.ppmm.getChildAt(2);
|
2015-05-01 04:20:51 +03:00
|
|
|
|
|
|
|
childMM.loadProcessScript(initTestScriptURL, false);
|
2017-06-22 13:51:42 +03:00
|
|
|
let msg = await promiseMessage(childMM, "ProcessTest:InitGood");
|
2015-05-01 04:20:51 +03:00
|
|
|
is(msg.data, "bye", "initial process data was correct");
|
2015-03-06 03:13:02 +03:00
|
|
|
} else {
|
|
|
|
info("Unable to finish test entirely");
|
|
|
|
}
|
|
|
|
});
|