Bug 1504854 - Autofilled search shortcuts should show a single "Search with Engine" heuristic result in the popup r=mak
authorDrew Willcoxon <adw@mozilla.com>
Mon, 12 Nov 2018 15:45:39 +0000
changeset 445984 867aaeefa9adf5e160b198d6ea55b1d2c3c02aa3
parent 445983 8105dec7146e2fdba5c88ba65721c2ff51574fef
child 445985 0557cad00db4733570bbf912c0fe9fc8641ac004
push id35031
push usernerli@mozilla.com
push dateTue, 13 Nov 2018 16:25:26 +0000
treeherdermozilla-central@2655a3d8dcd9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1504854
milestone65.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 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
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_autofill_search_engine_aliases.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -1109,17 +1109,17 @@ Search.prototype = {
       this._addSearchEngineMatch({
         engine,
         alias: tokenAliases[0],
       });
     }
     return true;
   },
 
-  async _matchSearchEngineTokenAlias() {
+  async _matchSearchEngineTokenAliasForAutofill() {
     // We need a single "@engine" search token.
     if (this._searchTokens.length != 1) {
       return false;
     }
     let token = this._searchTokens[0];
     if (token[0] != "@" || token.length == 1) {
       return false;
     }
@@ -1147,16 +1147,27 @@ Search.prototype = {
               searchQuery: "",
             }),
             comment: engine.name,
             frecency: FRECENCY_DEFAULT,
             style: "autofill action searchengine",
             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;
         }
       }
     }
 
     return false;
   },
 
@@ -1219,17 +1230,17 @@ Search.prototype = {
     if (this.pending && shouldAutofill) {
       let matched = this._matchPreloadedSiteForAutofill();
       if (matched) {
         return true;
       }
     }
 
     if (this.pending && shouldAutofill) {
-      let matched = await this._matchSearchEngineTokenAlias();
+      let matched = await this._matchSearchEngineTokenAliasForAutofill();
       if (matched) {
         return true;
       }
     }
 
     if (this.pending && hasSearchTerms && this._enableActions) {
       // If we don't have a result that matches what we know about, then
       // we use a fallback for things we don't know about.
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_search_engine_aliases.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_search_engine_aliases.js
@@ -19,16 +19,24 @@ add_task(async function init() {
     let engine = Services.search.getEngineByName(TEST_ENGINE_NAME);
     Assert.ok(engine);
     Services.search.removeEngine(engine);
   });
 });
 
 // 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,
     alias: TEST_ENGINE_ALIAS,
     input: autofilledValue,
     searchQuery: "",
   });
   await check_autocomplete({
@@ -44,16 +52,24 @@ add_task(async function basic() {
     }],
   });
   await cleanup();
 });
 
 // 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));
   let alias = search + TEST_ENGINE_ALIAS.substr(search.length);
   let autofilledValue = alias + " ";
   let completedURL = PlacesUtils.mozActionURI("searchengine", {
     engineName: TEST_ENGINE_NAME,
     alias,