Bug 1485288 - Fix intermittent browser/base/content/test/urlbar/browser_urlbarStop.js by waiting for URLBarSetURI to be called by using a progress listener. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Tue, 14 May 2019 09:37:30 +0000
changeset 535678 4934e59477f4d9cb7ab742973b4c31ee3b9bd261
parent 535677 54a4320c7206d6a478b23a6a52b1f51b00dcec53
child 535679 6ff9d6783ae0e67b522400818dbd02e1e42b74f6
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1485288
milestone68.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 1485288 - Fix intermittent browser/base/content/test/urlbar/browser_urlbarStop.js by waiting for URLBarSetURI to be called by using a progress listener. r=mak When the load is stopped, tabbrowser calls URLBarSetURI [1] and then calls onStateChange [2] on its progress listeners. That's the URLBarSetURI call that updates the urlbar value in this case. So to properly wait until the urlbar value has been updated, add our own progress listener in the test. [1] https://searchfox.org/mozilla-central/rev/cc280c4be94ff8cf64a27cc9b3d6831ffa49fa45/browser/base/content/tabbrowser.js#5036 [2] https://searchfox.org/mozilla-central/rev/cc280c4be94ff8cf64a27cc9b3d6831ffa49fa45/browser/base/content/tabbrowser.js#5071 Differential Revision: https://phabricator.services.mozilla.com/D31018
browser/components/urlbar/tests/browser/browser_urlbarStop.js
--- a/browser/components/urlbar/tests/browser/browser_urlbarStop.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarStop.js
@@ -27,13 +27,30 @@ add_task(async function() {
   is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects stopped page in an empty tab");
   gBrowser.removeCurrentTab();
 });
 
 async function typeAndSubmitAndStop(url) {
   await promiseAutocompleteResultPopup(url, window, true);
   is(gURLBar.textValue, gURLBar.trimValue(url), "location bar reflects loading page");
 
-  let promise =
+  let docLoadPromise =
     BrowserTestUtils.waitForDocLoadAndStopIt(url, gBrowser.selectedBrowser, false);
+
+  // When the load is stopped, tabbrowser calls URLBarSetURI and then calls
+  // onStateChange on its progress listeners.  So to properly wait until the
+  // urlbar value has been updated, add our own progress listener here.
+  let progressPromise = new Promise(resolve => {
+    let listener = {
+      onStateChange(browser, webProgress, request, stateFlags, status) {
+        if (webProgress.isTopLevel &&
+            (stateFlags & Ci.nsIWebProgressListener.STATE_STOP)) {
+          gBrowser.removeTabsProgressListener(listener);
+          resolve();
+        }
+      },
+    };
+    gBrowser.addTabsProgressListener(listener);
+  });
+
   gURLBar.handleCommand();
-  await promise;
+  await Promise.all([docLoadPromise, progressPromise]);
 }