Bug 1337354 - Fix races in referrer tests. r=mrbkap, a=test-only
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 08 Feb 2017 11:22:33 +0100
changeset 376376 eb716d41e5b7b26a53030a2ba8d84de627379846
parent 376375 11aa99d14cd1162a677bc290f17b001573f2462b
child 376377 716903f2bac83231d7f095fb32024cfa4a740f28
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, test-only
bugs1337354
milestone53.0a2
Bug 1337354 - Fix races in referrer tests. r=mrbkap, a=test-only
browser/base/content/test/referrer/browser_referrer_middle_click.js
browser/base/content/test/referrer/browser_referrer_middle_click_in_container.js
browser/base/content/test/referrer/head.js
--- a/browser/base/content/test/referrer/browser_referrer_middle_click.js
+++ b/browser/base/content/test/referrer/browser_referrer_middle_click.js
@@ -1,18 +1,19 @@
 // Tests referrer on middle-click navigation.
 // Middle-clicks on the link, which opens it in a new tab.
 
 function startMiddleClickTestCase(aTestNumber) {
   info("browser_referrer_middle_click: " +
        getReferrerTestDescription(aTestNumber));
   someTabLoaded(gTestWindow).then(function(aNewTab) {
-    gTestWindow.gBrowser.selectedTab = aNewTab;
-    checkReferrerAndStartNextTest(aTestNumber, null, aNewTab,
-                                  startMiddleClickTestCase);
+    BrowserTestUtils.switchTab(gTestWindow.gBrowser, aNewTab).then(() => {
+      checkReferrerAndStartNextTest(aTestNumber, null, aNewTab,
+                                    startMiddleClickTestCase);
+    });
   });
 
   clickTheLink(gTestWindow, "testlink", {button: 1});
 }
 
 function test() {
   requestLongerTimeout(10);  // slowwww shutdown on e10s
   startReferrerTest(startMiddleClickTestCase);
--- a/browser/base/content/test/referrer/browser_referrer_middle_click_in_container.js
+++ b/browser/base/content/test/referrer/browser_referrer_middle_click_in_container.js
@@ -1,19 +1,20 @@
 // Tests referrer on middle-click navigation.
 // Middle-clicks on the link, which opens it in a new tab, same container.
 
 function startMiddleClickTestCase(aTestNumber) {
   info("browser_referrer_middle_click: " +
        getReferrerTestDescription(aTestNumber));
   someTabLoaded(gTestWindow).then(function(aNewTab) {
-    gTestWindow.gBrowser.selectedTab = aNewTab;
-    checkReferrerAndStartNextTest(aTestNumber, null, aNewTab,
-                                  startMiddleClickTestCase,
-                                  { userContextId: 3 });
+    BrowserTestUtils.switchTab(gTestWindow.gBrowser, aNewTab).then(() => {
+      checkReferrerAndStartNextTest(aTestNumber, null, aNewTab,
+                                    startMiddleClickTestCase,
+                                    { userContextId: 3 });
+    });
   });
 
   clickTheLink(gTestWindow, "testlink", {button: 1});
 }
 
 function test() {
   waitForExplicitFinish();
 
--- a/browser/base/content/test/referrer/head.js
+++ b/browser/base/content/test/referrer/head.js
@@ -137,16 +137,19 @@ function delayedStartupFinished(aWindow)
  * Waits for some (any) tab to load. The caller triggers the load.
  * @param aWindow The window where to wait for a tab to load.
  * @return {Promise}
  * @resolves With the tab once it's loaded.
  */
 function someTabLoaded(aWindow) {
   return new Promise(function(resolve) {
     aWindow.gBrowser.addEventListener("load", function onLoad(aEvent) {
+      if (aWindow.location === "about:blank") {
+        return;
+      }
       let tab = aWindow.gBrowser._getTabForContentWindow(
           aEvent.target.defaultView.top);
       if (tab) {
         aWindow.gBrowser.removeEventListener("load", onLoad, true);
         resolve(tab);
       }
     }, true);
   });