Bug 1497901 - Make some tests work if Activity Stream runs in its own content process. r=Felipe
authorMike Conley <mconley@mozilla.com>
Thu, 11 Oct 2018 21:13:31 +0000
changeset 496519 71892e0c54f9f321fea9d02519522d278e014349
parent 496518 45bc3a854dd1484266c7da28d56e8baa6c54a8d8
child 496520 31eac8d65771c51c5e1a099e1a57dadcc98fc57a
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1497901
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497901 - Make some tests work if Activity Stream runs in its own content process. r=Felipe The separate Activity Stream content process is currently pref-able, and I'd like to make sure that the tree is green with it enabled and disabled. This patch makes it so that tests that browse from about:home/about:newtab to some other page or back work properly even if there are process flips. Based on work originally by Jay Lim (:imjching) <jay@imjching.com>. Differential Revision: https://phabricator.services.mozilla.com/D8265
browser/base/content/test/about/browser_aboutCertError.js
browser/base/content/test/about/head.js
browser/base/content/test/general/browser_bug724239.js
browser/base/content/test/general/browser_e10s_chrome_process.js
browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
--- a/browser/base/content/test/about/browser_aboutCertError.js
+++ b/browser/base/content/test/about/browser_aboutCertError.js
@@ -66,20 +66,23 @@ add_task(async function checkReturnToAbo
     info("Clicking the go back button on about:certerror");
     await ContentTask.spawn(browser, {frame: useFrame}, async function({frame}) {
       let doc = frame ? content.document.querySelector("iframe").contentDocument : content.document;
 
       let returnButton = doc.getElementById("returnButton");
       if (!frame) {
         is(returnButton.getAttribute("autofocus"), "true", "returnButton has autofocus");
       }
+      // Note that going back to about:newtab might cause a process flip, if
+      // the browser is configured to run about:newtab in its own special
+      // content process.
       returnButton.click();
+    });
 
-      await ContentTaskUtils.waitForEvent(this, "pageshow", true);
-    });
+    await BrowserTestUtils.waitForLocationChange(gBrowser, "about:home");
 
     is(browser.webNavigation.canGoBack, true, "webNavigation.canGoBack");
     is(browser.webNavigation.canGoForward, false, "!webNavigation.canGoForward");
     is(gBrowser.currentURI.spec, "about:home", "Went back");
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
   }
 });
--- a/browser/base/content/test/about/head.js
+++ b/browser/base/content/test/about/head.js
@@ -124,27 +124,54 @@ function waitForDocLoadAndStopIt(aExpect
      */
     addEventListener("unload", function() {
       try {
         wp.removeProgressListener(progressListener);
       } catch (e) { /* Will most likely fail. */ }
     });
   }
 
+  // We are deferring the setup of this promise because there is a possibility
+  // that a process flip will occur as we transition from page to page. This is
+  // a little convoluted because we have a very small window of time in which to
+  // send down the content_script frame script before the expected page actually
+  // loads. The best time to send down the script, it seems, is right after the
+  // TabRemotenessUpdate event.
+  //
+  // So, we abstract out the content_script handling into a helper stoppedDocLoadPromise
+  // promise so that we can account for the process flipping case, and jam in the
+  // content_script at just the right time in the TabRemotenessChange handler.
+  let stoppedDocLoadPromise = () => {
+    return new Promise((resolve, reject) => {
+      function complete({ data }) {
+        is(data.uri, aExpectedURL, "waitForDocLoadAndStopIt: The expected URL was loaded");
+        mm.removeMessageListener("Test:WaitForDocLoadAndStopIt", complete);
+        resolve();
+      }
+
+      let mm = aBrowser.messageManager;
+      mm.loadFrameScript("data:,(" + content_script.toString() + ")(" + aStopFromProgressListener + ");", true);
+      mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
+      info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
+    });
+  };
+
+  let win = aBrowser.ownerGlobal;
+  let tab = win.gBrowser.getTabForBrowser(aBrowser);
+  let { mustChangeProcess } = E10SUtils.shouldLoadURIInBrowser(aBrowser, aExpectedURL);
+  if (!tab ||
+      !win.gMultiProcessBrowser ||
+      !mustChangeProcess) {
+    return stoppedDocLoadPromise();
+  }
+
   return new Promise((resolve, reject) => {
-    function complete({ data }) {
-      is(data.uri, aExpectedURL, "waitForDocLoadAndStopIt: The expected URL was loaded");
-      mm.removeMessageListener("Test:WaitForDocLoadAndStopIt", complete);
-      resolve();
-    }
-
-    let mm = aBrowser.messageManager;
-    mm.loadFrameScript("data:,(" + content_script.toString() + ")(" + aStopFromProgressListener + ");", true);
-    mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
-    info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
+    tab.addEventListener("TabRemotenessChange", function() {
+      stoppedDocLoadPromise().then(resolve, reject);
+    }, {once: true});
   });
 }
 
 /**
  * Wait for the search engine to change.
  */
 function promiseContentSearchChange(browser, newEngineName) {
   return ContentTask.spawn(browser, { newEngineName }, async function(args) {
--- a/browser/base/content/test/general/browser_bug724239.js
+++ b/browser/base/content/test/general/browser_bug724239.js
@@ -8,17 +8,34 @@ add_task(async function test_blank() {
     await BrowserTestUtils.browserLoaded(browser);
     ok(!gBrowser.canGoBack, "about:blank wasn't added to session history");
   });
 });
 
 add_task(async function test_newtab() {
   await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
                                     async function(browser) {
+    let tab = gBrowser.getTabForBrowser(browser);
+
     // Can't load it directly because that'll use a preloaded tab if present.
     BrowserTestUtils.loadURI(browser, "about:newtab");
-    await BrowserTestUtils.browserLoaded(browser);
+    // We will need to wait for about:newtab to be loaded so that it goes into
+    // the session history.
+    await BrowserTestUtils.browserStopped(browser, "about:newtab");
+
+    let { mustChangeProcess } =
+      E10SUtils.shouldLoadURIInBrowser(browser, "http://example.com");
 
     BrowserTestUtils.loadURI(browser, "http://example.com");
-    await BrowserTestUtils.browserLoaded(browser);
+
+    let stopped = BrowserTestUtils.browserStopped(browser);
+
+    if (mustChangeProcess) {
+      // If we did a process flip, we will need to ensure that the restoration has
+      // completed before we check gBrowser.canGoBack.
+      await BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
+    }
+
+    await stopped;
+
     is(gBrowser.canGoBack, true, "about:newtab was added to the session history when AS was enabled.");
   });
 });
--- a/browser/base/content/test/general/browser_e10s_chrome_process.js
+++ b/browser/base/content/test/general/browser_e10s_chrome_process.js
@@ -10,22 +10,22 @@ function makeTest(name, startURL, startP
     if (!gMultiProcessBrowser) {
       startProcessIsRemote = false;
       endProcessIsRemote = false;
     }
 
     // Load the initial URL and make sure we are in the right initial process
     info("Loading initial URL");
     BrowserTestUtils.loadURI(browser, startURL);
-    await BrowserTestUtils.browserLoaded(browser);
+    await BrowserTestUtils.browserLoaded(browser, false, startURL);
 
     is(browser.currentURI.spec, startURL, "Shouldn't have been redirected");
     is(browser.isRemoteBrowser, startProcessIsRemote, "Should be displayed in the right process");
 
-    let docLoadedPromise = BrowserTestUtils.browserLoaded(browser);
+    let docLoadedPromise = BrowserTestUtils.browserLoaded(browser, false, endURL);
     let expectSyncChange = await transitionTask(browser, endURL);
     if (expectSyncChange) {
       is(browser.isRemoteBrowser, endProcessIsRemote, "Should have switched to the right process synchronously");
     }
     await docLoadedPromise;
 
     is(browser.currentURI.spec, endURL, "Should have made it to the final URL");
     is(browser.isRemoteBrowser, endProcessIsRemote, "Should be displayed in the right process");
--- a/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
@@ -43,31 +43,27 @@ add_task(async function setup() {
 add_task(async function test_abouthome_activitystream_simpleQuery() {
   // Let's reset the counts.
   Services.telemetry.clearScalars();
   Services.telemetry.clearEvents();
   let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
 
-  info("Setup waiting for search input to initialise.");
-  let promiseAboutHomeSearchLoaded = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "ContentSearchClient", true, null, true).then(() => false);
-
   info("Load about:home.");
   BrowserTestUtils.loadURI(tab.linkedBrowser, "about:home");
-  info("Wait for ActivityStream search input.");
-  await promiseAboutHomeSearchLoaded;
+  await BrowserTestUtils.browserStopped(tab.linkedBrowser, "about:home");
 
   info("Wait for ContentSearchUI search provider to initialize.");
   await ContentTask.spawn(tab.linkedBrowser, null, async function() {
     await ContentTaskUtils.waitForCondition(() => content.wrappedJSObject.gContentSearchController.defaultEngine);
   });
 
-  info("Trigger a simple serch, just test + enter.");
-  let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  info("Trigger a simple search, just test + enter.");
+  let p = BrowserTestUtils.browserStopped(tab.linkedBrowser, "http://example.com/?q=test+query");
   await typeInSearchField(tab.linkedBrowser, "test query", "newtab-search-text");
   await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
   await p;
 
   // Check if the scalars contain the expected values.
   const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
   checkKeyedScalar(scalars, SCALAR_ABOUT_HOME, "search_enter", 1);
   Assert.equal(Object.keys(scalars[SCALAR_ABOUT_HOME]).length, 1,