Bug 1240727 - match search engine alias with lower case; r=mak
authorgasolin <gasolin@gmail.com>
Tue, 29 Mar 2016 11:47:41 +0800
changeset 291337 642e91672f8ae6738f48c93d0846d65dbc0eb2f2
parent 291336 abba7d7115a474289ad30f375ce2e95e3af52f58
child 291338 1d794d077cb1d12228185a0b9f6bbf64c56b8513
push id74545
push userkwierso@gmail.com
push dateFri, 01 Apr 2016 23:05:42 +0000
treeherdermozilla-inbound@c410d4e20586 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1240727
milestone48.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 1240727 - match search engine alias with lower case; r=mak matching both alias and searchToken with lower case, add tests to validate lower, upper, cap cases MozReview-Commit-ID: F8aNsilK5pm
toolkit/components/places/PlacesSearchAutocompleteProvider.jsm
toolkit/components/places/tests/unit/test_PlacesSearchAutocompleteProvider.js
--- a/toolkit/components/places/PlacesSearchAutocompleteProvider.jsm
+++ b/toolkit/components/places/PlacesSearchAutocompleteProvider.jsm
@@ -237,17 +237,17 @@ this.PlacesSearchAutocompleteProvider = 
    *           engineName: The display name of the search engine.
    *           iconUrl: Icon associated to the match, or null if not available.
    *         }
    */
   findMatchByAlias: Task.async(function* (searchToken) {
     yield this.ensureInitialized();
 
     return SearchAutocompleteProviderInternal.aliasMatches
-                                             .find(m => m.alias == searchToken);
+             .find(m => m.alias.toLocaleLowerCase() == searchToken.toLocaleLowerCase());
   }),
 
   getDefaultMatch: Task.async(function* () {
     yield this.ensureInitialized();
 
     return SearchAutocompleteProviderInternal.defaultMatch;
   }),
 
--- a/toolkit/components/places/tests/unit/test_PlacesSearchAutocompleteProvider.js
+++ b/toolkit/components/places/tests/unit/test_PlacesSearchAutocompleteProvider.js
@@ -45,21 +45,54 @@ add_task(function* add_search_engine_mat
   let match = yield PlacesSearchAutocompleteProvider.findMatchByToken("bacon");
   do_check_eq(match.url, "http://www.bacon.moz");
   do_check_eq(match.engineName, "bacon");
   do_check_eq(match.iconUrl, null);
 });
 
 add_task(function* test_aliased_search_engine_match() {
   do_check_eq(null, yield PlacesSearchAutocompleteProvider.findMatchByAlias("sober"));
-
+  // Lower case
   let match = yield PlacesSearchAutocompleteProvider.findMatchByAlias("pork");
   do_check_eq(match.engineName, "bacon");
   do_check_eq(match.alias, "pork");
   do_check_eq(match.iconUrl, null);
+  // Upper case
+  let match1 = yield PlacesSearchAutocompleteProvider.findMatchByAlias("PORK");
+  do_check_eq(match1.engineName, "bacon");
+  do_check_eq(match1.alias, "pork");
+  do_check_eq(match1.iconUrl, null);
+  // Cap case
+  let match2 = yield PlacesSearchAutocompleteProvider.findMatchByAlias("Pork");
+  do_check_eq(match2.engineName, "bacon");
+  do_check_eq(match2.alias, "pork");
+  do_check_eq(match2.iconUrl, null);
+});
+
+add_task(function* test_aliased_search_engine_match_upper_case_alias() {
+  let promiseTopic = promiseSearchTopic("engine-added");
+  do_check_eq(null, yield PlacesSearchAutocompleteProvider.findMatchByToken("patch"));
+  Services.search.addEngineWithDetails("patch", "", "PR", "Search Patch",
+                                       "GET", "http://www.patch.moz/?search={searchTerms}");
+  yield promiseSearchTopic;
+  // lower case
+  let match = yield PlacesSearchAutocompleteProvider.findMatchByAlias("pr");
+  do_check_eq(match.engineName, "patch");
+  do_check_eq(match.alias, "PR");
+  do_check_eq(match.iconUrl, null);
+  // Upper case
+  let match1 = yield PlacesSearchAutocompleteProvider.findMatchByAlias("PR");
+  do_check_eq(match1.engineName, "patch");
+  do_check_eq(match1.alias, "PR");
+  do_check_eq(match1.iconUrl, null);
+  // Cap case
+  let match2 = yield PlacesSearchAutocompleteProvider.findMatchByAlias("Pr");
+  do_check_eq(match2.engineName, "patch");
+  do_check_eq(match2.alias, "PR");
+  do_check_eq(match2.iconUrl, null);
 });
 
 add_task(function* remove_search_engine_nomatch() {
   let engine = Services.search.getEngineByName("bacon");
   let promiseTopic = promiseSearchTopic("engine-removed");
   Services.search.removeEngine(engine);
   yield promiseTopic;
   do_check_eq(null, yield PlacesSearchAutocompleteProvider.findMatchByToken("bacon"));