Bug 1504854 - Autofilled search shortcuts should show a single "Search with Engine" heuristic result in the popup r=mak

All we need to do is set `_searchEngineAliasMatch` with an empty query so that we don't try to add any more results. That hits the existing case where the user types out a full @ alias and we show only the "search with engine" heuristic result.

Differential Revision: https://phabricator.services.mozilla.com/D11547

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Drew Willcoxon 2018-11-12 15:45:39 +00:00
Родитель 478074e691
Коммит b6884c7920
2 изменённых файлов: 29 добавлений и 2 удалений

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

@ -1114,7 +1114,7 @@ Search.prototype = {
return true;
},
async _matchSearchEngineTokenAlias() {
async _matchSearchEngineTokenAliasForAutofill() {
// We need a single "@engine" search token.
if (this._searchTokens.length != 1) {
return false;
@ -1152,6 +1152,17 @@ Search.prototype = {
icon: engine.iconURI ? engine.iconURI.spec : null,
});
this._result.setDefaultIndex(0);
// Set _searchEngineAliasMatch with an empty query so that we don't
// attempt to add any more matches. When a token alias is autofilled,
// the only match should be the one we just added.
this._searchEngineAliasMatch = {
engine,
alias: aliasPreservingUserCase,
query: "",
isTokenAlias: true,
};
return true;
}
}
@ -1224,7 +1235,7 @@ Search.prototype = {
}
if (this.pending && shouldAutofill) {
let matched = await this._matchSearchEngineTokenAlias();
let matched = await this._matchSearchEngineTokenAliasForAutofill();
if (matched) {
return true;
}

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

@ -24,6 +24,14 @@ add_task(async function init() {
// Searching for @autofi should autofill to @autofilltest.
add_task(async function basic() {
// Add a history visit that should normally match but for the fact that the
// search uses an @ alias. When an @ alias is autofilled, there should be no
// other matches except the autofill heuristic match.
await PlacesTestUtils.addVisits({
uri: "http://example.com/",
title: TEST_ENGINE_ALIAS,
});
let autofilledValue = TEST_ENGINE_ALIAS + " ";
let completedURL = PlacesUtils.mozActionURI("searchengine", {
engineName: TEST_ENGINE_NAME,
@ -49,6 +57,14 @@ add_task(async function basic() {
// Searching for @AUTOFI should autofill to @AUTOFIlltest, preserving the case
// in the search string.
add_task(async function preserveCase() {
// Add a history visit that should normally match but for the fact that the
// search uses an @ alias. When an @ alias is autofilled, there should be no
// other matches except the autofill heuristic match.
await PlacesTestUtils.addVisits({
uri: "http://example.com/",
title: TEST_ENGINE_ALIAS,
});
let search =
TEST_ENGINE_ALIAS.toUpperCase()
.substr(0, Math.round(TEST_ENGINE_ALIAS.length / 2));