diff --git a/browser/components/urlbar/UrlbarView.jsm b/browser/components/urlbar/UrlbarView.jsm index b6a5006aba30..b4e0359b6085 100644 --- a/browser/components/urlbar/UrlbarView.jsm +++ b/browser/components/urlbar/UrlbarView.jsm @@ -451,6 +451,7 @@ class UrlbarView { // UrlbarController listener methods. onQueryStarted(queryContext) { this._queryWasCancelled = false; + this._queryUpdatedResults = false; this._startRemoveStaleRowsTimer(); } @@ -461,9 +462,16 @@ class UrlbarView { onQueryFinished(queryContext) { this._cancelRemoveStaleRowsTimer(); - // If the query has not been canceled, remove stale rows immediately. if (!this._queryWasCancelled) { - this._removeStaleRows(); + // If the query has not been canceled and returned some results, remove + // stale rows immediately. If no results were returned, just clear and + // close the view. + if (this._queryUpdatedResults) { + this._removeStaleRows(); + } else { + this.clear(); + this.close(); + } } } @@ -474,6 +482,7 @@ class UrlbarView { if (!this.isOpen) { this.clear(); } + this._queryUpdatedResults = true; this._updateResults(queryContext); let firstResult = queryContext.results[0]; diff --git a/browser/components/urlbar/tests/browser/browser.ini b/browser/components/urlbar/tests/browser/browser.ini index bf8f4df0a1dd..044d2aba23e6 100644 --- a/browser/components/urlbar/tests/browser/browser.ini +++ b/browser/components/urlbar/tests/browser/browser.ini @@ -207,6 +207,7 @@ skip-if = (os == 'mac') # bug 1570474 [browser_userTypedValue.js] support-files = file_userTypedValue.html [browser_valueOnTabSwitch.js] +[browser_view_emptyResultSet.js] [browser_view_resultDisplay.js] [browser_view_resultTypes_display.js] support-files = diff --git a/browser/components/urlbar/tests/browser/browser_view_emptyResultSet.js b/browser/components/urlbar/tests/browser/browser_view_emptyResultSet.js new file mode 100644 index 000000000000..a4c0efd2757e --- /dev/null +++ b/browser/components/urlbar/tests/browser/browser_view_emptyResultSet.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Tests that the view results are cleared and the view is closed, when an empty +// result set arrives after a non-empty one. + +add_task(async function() { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + value: "foo", + }); + Assert.ok( + UrlbarTestUtils.getResultCount(window) > 0, + `There should be some results in the view.` + ); + Assert.ok(gURLBar.view.isOpen, `The view should be open.`); + + // Register an high priority empty result provider. + let provider = new UrlbarTestUtils.TestProvider({ + results: [], + priority: 999, + }); + UrlbarProvidersManager.registerProvider(provider); + registerCleanupFunction(async function() { + UrlbarProvidersManager.unregisterProvider(provider); + await PlacesUtils.history.clear(); + }); + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + value: "foo", + }); + Assert.ok( + UrlbarTestUtils.getResultCount(window) == 0, + `There should be no results in the view.` + ); + Assert.ok(!gURLBar.view.isOpen, `The view should have been closed.`); +});