Bug 1329331 - Add tests for not leaving the Large-Allocation process when there are other toplevel windows, r=smaug
authorMichael Layzell <michael@thelayzells.com>
Tue, 10 Jan 2017 18:18:28 -0500
changeset 462255 8ca577abf6b536eba1292cdde4cd8c5c07366056
parent 462254 4269f1d5be3612f9d12c5999d1d707da6d3c8b00
child 462256 9d951b0e3ce23eb97920a6caf6a14dd68dbe9db7
push id41683
push userbmo:steffen.wilberg@web.de
push dateMon, 16 Jan 2017 21:50:32 +0000
reviewerssmaug
bugs1329331
milestone53.0a1
Bug 1329331 - Add tests for not leaving the Large-Allocation process when there are other toplevel windows, r=smaug MozReview-Commit-ID: JVM8SxleFe8
dom/tests/browser/browser.ini
dom/tests/browser/browser_largeAllocation.js
dom/tests/browser/test_largeAllocation.html
dom/tests/browser/test_largeAllocation2.html
dom/tests/browser/test_largeAllocation2.html^headers^
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -5,16 +5,18 @@ support-files =
   position.html
   test-console-api.html
   test_bug1004814.html
   worker_bug1004814.js
   geo_leak_test.html
   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]
 disabled = Does not reliably pass on 32-bit systems - bug 1314098
 skip-if = !e10s
 [browser_autofocus_background.js]
 [browser_autofocus_preference.js]
 [browser_bug396843.js]
--- a/dom/tests/browser/browser_largeAllocation.js
+++ b/dom/tests/browser/browser_largeAllocation.js
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * 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);
   return new Promise(resolve => {
     let topic = "ipc:content-created";
     function observer() {
       os.removeObserver(observer, topic);
       ok(true, "Expect process created");
@@ -39,22 +40,25 @@ function getPID(aBrowser) {
 
 add_task(function*() {
   // I'm terrible and put this set of tests into a single file, so I need a longer timeout
   requestLongerTimeout(2);
 
   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();
     yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
       content.document.location = TEST_URI;
     });
 
     // Wait for the new process to be created
@@ -63,17 +67,17 @@ add_task(function*() {
     let pid2 = yield getPID(aBrowser);
 
     isnot(pid1, pid2, "The pids should be different between the initial load and the new load");
   });
 
   // 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
     let stopExpectNoProcess = expectNoProcess();
 
     yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
       content.document.body.innerHTML = `<iframe src='${TEST_URI}'></iframe>`;
 
@@ -89,17 +93,17 @@ add_task(function*() {
 
     is(pid1, pid2, "The PID should not have changed");
 
     stopExpectNoProcess();
   });
 
   // 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
     let stopExpectNoProcess = expectNoProcess();
 
     let loaded = ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
       content.document.body.innerHTML = '<button>CLICK ME</button>';
 
@@ -123,17 +127,17 @@ add_task(function*() {
 
     is(pid1, pid2, "The PID should not have changed");
 
     stopExpectNoProcess();
   });
 
   // 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();
 
     yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
       content.document.location = TEST_URI;
     });
 
@@ -166,17 +170,17 @@ add_task(function*() {
     let pid4 = yield getPID(aBrowser);
 
     isnot(pid1, pid4);
     isnot(pid2, pid4);
   });
 
   // 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();
 
     yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
       content.document.location = TEST_URI;
     });
 
@@ -216,9 +220,81 @@ add_task(function*() {
     yield epc;
 
     let pid4 = yield getPID(aBrowser);
 
     isnot(pid1, pid4, "PID 4 shouldn't match PID 1");
     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]);
+  });
 });
--- a/dom/tests/browser/test_largeAllocation.html
+++ b/dom/tests/browser/test_largeAllocation.html
@@ -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>
copy from dom/tests/browser/test_largeAllocation.html
copy to dom/tests/browser/test_largeAllocation2.html
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/test_largeAllocation2.html^headers^
@@ -0,0 +1,1 @@
+Large-Allocation: 0
\ No newline at end of file