Bug 1329331 - Add tests for not leaving the Large-Allocation process when there are other toplevel windows, r=smaug

MozReview-Commit-ID: JVM8SxleFe8


--HG--
rename : dom/tests/browser/test_largeAllocation.html => dom/tests/browser/test_largeAllocation2.html
This commit is contained in:
Michael Layzell 2017-01-10 18:18:28 -05:00
parent 3a272149c6
commit 32925494c4
5 changed files with 94 additions and 6 deletions

View File

@ -10,6 +10,8 @@ support-files =
dummy.html
test_largeAllocation.html
test_largeAllocation.html^headers^
test_largeAllocation2.html
test_largeAllocation2.html^headers^
!/dom/tests/mochitest/geolocation/network_geolocation.sjs
[browser_allocateGigabyte.js]

View File

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TEST_URI = "http://example.com/browser/dom/tests/browser/test_largeAllocation.html";
const TEST_URI_2 = "http://example.com/browser/dom/tests/browser/test_largeAllocation2.html";
function expectProcessCreated() {
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
@ -44,12 +45,15 @@ add_task(function*() {
yield SpecialPowers.pushPrefEnv({
set: [
["dom.largeAllocationHeader.enabled", true],
// Increase processCount.webLargeAllocation to avoid any races where
// processes aren't being cleaned up quickly enough.
["dom.ipc.processCount.webLargeAllocation", 20]
]
});
// A toplevel tab should be able to navigate cross process!
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
ok(true, "Starting test 0");
info("Starting test 0");
let pid1 = yield getPID(aBrowser);
let epc = expectProcessCreated();
@ -68,7 +72,7 @@ add_task(function*() {
// When a Large-Allocation document is loaded in an iframe, the header should
// be ignored, and the tab should stay in the current process.
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
ok(true, "Starting test 1");
info("Starting test 1");
let pid1 = yield getPID(aBrowser);
// Fail the test if we create a process
@ -94,7 +98,7 @@ add_task(function*() {
// If you have an opener cross process navigation shouldn't work
yield BrowserTestUtils.withNewTab("http://example.com", function*(aBrowser) {
ok(true, "Starting test 2");
info("Starting test 2");
let pid1 = yield getPID(aBrowser);
// Fail the test if we create a process
@ -128,7 +132,7 @@ add_task(function*() {
// Load Large-Allocation twice with about:blank load in between
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
ok(true, "Starting test 3");
info("Starting test 3");
let pid1 = yield getPID(aBrowser);
let epc = expectProcessCreated();
@ -171,7 +175,7 @@ add_task(function*() {
// Load Large-Allocation then about:blank load, then back button press should load from bfcache.
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
ok(true, "Starting test 4");
info("Starting test 4");
let pid1 = yield getPID(aBrowser);
let epc = expectProcessCreated();
@ -221,4 +225,76 @@ add_task(function*() {
isnot(pid2, pid4, "PID 4 shouldn't match PID 2");
});
// Two consecutive large-allocation loads should create two processes.
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
info("Starting test 5");
let pid1 = yield getPID(aBrowser);
let ready = Promise.all([expectProcessCreated(),
BrowserTestUtils.browserLoaded(aBrowser)]);
yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
yield ready;
let pid2 = yield getPID(aBrowser);
isnot(pid1, pid2, "PIDs 1 and 2 should not match");
let epc = expectProcessCreated();
yield ContentTask.spawn(aBrowser, TEST_URI_2, TEST_URI_2 => {
content.document.location = TEST_URI_2;
});
yield epc;
let pid3 = yield getPID(aBrowser);
isnot(pid1, pid3, "PIDs 1 and 3 should not match");
isnot(pid2, pid3, "PIDs 1 and 3 should not match");
});
// Opening a window from the large-allocation window should prevent the process switch.
yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
info("Starting test 6");
let pid1 = yield getPID(aBrowser);
let ready = Promise.all([expectProcessCreated(),
BrowserTestUtils.browserLoaded(aBrowser)]);
yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
yield ready;
let pid2 = yield getPID(aBrowser);
isnot(pid1, pid2, "PIDs 1 and 2 should not match");
yield BrowserTestUtils.synthesizeMouse("a", 0, 0, {}, aBrowser);
let stopExpectNoProcess = expectNoProcess();
yield ContentTask.spawn(aBrowser, null, () => {
content.document.location = "about:blank";
});
yield BrowserTestUtils.browserLoaded(aBrowser);
let pid3 = yield getPID(aBrowser);
is(pid3, pid2, "PIDs 2 and 3 should match");
stopExpectNoProcess();
is(gBrowser.tabs.length, 3, "There should be 3 tabs");
// Get rid of that other tab. It should always be the last one.
gBrowser.removeTab(gBrowser.tabs[2]);
});
});

View File

@ -1,4 +1,9 @@
<!doctype html>
<html>
<body>Loaded in a new process!</body>
<script>
function onClick() {
window.open("about:blank");
}
</script>
<body><a onclick="onClick()">clicky</a>Loaded in a new process!</body>
</html>

View File

@ -0,0 +1,4 @@
<!doctype html>
<html>
<body>Loaded in a new process!</body>
</html>

View File

@ -0,0 +1 @@
Large-Allocation: 0