Bug 1335801 - Make these tests wait correctly. r=Felipe,krizsa a=test-only
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 01 Mar 2017 17:11:23 -0800
changeset 395210 e5a0500b0483a783b1f49f9269c7173aa8b47210
parent 395209 6a72a11138b9b41a02455a3cb32a8994a7f41934
child 395211 8154f92ee3e22aac59481f4752cb90f47cda5efd
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, krizsa, test-only
bugs1335801
milestone54.0a2
Bug 1335801 - Make these tests wait correctly. r=Felipe,krizsa a=test-only
browser/base/content/test/referrer/browser_referrer_open_link_in_private.js
browser/base/content/test/referrer/browser_referrer_open_link_in_window.js
browser/base/content/test/referrer/browser_referrer_open_link_in_window_in_container.js
browser/base/content/test/referrer/browser_referrer_simple_click.js
browser/base/content/test/referrer/head.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/browser/base/content/test/referrer/browser_referrer_open_link_in_private.js
+++ b/browser/base/content/test/referrer/browser_referrer_open_link_in_private.js
@@ -1,17 +1,17 @@
 // Tests referrer on context menu navigation - open link in new private window.
 // Selects "open link in new private window" from the context menu.
 
 function startNewPrivateWindowTestCase(aTestNumber) {
   info("browser_referrer_open_link_in_private: " +
        getReferrerTestDescription(aTestNumber));
   contextMenuOpened(gTestWindow, "testlink").then(function(aContextMenu) {
     newWindowOpened().then(function(aNewWindow) {
-      someTabLoaded(aNewWindow).then(function() {
+      BrowserTestUtils.firstBrowserLoaded(aNewWindow, false).then(function() {
         checkReferrerAndStartNextTest(aTestNumber, aNewWindow, null,
                                       startNewPrivateWindowTestCase);
       });
     });
 
     doContextMenuCommand(gTestWindow, aContextMenu, "context-openlinkprivate");
   });
 }
--- a/browser/base/content/test/referrer/browser_referrer_open_link_in_window.js
+++ b/browser/base/content/test/referrer/browser_referrer_open_link_in_window.js
@@ -1,17 +1,17 @@
 // Tests referrer on context menu navigation - open link in new window.
 // Selects "open link in new window" from the context menu.
 
 function startNewWindowTestCase(aTestNumber) {
   info("browser_referrer_open_link_in_window: " +
        getReferrerTestDescription(aTestNumber));
   contextMenuOpened(gTestWindow, "testlink").then(function(aContextMenu) {
     newWindowOpened().then(function(aNewWindow) {
-      someTabLoaded(aNewWindow).then(function() {
+      BrowserTestUtils.firstBrowserLoaded(aNewWindow, false).then(function() {
         checkReferrerAndStartNextTest(aTestNumber, aNewWindow, null,
                                       startNewWindowTestCase);
       });
     });
 
     doContextMenuCommand(gTestWindow, aContextMenu, "context-openlink");
   });
 }
--- a/browser/base/content/test/referrer/browser_referrer_open_link_in_window_in_container.js
+++ b/browser/base/content/test/referrer/browser_referrer_open_link_in_window_in_container.js
@@ -4,17 +4,17 @@
 // This test runs from a container tab. The new tab/window will be loaded in
 // the same container.
 
 function startNewWindowTestCase(aTestNumber) {
   info("browser_referrer_open_link_in_window: " +
        getReferrerTestDescription(aTestNumber));
   contextMenuOpened(gTestWindow, "testlink").then(function(aContextMenu) {
     newWindowOpened().then(function(aNewWindow) {
-      someTabLoaded(aNewWindow).then(function() {
+      BrowserTestUtils.firstBrowserLoaded(aNewWindow, false).then(function() {
         checkReferrerAndStartNextTest(aTestNumber, aNewWindow, null,
                                       startNewWindowTestCase,
                                       { userContextId: 1 });
       });
     });
 
     doContextMenuCommand(gTestWindow, aContextMenu, "context-openlink");
   });
--- a/browser/base/content/test/referrer/browser_referrer_simple_click.js
+++ b/browser/base/content/test/referrer/browser_referrer_simple_click.js
@@ -1,18 +1,20 @@
 // Tests referrer on simple click navigation.
 // Clicks on the link, which opens it in the same tab.
 
 function startSimpleClickTestCase(aTestNumber) {
   info("browser_referrer_simple_click: " +
        getReferrerTestDescription(aTestNumber));
-  BrowserTestUtils.browserLoaded(gTestWindow.gBrowser.selectedBrowser).then(function() {
-    checkReferrerAndStartNextTest(aTestNumber, null, null,
-                                  startSimpleClickTestCase);
-  });
+  BrowserTestUtils.browserLoaded(gTestWindow.gBrowser.selectedBrowser, false,
+                                 (url) => url.endsWith("file_referrer_testserver.sjs"))
+                  .then(function() {
+                    checkReferrerAndStartNextTest(aTestNumber, null, null,
+                                                  startSimpleClickTestCase);
+                  });
 
   clickTheLink(gTestWindow, "testlink", {});
 }
 
 function test() {
   requestLongerTimeout(10);  // slowwww shutdown on e10s
   startReferrerTest(startSimpleClickTestCase);
 }
--- a/browser/base/content/test/referrer/head.js
+++ b/browser/base/content/test/referrer/head.js
@@ -135,28 +135,18 @@ 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.href === "about:blank") {
-        return;
-      }
-      let tab = aWindow.gBrowser._getTabForContentWindow(
-          aEvent.target.defaultView.top);
-      if (tab) {
-        aWindow.gBrowser.removeEventListener("load", onLoad, true);
-        resolve(tab);
-      }
-    }, true);
+  return BrowserTestUtils.waitForNewTab(gTestWindow.gBrowser).then((tab) => {
+    return BrowserTestUtils.browserStopped(tab.linkedBrowser).then(() => tab);
   });
 }
 
 /**
  * Waits for a new window to open and load. The caller triggers the open.
  * @return {Promise}
  * @resolves With the new window once it's open and loaded.
  */
@@ -204,17 +194,17 @@ function referrerTestCaseLoaded(aTestNum
                              REFERRER_POLICYSERVER_URL_ATTRIBUTE;
   let url = test.fromScheme + server +
             "?scheme=" + escape(test.toScheme) +
             "&policy=" + escape(test.policy || "") +
             "&rel=" + escape(test.rel || "");
   let browser = gTestWindow.gBrowser;
   return BrowserTestUtils.openNewForegroundTab(browser, () => {
     browser.selectedTab = browser.addTab(url, aParams);
-  });
+  }, false, true);
 }
 
 /**
  * Checks the result of the referrer test, and moves on to the next test.
  * @param aTestNumber The test number - 0, 1, 2, ...
  * @param aNewWindow The new window where the referrer target opened, or null.
  * @param aNewTab The new tab where the referrer target opened, or null.
  * @param aStartTestCase The callback to start the next test, aTestNumber + 1.
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -221,21 +221,22 @@ this.BrowserTestUtils = {
    *
    * @param {win}
    *        A newly opened window for which we're waiting for the
    *        first browser load.
    *
    * @return {Promise}
    * @resolves Once the selected browser fires its load event.
    */
-  firstBrowserLoaded(win) {
+  firstBrowserLoaded(win, aboutBlank = true) {
     let mm = win.messageManager;
     return this.waitForMessage(mm, "browser-test-utils:loadEvent", (msg) => {
       let selectedBrowser = win.gBrowser.selectedBrowser;
-      return msg.target == selectedBrowser;
+      return msg.target == selectedBrowser &&
+             (aboutBlank || selectedBrowser.currentURI.spec != "about:blank")
     });
   },
 
   /**
    * Waits for the web progress listener associated with this tab to fire a
    * STATE_STOP for the toplevel document.
    *
    * @param {xul:browser} browser