Bug 1451460 - Get rid of single-process support in TPS talos test. r?rwood draft
authorMike Conley <mconley@mozilla.com>
Thu, 05 Apr 2018 14:16:29 -0400
changeset 779375 5076c576e2007e48a92ebf3ac72aad623ff1a305
parent 779374 268400a2b913a030fbc7a76ca5a568e7f4359a92
child 779376 018d37d8a0f19ee73f8aa978c49da476c5db3e34
push id105760
push usermconley@mozilla.com
push dateMon, 09 Apr 2018 20:21:39 +0000
reviewersrwood
bugs1451460
milestone61.0a1
Bug 1451460 - Get rid of single-process support in TPS talos test. r?rwood MozReview-Commit-ID: EN3YSW9nnV0
testing/talos/talos/tests/tabswitch/api.js
--- a/testing/talos/talos/tests/tabswitch/api.js
+++ b/testing/talos/talos/tests/tabswitch/api.js
@@ -99,19 +99,16 @@ function loadTabs(gBrowser, urls) {
  *
  * @param browser (<xul:browser>)
  *        The remote browser to load the script in.
  * @returns Promise
  *        Resolves once the script has been loaded and executed in
  *        the remote browser.
  */
 function loadTPSContentScript(browser) {
-  if (!browser.isRemoteBrowser) {
-    throw new Error("loadTPSContentScript expects a remote browser.");
-  }
   return new Promise((resolve) => {
     // Here's our utility script. We'll serialize this and send it down
     // to run in the content process for this browser.
     let script = function() {
       ChromeUtils.import("resource://gre/modules/Services.jsm");
 
       /**
        * In order to account for the fact that a MozAfterPaint might fire
@@ -155,69 +152,31 @@ function loadTPSContentScript(browser) {
  * to that tab. Returns a Promise that resolves ones the tab content
  * has been presented to the user.
  */
 async function switchToTab(tab) {
   let browser = tab.linkedBrowser;
   let gBrowser = tab.ownerGlobal.gBrowser;
   let window = tab.ownerGlobal;
 
-  // Single-process tab switching works quite differently from
-  // multi-process tab switching. In the single-process case, tab
-  // switching is synchronous, whereas in the multi-process case,
-  // it is not. The following two tab switching mechanisms encapsulate
-  // those two differences.
-
-  if (browser.isRemoteBrowser) {
-    // The multi-process case requires that we load our utility script
-    // inside the content, since it's the content that will hear a MozAfterPaint
-    // once the content is presented to the user.
-    await loadTPSContentScript(browser);
-    let start = Math.floor(window.performance.timing.navigationStart + window.performance.now());
-
-    // We need to wait for the TabSwitchDone event to make sure
-    // that the async tab switcher has shut itself down.
-    let switchDone = waitForTabSwitchDone(browser);
-    // Set up our promise that will wait for the content to be
-    // presented.
-    let finishPromise = waitForContentPresented(browser);
-    // Finally, do the tab switch.
-    gBrowser.selectedTab = tab;
-
-    await switchDone;
-    let finish = await finishPromise;
-    return finish - start;
-  }
-
-  let win = browser.ownerGlobal;
-  let winUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIDOMWindowUtils);
-
+  await loadTPSContentScript(browser);
   let start = Math.floor(window.performance.timing.navigationStart + window.performance.now());
 
-  // There is no async tab switcher for the single-process case,
-  // but tabbrowser.xml will still fire this once the updateCurrentBrowser
-  // method runs.
+  // We need to wait for the TabSwitchDone event to make sure
+  // that the async tab switcher has shut itself down.
   let switchDone = waitForTabSwitchDone(browser);
-  // Do our tab switch
+  // Set up our promise that will wait for the content to be
+  // presented.
+  let finishPromise = waitForContentPresented(browser);
+  // Finally, do the tab switch.
   gBrowser.selectedTab = tab;
-  // Because the above tab switch is synchronous, we know that the
-  // we want a MozAfterPaint with a greater layer transaction id than
-  // what is currently the "last transaction id" for the window.
-  let lastTransactionId = winUtils.lastTransactionId;
 
   await switchDone;
-
-  // Now we'll wait for content to be presented. Because
-  // this is the single-process case, we pass the last transaction
-  // id that we got so that we don't get any intermediate MozAfterPaint's
-  // that might fire before web content is shown.
-  let finish = await waitForContentPresented(browser, lastTransactionId);
+  let finish = await finishPromise;
   return finish - start;
-
 }
 
 /**
  * For some <xul:browser>, find the <xul:tabbrowser> associated with it,
  * and wait until that tabbrowser has finished a tab switch. This function
  * assumes a tab switch has started, or is about to start.
  *
  * @param browser (<xul:browser>)
@@ -236,57 +195,28 @@ function waitForTabSwitchDone(browser) {
 }
 
 /**
  * For some <xul:browser>, returns a Promise that resolves once its
  * content has been presented to the user.
  *
  * @param browser (<xul:browser>)
  *        The browser we expect to be presented.
- * @param lastTransactionId (int, optional)
- *        In the single-process case, we need to know the last layer
- *        transaction id that was used before the switch started. That
- *        way, when the MozAfterPaint fires, we can be sure that its
- *        transaction id is greater than the one that was last used,
- *        so we know that the content has definitely been presented.
- *
- *        This argument is ignored in the multi-process browser case.
  *
  * @returns Promise
  *        Resolves once the content has been presented. Resolves to
  *        the system time that the presentation occurred at, in
  *        milliseconds since midnight 01 January, 1970 UTC.
  */
-function waitForContentPresented(browser, lastTransactionId) {
-  // We treat multi-process browsers differently here - we expect the
-  // utility script we loaded to inform us once content has been presented.
-  if (browser.isRemoteBrowser) {
-    return new Promise((resolve) => {
-      let mm = browser.messageManager;
-      mm.addMessageListener("TPS:ContentSawPaint", function onContentPaint(msg) {
-        mm.removeMessageListener("TPS:ContentSawPaint", onContentPaint);
-        resolve(msg.data.time);
-      });
-    });
-  }
-
-  // Wait for the next MozAfterPaint for this browser's window that has
-  // a greater transaction id than lastTransactionId.
+function waitForContentPresented(browser) {
   return new Promise((resolve) => {
-    let win = browser.ownerGlobal;
-    win.addEventListener("MozAfterPaint", function onPaint(event) {
-      if (ChromeUtils.getClassName(event) === "NotifyPaintEvent") {
-        TalosParentProfiler.mark("Content saw transaction id: " + event.transactionId);
-        if (event.transactionId > lastTransactionId) {
-          win.removeEventListener("MozAfterPaint", onPaint);
-          TalosParentProfiler.mark("Content saw MozAfterPaint");
-          let time = Math.floor(win.performance.timing.navigationStart + win.performance.now());
-          resolve(time);
-        }
-      }
+    let mm = browser.messageManager;
+    mm.addMessageListener("TPS:ContentSawPaint", function onContentPaint(msg) {
+      mm.removeMessageListener("TPS:ContentSawPaint", onContentPaint);
+      resolve(msg.data.time);
     });
   });
 }
 
 /**
  * Given some browser, do a garbage collect in the parent, and then
  * a garbage collection in the content process that the browser is
  * running in.
@@ -324,16 +254,22 @@ function forceGC(win, browser) {
  * report the results.
  *
  * @param window
  *        A host window. Primarily, we just use this for the OpenBrowserWindow
  *        function defined in that window.
  * @returns Promise
  */
 async function test(window) {
+  if (!window.gMultiProcessBrowser) {
+    dump("** The TPS Talos test does not support running in non-e10s mode " +
+         "anymore! Bailing out!\n");
+    return;
+  }
+
   Services.scriptloader.loadSubScript("chrome://talos-powers-content/content/TalosParentProfiler.js", context);
   TalosParentProfiler = context.TalosParentProfiler;
 
   let testURLs = [];
 
   let win = window.OpenBrowserWindow();
   try {
     let prefFile = Services.prefs.getCharPref("addon.test.tabswitch.urlfile");