Bug 1521492 - When the QuantumBar input receives a blur, ensure queries are stopped and the popup is closed. r=dao
authorMark Banner <standard8@mozilla.com>
Thu, 24 Jan 2019 12:22:14 +0000
changeset 515268 76c397291c5fd579ada699db17ea80cb36ab7581
parent 515267 dfc1e458a78055ed5d73807b2c27c8b49fc7ea25
child 515269 08c85a7f6bccaf072f95d06c82c4e9162a311cad
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1521492
milestone66.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 1521492 - When the QuantumBar input receives a blur, ensure queries are stopped and the popup is closed. r=dao Depends on D17352 Differential Revision: https://phabricator.services.mozilla.com/D17369
browser/components/urlbar/UrlbarController.jsm
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/UrlbarView.jsm
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/unit/test_UrlbarController_unit.js
--- a/browser/components/urlbar/UrlbarController.jsm
+++ b/browser/components/urlbar/UrlbarController.jsm
@@ -100,29 +100,28 @@ class UrlbarController {
     this._notify("onQueryStarted", queryContext);
     await this.manager.startQuery(queryContext, this);
     this._notify("onQueryFinished", queryContext);
   }
 
   /**
    * Cancels an in-progress query. Note, queries may continue running if they
    * can't be canceled.
-   *
-   * @param {UrlbarQueryContext} queryContext The query details.
    */
-  cancelQuery(queryContext) {
-    if (queryContext === this._lastQueryContext) {
-      delete this._lastQueryContext;
+  cancelQuery() {
+    if (!this._lastQueryContext) {
+      return;
     }
 
-    TelemetryStopwatch.cancel(TELEMETRY_1ST_RESULT, queryContext);
-    TelemetryStopwatch.cancel(TELEMETRY_6_FIRST_RESULTS, queryContext);
+    TelemetryStopwatch.cancel(TELEMETRY_1ST_RESULT, this._lastQueryContext);
+    TelemetryStopwatch.cancel(TELEMETRY_6_FIRST_RESULTS, this._lastQueryContext);
 
-    this.manager.cancelQuery(queryContext);
-    this._notify("onQueryCancelled", queryContext);
+    this.manager.cancelQuery(this._lastQueryContext);
+    this._notify("onQueryCancelled", this._lastQueryContext);
+    delete this._lastQueryContext;
   }
 
   /**
    * Receives results from a query.
    *
    * @param {UrlbarQueryContext} queryContext The query details.
    */
   receiveResults(queryContext) {
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -132,16 +132,17 @@ class UrlbarInput {
   /**
    * Applies styling to the text in the urlbar input, depending on the text.
    */
   formatValue() {
     this.valueFormatter.update();
   }
 
   closePopup() {
+    this.controller.cancelQuery();
     this.view.close();
   }
 
   /**
    * Converts an internal URI (e.g. a wyciwyg URI) into one which we can
    * expose to the user.
    *
    * @param {nsIURI} uri
@@ -851,16 +852,17 @@ class UrlbarInput {
 
     insertLocation.insertAdjacentElement("afterend", pasteAndGo);
   }
 
   // Event handlers below.
 
   _on_blur(event) {
     this.formatValue();
+    this.closePopup();
   }
 
   _on_focus(event) {
     this._updateUrlTooltip();
 
     this.formatValue();
   }
 
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -36,16 +36,18 @@ class UrlbarView {
 
     this._rows.addEventListener("mouseup", this);
 
     // For the horizontal fade-out effect, set the overflow attribute on result
     // rows when they overflow.
     this._rows.addEventListener("overflow", this);
     this._rows.addEventListener("underflow", this);
 
+    this.panel.addEventListener("popuphiding", this);
+
     this.controller.setView(this);
     this.controller.addQueryListener(this);
   }
 
   get oneOffSearchButtons() {
     return this._oneOffSearchButtons ||
       (this._oneOffSearchButtons =
          new this.window.SearchOneOffs(this.panel.querySelector(".search-one-offs")));
@@ -395,9 +397,13 @@ class UrlbarView {
     }
   }
 
   _on_underflow(event) {
     if (event.target.classList.contains("urlbarView-row-inner")) {
       event.target.toggleAttribute("overflow", false);
     }
   }
+
+  _on_popuphiding(event) {
+    this.controller.cancelQuery();
+  }
 }
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -10,20 +10,18 @@ support-files =
   head-common.js
 
 [browser_bug562649.js]
 support-files = file_bug562649.html
 [browser_bug623155.js]
 support-files =
   redirect_bug623155.sjs
 [browser_bug783614.js]
-skip-if = true # Bug 1521490
 [browser_bug1025195_switchToTabHavingURI_aOpenParams.js]
 [browser_locationBarExternalLoad.js]
-skip-if = true # Bug 1521490
 [browser_moz_action_link.js]
 [browser_populateAfterPushState.js]
 [browser_urlbar_blanking.js]
 support-files =
   file_blank_but_not_blank.html
 [browser_urlbar_content_opener.js]
 [browser_urlbar_locationchange_urlbar_edit_dos.js]
 support-files =
--- a/browser/components/urlbar/tests/unit/test_UrlbarController_unit.js
+++ b/browser/components/urlbar/tests/unit/test_UrlbarController_unit.js
@@ -167,18 +167,23 @@ add_task(function test_handle_query_star
     "Should have passed the controller as the second argument");
 
   sandbox.resetHistory();
 
   Services.prefs.clearUserPref("browser.urlbar.autoFill");
 });
 
 add_task(function test_cancel_query() {
+  // Ensure the controller doesn't have any previous queries.
+  delete controller._lastQueryContext;
+
   const context = createContext();
-  controller.cancelQuery(context);
+  controller.startQuery(context);
+
+  controller.cancelQuery();
 
   Assert.equal(fPM.cancelQuery.callCount, 1,
     "Should have called cancelQuery once");
   Assert.equal(fPM.cancelQuery.args[0].length, 1,
     "Should have called cancelQuery with one argument");
 
   Assert.equal(generalListener.onQueryCancelled.callCount, 1,
     "Should have called onQueryCancelled for the listener");