Bug 1587784 - improve logging and test assertions in browser_alltabslistener.js so it's easier to work out what's going on, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 11 Oct 2019 15:12:15 +0000
changeset 497283 d4837cfe8ba0a5f25658d2aeb9bfc5cb99d06f33
parent 497282 d19d644cb240a27a1d0389a0ca603b4bbffddd42
child 497284 a90b5a94599371b19551906fd41384367b2eb16a
push id36681
push usercbrindusan@mozilla.com
push dateFri, 11 Oct 2019 21:50:12 +0000
treeherdermozilla-central@c5e6477c3a24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1587784
milestone71.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 1587784 - improve logging and test assertions in browser_alltabslistener.js so it's easier to work out what's going on, r=dao Differential Revision: https://phabricator.services.mozilla.com/D48851
browser/base/content/test/general/browser_alltabslistener.js
--- a/browser/base/content/test/general/browser_alltabslistener.js
+++ b/browser/base/content/test/general/browser_alltabslistener.js
@@ -1,170 +1,171 @@
 const gCompleteState =
   Ci.nsIWebProgressListener.STATE_STOP +
   Ci.nsIWebProgressListener.STATE_IS_NETWORK;
 
+function getOriginalURL(request) {
+  return request && request.QueryInterface(Ci.nsIChannel).originalURI.spec;
+}
+
 var gFrontProgressListener = {
   onProgressChange(
     aWebProgress,
     aRequest,
     aCurSelfProgress,
     aMaxSelfProgress,
     aCurTotalProgress,
     aMaxTotalProgress
   ) {},
 
   onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
-      // ignore initial about blank
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       return;
     }
     var state = "onStateChange";
-    info("FrontProgress: " + state + " 0x" + aStateFlags.toString(16));
-    ok(
-      gFrontNotificationsPos < gFrontNotifications.length,
+    info(
+      "FrontProgress (" + url + "): " + state + " 0x" + aStateFlags.toString(16)
+    );
+    Assert.less(
+      gFrontNotificationsPos,
+      gFrontNotifications.length,
       "Got an expected notification for the front notifications listener"
     );
     is(
       state,
       gFrontNotifications[gFrontNotificationsPos],
       "Got a notification for the front notifications listener"
     );
     gFrontNotificationsPos++;
   },
 
   onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
-      // ignore initial about blank
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       return;
     }
     var state = "onLocationChange";
     info("FrontProgress: " + state + " " + aLocationURI.spec);
-    ok(
-      gFrontNotificationsPos < gFrontNotifications.length,
+    Assert.less(
+      gFrontNotificationsPos,
+      gFrontNotifications.length,
       "Got an expected notification for the front notifications listener"
     );
     is(
       state,
       gFrontNotifications[gFrontNotificationsPos],
       "Got a notification for the front notifications listener"
     );
     gFrontNotificationsPos++;
   },
 
   onSecurityChange(aWebProgress, aRequest, aState) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
-      // ignore initial about blank
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       return;
     }
     var state = "onSecurityChange";
-    info("FrontProgress: " + state + " 0x" + aState.toString(16));
-    ok(
-      gFrontNotificationsPos < gFrontNotifications.length,
+    info("FrontProgress (" + url + "): " + state + " 0x" + aState.toString(16));
+    Assert.less(
+      gFrontNotificationsPos,
+      gFrontNotifications.length,
       "Got an expected notification for the front notifications listener"
     );
     is(
       state,
       gFrontNotifications[gFrontNotificationsPos],
       "Got a notification for the front notifications listener"
     );
     gFrontNotificationsPos++;
   },
 };
 
 var gAllProgressListener = {
   onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       // ignore initial about blank
       return;
     }
     var state = "onStateChange";
-    info("AllProgress: " + state + " 0x" + aStateFlags.toString(16));
+    info(
+      "AllProgress (" + url + "): " + state + " 0x" + aStateFlags.toString(16)
+    );
     ok(
       aBrowser == gTestBrowser,
       state + " notification came from the correct browser"
     );
-    ok(
-      gAllNotificationsPos < gAllNotifications.length,
+    Assert.less(
+      gAllNotificationsPos,
+      gAllNotifications.length,
       "Got an expected notification for the all notifications listener"
     );
     is(
       state,
       gAllNotifications[gAllNotificationsPos],
       "Got a notification for the all notifications listener"
     );
     gAllNotificationsPos++;
 
     if ((aStateFlags & gCompleteState) == gCompleteState) {
-      ok(
-        gAllNotificationsPos == gAllNotifications.length,
+      is(
+        gAllNotificationsPos,
+        gAllNotifications.length,
         "Saw the expected number of notifications"
       );
-      ok(
-        gFrontNotificationsPos == gFrontNotifications.length,
+      is(
+        gFrontNotificationsPos,
+        gFrontNotifications.length,
         "Saw the expected number of frontnotifications"
       );
       executeSoon(gNextTest);
     }
   },
 
   onLocationChange(aBrowser, aWebProgress, aRequest, aLocationURI, aFlags) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       // ignore initial about blank
       return;
     }
     var state = "onLocationChange";
     info("AllProgress: " + state + " " + aLocationURI.spec);
     ok(
       aBrowser == gTestBrowser,
       state + " notification came from the correct browser"
     );
-    ok(
-      gAllNotificationsPos < gAllNotifications.length,
+    Assert.less(
+      gAllNotificationsPos,
+      gAllNotifications.length,
       "Got an expected notification for the all notifications listener"
     );
     is(
       state,
       gAllNotifications[gAllNotificationsPos],
       "Got a notification for the all notifications listener"
     );
     gAllNotificationsPos++;
   },
 
   onSecurityChange(aBrowser, aWebProgress, aRequest, aState) {
-    if (
-      aRequest &&
-      aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec == "about:blank"
-    ) {
+    var url = getOriginalURL(aRequest);
+    if (url == "about:blank") {
       // ignore initial about blank
       return;
     }
     var state = "onSecurityChange";
-    info("AllProgress: " + state + " 0x" + aState.toString(16));
+    info("AllProgress (" + url + "): " + state + " 0x" + aState.toString(16));
     ok(
       aBrowser == gTestBrowser,
       state + " notification came from the correct browser"
     );
-    ok(
-      gAllNotificationsPos < gAllNotifications.length,
+    Assert.less(
+      gAllNotificationsPos,
+      gAllNotifications.length,
       "Got an expected notification for the all notifications listener"
     );
     is(
       state,
       gAllNotifications[gAllNotificationsPos],
       "Got a notification for the all notifications listener"
     );
     gAllNotificationsPos++;