Bug 1139628 - Test (r=billm)

This commit is contained in:
Dave Townsend 2015-03-05 16:13:02 -08:00 committed by Bill McCloskey
parent d3467852f4
commit 3b3cd3ce42

View File

@ -18,27 +18,72 @@ function processScript() {
});
sendSyncMessage("ProcessTest:Loaded");
}
let processScriptURL = "data:,(" + processScript.toString() + ")()";
function test() {
waitForExplicitFinish();
let checkProcess = Task.async(function*(mm) {
let { target } = yield promiseMessage(mm, "ProcessTest:Loaded");
target.sendAsyncMessage("ProcessTest:Reply");
yield promiseMessage(target, "ProcessTest:Finished");
ok(true, "Saw process finished");
});
let replyCount = 0;
function promiseMessage(messageManager, message) {
return new Promise(resolve => {
let listener = (msg) => {
messageManager.removeMessageListener(message, listener);
resolve(msg);
};
function loadListener(msg) {
replyCount++;
msg.target.sendAsyncMessage("ProcessTest:Reply");
}
ppmm.addMessageListener("ProcessTest:Loaded", loadListener);
ppmm.addMessageListener("ProcessTest:Finished", function finishListener(msg) {
if (replyCount < ppmm.childCount) {
return;
}
info("Got " + replyCount + " replies");
ok(replyCount, "Got message reply");
ppmm.removeMessageListener("ProcessTest:Loaded", loadListener);
ppmm.removeMessageListener("ProcessTest:Finished", finishListener);
finish();
});
ppmm.loadProcessScript("data:,(" + processScript.toString() + ")()", true);
messageManager.addMessageListener(message, listener);
})
}
// Test that loading a process script loads in all existing processes
add_task(function*() {
let checks = [];
for (let i = 0; i < ppmm.childCount; i++)
checks.push(checkProcess(ppmm.getChildAt(i)));
ppmm.loadProcessScript(processScriptURL, false);
yield Promise.all(checks);
});
// Test that loading a process script loads in new processes
add_task(function*() {
// This test is only relevant in e10s
if (!gMultiProcessBrowser)
return;
is(ppmm.childCount, 2, "Should be two processes at this point");
// Load something in the main process
gBrowser.selectedBrowser.loadURI("about:robots");
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
// 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.
if (ppmm.childCount == 1) {
let check = checkProcess(ppmm);
ppmm.loadProcessScript(processScriptURL, true);
// The main process should respond
yield check;
check = checkProcess(ppmm);
// Reset the default browser to start a new child process
gBrowser.updateBrowserRemoteness(gBrowser.selectedBrowser, true);
gBrowser.selectedBrowser.loadURI("about:blank");
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
is(ppmm.childCount, 2, "Should be back to two processes at this point");
// The new process should have responded
yield check;
ppmm.removeDelayedProcessScript(processScriptURL);
} else {
info("Unable to finish test entirely");
}
});