Bug 1074167 - Autocomplete results for aliased search engines should use the search engine icon. r=mak
authorAlex Bardas <alex.bardas@gmail.com>
Fri, 10 Oct 2014 10:59:00 -0400
changeset 233203 412cf5315d9f37d7bed210d5b30423de8efb07f9
parent 233202 4978e73d44444ad1c1fc009316d0182aefc858f4
child 233204 a86a4468774af87c4c8a8e4627ef9b961880af6e
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1074167
milestone35.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 1074167 - Autocomplete results for aliased search engines should use the search engine icon. r=mak
browser/base/content/test/general/browser_action_searchengine.js
browser/base/content/test/general/browser_action_searchengine_alias.js
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_searchEngine_alias.js
toolkit/content/widgets/autocomplete.xml
--- a/browser/base/content/test/general/browser_action_searchengine.js
+++ b/browser/base/content/test/general/browser_action_searchengine.js
@@ -38,14 +38,16 @@ add_task(function* () {
       gBrowser.removeTab(tab);
     } catch(ex) { /* tab may have already been closed in case of failure */ }
 
     return promiseClearHistory();
   });
 
   let result = yield promise_first_result("open a search");
   isnot(result, null, "Should have a result");
+  is(result.hasAttribute("image"), false, "Result shouldn't have an image attribute");
+
   let tabPromise = promiseTabLoaded(gBrowser.selectedTab);
   EventUtils.synthesizeMouseAtCenter(result, {});
   yield tabPromise;
 
   is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search");
 });
--- a/browser/base/content/test/general/browser_action_searchengine_alias.js
+++ b/browser/base/content/test/general/browser_action_searchengine_alias.js
@@ -1,42 +1,48 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  **/
 
- let gOriginalEngine;
+let gOriginalEngine;
 
 add_task(function* () {
-  // This test is only relevant if UnifiedComplete is enabled.
-  if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete"))
-    return;
+  Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
 
-  Services.search.addEngineWithDetails("MozSearch", "", "moz", "", "GET",
+  let iconURI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC";
+  Services.search.addEngineWithDetails("MozSearch", iconURI, "moz", "", "GET",
                                        "http://example.com/?q={searchTerms}");
   let engine = Services.search.getEngineByName("MozSearch");
   gOriginalEngine = Services.search.currentEngine;
   Services.search.currentEngine = engine;
 
   let tab = gBrowser.selectedTab = gBrowser.addTab();
 
   registerCleanupFunction(() => {
     Services.search.currentEngine = gOriginalEngine;
     let engine = Services.search.getEngineByName("MozSearch");
     Services.search.removeEngine(engine);
+    Services.prefs.clearUserPref("browser.urlbar.unifiedcomplete");
 
     try {
       gBrowser.removeTab(tab);
     } catch(ex) { /* tab may have already been closed in case of failure */ }
 
     return promiseClearHistory();
   });
 
   gURLBar.focus();
   gURLBar.value = "moz open a searc";
   EventUtils.synthesizeKey("h" , {});
   yield promiseSearchComplete();
 
+  let result = gURLBar.popup.richlistbox.children[0];
+  ok(result.hasAttribute("image"), "Result should have an image attribute");
+  // Image attribute gets a suffix (-moz-resolution) added in the value.
+  ok(result.getAttribute("image").startsWith(engine.iconURI.spec),
+     "Image attribute should have the search engine's icon");
+
   EventUtils.synthesizeKey("VK_RETURN" , { });
   yield promiseTabLoaded(gBrowser.selectedTab);
 
   is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search");
 });
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -854,21 +854,22 @@ Search.prototype = {
     });
     return true;
   },
 
   _matchSearchEngineAlias: function* () {
     if (this._searchTokens.length < 2)
       return false;
 
-    let match = yield PlacesSearchAutocompleteProvider.findMatchByAlias(
-                                                         this._searchTokens[0]);
+    let alias = this._searchTokens[0];
+    let match = yield PlacesSearchAutocompleteProvider.findMatchByAlias(alias);
     if (!match)
       return false;
 
+    match.engineAlias = alias;
     let query = this._searchTokens.slice(1).join(" ");
 
     yield this._addSearchEngineMatch(match, query);
     return true;
   },
 
   _matchCurrentSearchEngine: function* () {
     let match = yield PlacesSearchAutocompleteProvider.getDefaultMatch();
@@ -876,21 +877,25 @@ Search.prototype = {
       return;
 
     let query = this._originalSearchString;
 
     yield this._addSearchEngineMatch(match, query);
   },
 
   _addSearchEngineMatch: function* (match, query) {
-    let value = makeActionURL("searchengine", {
+    let actionURLParams = {
       engineName: match.engineName,
       input: this._originalSearchString,
       searchQuery: query,
-    });
+    };
+    if (match.engineAlias) {
+      actionURLParams.alias = match.engineAlias;
+    }
+    let value = makeActionURL("searchengine", actionURLParams);
 
     this._addMatch({
       value: value,
       comment: match.engineName,
       icon: match.iconUrl,
       style: "action searchengine",
       finalCompleteValue: this._trimmedOriginalSearchString,
       frecency: FRECENCY_SEARCHENGINES_DEFAULT,
--- a/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_alias.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_alias.js
@@ -15,19 +15,19 @@ add_task(function*() {
     search: "doit",
     searchParam: "enable-actions",
     matches: [ { uri: makeActionURI("searchengine", {engineName: "MozSearch", input: "doit", searchQuery: "doit"}), title: "MozSearch" }, ]
   });
 
   yield check_autocomplete({
     search: "doit mozilla",
     searchParam: "enable-actions",
-    matches: [ { uri: makeActionURI("searchengine", {engineName: "AliasedMozSearch", input: "doit mozilla", searchQuery: "mozilla"}), title: "AliasedMozSearch" }, ]
+    matches: [ { uri: makeActionURI("searchengine", {engineName: "AliasedMozSearch", input: "doit mozilla", searchQuery: "mozilla", alias: "doit"}), title: "AliasedMozSearch" }, ]
   });
 
   yield check_autocomplete({
     search: "doit mozzarella mozilla",
     searchParam: "enable-actions",
-    matches: [ { uri: makeActionURI("searchengine", {engineName: "AliasedMozSearch", input: "doit mozzarella mozilla", searchQuery: "mozzarella mozilla"}), title: "AliasedMozSearch" }, ]
+    matches: [ { uri: makeActionURI("searchengine", {engineName: "AliasedMozSearch", input: "doit mozzarella mozilla", searchQuery: "mozzarella mozilla", alias: "doit"}), title: "AliasedMozSearch" }, ]
   });
 
   yield cleanup();
 });
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -1581,19 +1581,25 @@ extends="chrome://global/content/binding
             } else if (action.type == "searchengine") {
               emphasiseUrl = false;
 
               let sourceStr = this._stringBundle.GetStringFromName("searchWithEngineForQuery");
               title = this._generateEmphasisPairs(sourceStr, [
                                                     [action.params.engineName, false],
                                                     [action.params.searchQuery, true]
                                                   ]);
-              // Remove the image, so we can style it ourselves with a generic
-              // search icon.
-              this.removeAttribute("image");
+              // If this is a default search match, we remove the image so we
+              // can style it ourselves with a generic search icon.
+              // We don't do this when matching an aliased search engine,
+              // because the icon helps with recognising which engine will be
+              // used (when using the default engine, we don't need that
+              // recognition).
+              if (!action.params.alias) {
+                this.removeAttribute("image");
+              }
             } else if (action.type == "visiturl") {
               emphasiseUrl = false;
               url = action.params.url;
 
               let sourceStr = this._stringBundle.GetStringFromName("visitURL");
               title = this._generateEmphasisPairs(sourceStr, [
                                                     [trimURL(url), true],
                                                   ]);