Bug 1628557 - Address bar results aren't cleared if the new query returns no results. r=harry

Differential Revision: https://phabricator.services.mozilla.com/D73279
This commit is contained in:
Marco Bonardo 2020-04-30 15:43:16 +00:00
Родитель 2899e6425d
Коммит 6ebc5624fc
3 изменённых файлов: 54 добавлений и 2 удалений

Просмотреть файл

@ -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];

Просмотреть файл

@ -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 =

Просмотреть файл

@ -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.`);
});