Bug 1188543 - TPS e10s should listen for TabSwitched event. r=blassey
authorBenoit Girard <b56girard@gmail.com>
Wed, 29 Jul 2015 13:56:23 -0400
changeset 998 e970f49a2dd2
parent 997 306fac2f61aa
child 999 335a890ad040
push id687
push userb56girard@gmail.com
push dateTue, 18 Aug 2015 18:57:44 +0000
reviewersblassey
bugs1188543
Bug 1188543 - TPS e10s should listen for TabSwitched event. r=blassey
talos/page_load_test/tabswitch/bootstrap.js
--- a/talos/page_load_test/tabswitch/bootstrap.js
+++ b/talos/page_load_test/tabswitch/bootstrap.js
@@ -108,16 +108,31 @@ function loadTabs(urls, win, callback) {
     let tabs = win.gBrowser.getTabsToTheEndFrom(initialTab);
     callback(tabs);
   });
   win.gBrowser.loadTabs(urls, true);
 
   aboutBlankTab = initialTab;
 }
 
+function waitForTabSwitchDone(win, callback) {
+  if (win.gBrowser.selectedBrowser.isRemoteBrowser) {
+    var list = function onSwitch() {
+      win.gBrowser.removeEventListener("TabSwitched", list);
+      callback();
+    };
+
+    win.gBrowser.addEventListener("TabSwitched", list);
+
+  } else {
+    // Tab switch is sync so it has already happened.
+    callback();
+  }
+}
+
 function runTest(tabs, win, callback) {
   let startTab = win.gBrowser.selectedTab;
   let times = [];
   runTestHelper(startTab, tabs, 0, win, times, function() {
     callback(times);
   });
 }
 
@@ -132,43 +147,46 @@ function runTestHelper(startTab, tabs, i
      .garbageCollect();
 
   forceContentGC(tab.linkedBrowser).then(function() {
     if (typeof(Profiler) !== "undefined") {
       Profiler.resume(tab.linkedBrowser.currentURI.spec);
     }
     let start = win.performance.now();
     win.gBrowser.selectedTab = tab;
-    // This will fire when we're about to paint the tab switch
-    win.requestAnimationFrame(function() {
-      // This will fire on the next vsync tick after the tab has switched.
-      // If we have a sync transaction on the compositor, that time will
-      // be included here. It will not accuratly capture the composite time
-      // or the time of async transaction.
-      // XXX: This will need to be adjusted for e10s since we need to block
-      //      on the child/content having painted.
-      win.requestAnimationFrame(function() {
-        times.push(win.performance.now() - start);
-        if (typeof(Profiler) !== "undefined") {
-          Profiler.pause(tab.linkedBrowser.currentURI.spec);
-        }
 
-        // Select about:blank which will let the browser reach a steady no
-        // painting state
-        win.gBrowser.selectedTab = aboutBlankTab;
+    waitForTabSwitchDone(win, function() {
+      // This will fire when we're about to paint the tab switch
+      win.requestAnimationFrame(function() {
+        // This will fire on the next vsync tick after the tab has switched.
+        // If we have a sync transaction on the compositor, that time will
+        // be included here. It will not accuratly capture the composite time
+        // or the time of async transaction.
+        // XXX: This will need to be adjusted for e10s since we need to block
+        //      on the child/content having painted.
+        win.requestAnimationFrame(function() {
+          times.push(win.performance.now() - start);
+          if (typeof(Profiler) !== "undefined") {
+            Profiler.pause(tab.linkedBrowser.currentURI.spec);
+          }
 
-        win.requestAnimationFrame(function() {
+          // Select about:blank which will let the browser reach a steady no
+          // painting state
+          win.gBrowser.selectedTab = aboutBlankTab;
+
           win.requestAnimationFrame(function() {
-            if (index == tabs.length - 1) {
-              callback();
-            } else {
-              runTestHelper(startTab, tabs, index + 1, win, times, function() {
+            win.requestAnimationFrame(function() {
+              if (index == tabs.length - 1) {
                 callback();
-              });
-            }
+              } else {
+                runTestHelper(startTab, tabs, index + 1, win, times, function() {
+                  callback();
+                });
+              }
+            });
           });
         });
       });
     });
   });
 }
 
 function forceContentGC(browser) {