Bug 1376986 - Remove ability to customize restriction tokens. r=mak draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 29 Jun 2017 01:10:37 +0100
changeset 602014 1121d85ee910eb7e84a346cb1ead4c591e2ca066
parent 601465 d858e9a1e21746612793c52230146472bc47df2f
child 635428 d89081159bdf1331141ec4b33aafe30d1b441836
push id66243
push userbmo:paolo.mozmail@amadzone.org
push dateThu, 29 Jun 2017 12:49:47 +0000
reviewersmak
bugs1376986
milestone56.0a1
Bug 1376986 - Remove ability to customize restriction tokens. r=mak MozReview-Commit-ID: 3JuLExJwF6z
browser/app/profile/firefox.js
browser/base/content/test/urlbar/browser_tabMatchesInAwesomebar.js
browser/components/sessionstore/test/browser_599909.js
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
toolkit/components/places/tests/unifiedcomplete/test_special_search.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -309,28 +309,16 @@ pref("browser.urlbar.filter.javascript",
 
 // the maximum number of results to show in autocomplete when doing richResults
 pref("browser.urlbar.maxRichResults", 10);
 // The amount of time (ms) to wait after the user has stopped typing
 // before starting to perform autocomplete.  50 is the default set in
 // autocomplete.xml.
 pref("browser.urlbar.delay", 50);
 
-// The special characters below can be typed into the urlbar to either restrict
-// the search to visited history, bookmarked, tagged pages; or force a match on
-// just the title text or url.
-pref("browser.urlbar.restrict.history", "^");
-pref("browser.urlbar.restrict.bookmark", "*");
-pref("browser.urlbar.restrict.tag", "+");
-pref("browser.urlbar.restrict.openpage", "%");
-pref("browser.urlbar.restrict.typed", "~");
-pref("browser.urlbar.restrict.searches", "$");
-pref("browser.urlbar.match.title", "#");
-pref("browser.urlbar.match.url", "@");
-
 // The default behavior for the urlbar can be configured to use any combination
 // of the match filters with each additional filter adding more results (union).
 pref("browser.urlbar.suggest.history",              true);
 pref("browser.urlbar.suggest.bookmark",             true);
 pref("browser.urlbar.suggest.openpage",             true);
 pref("browser.urlbar.suggest.searches",             true);
 pref("browser.urlbar.userMadeSearchSuggestionsChoice", false);
 // The suggestion opt-in notification will be shown on 4 different days.
--- a/browser/base/content/test/urlbar/browser_tabMatchesInAwesomebar.js
+++ b/browser/base/content/test/urlbar/browser_tabMatchesInAwesomebar.js
@@ -6,16 +6,18 @@
 
 requestLongerTimeout(2);
 
 const TEST_URL_BASES = [
   "http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html#tabmatch",
   "http://example.org/browser/browser/base/content/test/urlbar/moz.png#tabmatch"
 ];
 
+const RESTRICT_TOKEN_OPENPAGE = "%";
+
 var gController = Cc["@mozilla.org/autocomplete/controller;1"].
                   getService(Ci.nsIAutoCompleteController);
 
 var gTabCounter = 0;
 
 add_task(async function step_1() {
   info("Running step 1");
   let maxResults = Services.prefs.getIntPref("browser.urlbar.maxRichResults");
@@ -204,10 +206,10 @@ function checkAutocompleteResults(aExpec
     getSearchAt(aIndex) { return this.searches[aIndex]; },
     QueryInterface: XPCOMUtils.generateQI([
       Ci.nsIAutoCompleteInput,
       Ci.nsIAutoCompletePopup,
     ])
   };
 
   info("Searching open pages.");
-  gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage"));
+  gController.startSearch(RESTRICT_TOKEN_OPENPAGE);
 }
--- a/browser/components/sessionstore/test/browser_599909.js
+++ b/browser/components/sessionstore/test/browser_599909.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+const RESTRICT_TOKEN_OPENPAGE = "%";
+
 var stateBackup = ss.getBrowserState();
 
 function cleanup() {
   // Reset the prefs
   Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
   Services.prefs.clearUserPref("browser.sessionstore.restore_tabs_lazily");
   ss.setBrowserState(stateBackup);
   executeSoon(finish);
@@ -111,10 +113,10 @@ function checkAutocompleteResults(aExpec
     },
     QueryInterface: XPCOMUtils.generateQI([
       Ci.nsIAutoCompleteInput,
       Ci.nsIAutoCompletePopup,
     ])
   };
 
   info("Searching open pages.");
-  gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage"));
+  gController.startSearch(RESTRICT_TOKEN_OPENPAGE);
 }
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -27,24 +27,16 @@ const PREF_ENABLED =                [ "a
 const PREF_AUTOFILL =               [ "autoFill",               true ];
 const PREF_AUTOFILL_TYPED =         [ "autoFill.typed",         true ];
 const PREF_AUTOFILL_SEARCHENGINES = [ "autoFill.searchEngines", false ];
 const PREF_RESTYLESEARCHES        = [ "restyleSearches",        false ];
 const PREF_DELAY =                  [ "delay",                  50 ];
 const PREF_BEHAVIOR =               [ "matchBehavior", MATCH_BOUNDARY_ANYWHERE ];
 const PREF_FILTER_JS =              [ "filter.javascript",      true ];
 const PREF_MAXRESULTS =             [ "maxRichResults",         25 ];
-const PREF_RESTRICT_HISTORY =       [ "restrict.history",       "^" ];
-const PREF_RESTRICT_BOOKMARKS =     [ "restrict.bookmark",      "*" ];
-const PREF_RESTRICT_TYPED =         [ "restrict.typed",         "~" ];
-const PREF_RESTRICT_TAG =           [ "restrict.tag",           "+" ];
-const PREF_RESTRICT_SWITCHTAB =     [ "restrict.openpage",      "%" ];
-const PREF_RESTRICT_SEARCHES =      [ "restrict.searches",      "$" ];
-const PREF_MATCH_TITLE =            [ "match.title",            "#" ];
-const PREF_MATCH_URL =              [ "match.url",              "@" ];
 
 const PREF_SUGGEST_HISTORY =        [ "suggest.history",        true ];
 const PREF_SUGGEST_BOOKMARK =       [ "suggest.bookmark",       true ];
 const PREF_SUGGEST_OPENPAGE =       [ "suggest.openpage",       true ];
 const PREF_SUGGEST_HISTORY_ONLYTYPED = [ "suggest.history.onlyTyped", false ];
 const PREF_SUGGEST_SEARCHES =       [ "suggest.searches",       false ];
 
 const PREF_MAX_CHARS_FOR_SUGGEST =  [ "maxCharsForSearchSuggestions", 20];
@@ -98,16 +90,30 @@ const QUERYINDEX_BOOKMARKED    = 3;
 const QUERYINDEX_BOOKMARKTITLE = 4;
 const QUERYINDEX_TAGS          = 5;
 const QUERYINDEX_VISITCOUNT    = 6;
 const QUERYINDEX_TYPED         = 7;
 const QUERYINDEX_PLACEID       = 8;
 const QUERYINDEX_SWITCHTAB     = 9;
 const QUERYINDEX_FRECENCY      = 10;
 
+// The special characters below can be typed into the urlbar to either restrict
+// the search to visited history, bookmarked, tagged pages; or force a match on
+// just the title text or url.
+const TOKEN_TO_BEHAVIOR_MAP = new Map([
+  ["^", "history"],
+  ["*", "bookmark"],
+  ["+", "tag"],
+  ["%", "openpage"],
+  ["~", "typed"],
+  ["$", "searches"],
+  ["#", "title"],
+  ["@", "url"],
+]);
+
 // If a URL starts with one of these prefixes, then we don't provide search
 // suggestions for it.
 const DISALLOWED_URLLIKE_PREFIXES = [
   "http", "https", "ftp"
 ];
 
 // This SQL query fragment provides the following:
 //   - whether the entry is bookmarked (QUERYINDEX_BOOKMARKED)
@@ -444,24 +450,16 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
     store.autofill = prefs.get(...PREF_AUTOFILL);
     store.autofillTyped = prefs.get(...PREF_AUTOFILL_TYPED);
     store.autofillSearchEngines = prefs.get(...PREF_AUTOFILL_SEARCHENGINES);
     store.restyleSearches = prefs.get(...PREF_RESTYLESEARCHES);
     store.delay = prefs.get(...PREF_DELAY);
     store.matchBehavior = prefs.get(...PREF_BEHAVIOR);
     store.filterJavaScript = prefs.get(...PREF_FILTER_JS);
     store.maxRichResults = prefs.get(...PREF_MAXRESULTS);
-    store.restrictHistoryToken = prefs.get(...PREF_RESTRICT_HISTORY);
-    store.restrictBookmarkToken = prefs.get(...PREF_RESTRICT_BOOKMARKS);
-    store.restrictTypedToken = prefs.get(...PREF_RESTRICT_TYPED);
-    store.restrictTagToken = prefs.get(...PREF_RESTRICT_TAG);
-    store.restrictOpenPageToken = prefs.get(...PREF_RESTRICT_SWITCHTAB);
-    store.restrictSearchesToken = prefs.get(...PREF_RESTRICT_SEARCHES);
-    store.matchTitleToken = prefs.get(...PREF_MATCH_TITLE);
-    store.matchURLToken = prefs.get(...PREF_MATCH_URL);
     store.suggestHistory = prefs.get(...PREF_SUGGEST_HISTORY);
     store.suggestBookmark = prefs.get(...PREF_SUGGEST_BOOKMARK);
     store.suggestOpenpage = prefs.get(...PREF_SUGGEST_OPENPAGE);
     store.suggestTyped = prefs.get(...PREF_SUGGEST_HISTORY_ONLYTYPED);
     store.suggestSearches = prefs.get(...PREF_SUGGEST_SEARCHES);
     store.maxCharsForSearchSuggestions = prefs.get(...PREF_MAX_CHARS_FOR_SUGGEST);
     store.preloadedSitesEnabled = prefs.get(...PREF_PRELOADED_SITES_ENABLED);
     store.preloadedSitesExpireDays = prefs.get(...PREF_PRELOADED_SITES_EXPIRE_DAYS);
@@ -493,26 +491,16 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
 
     // Validate matchBehavior; default to MATCH_BOUNDARY_ANYWHERE.
     if (store.matchBehavior != MATCH_ANYWHERE &&
         store.matchBehavior != MATCH_BOUNDARY &&
         store.matchBehavior != MATCH_BEGINNING) {
       store.matchBehavior = MATCH_BOUNDARY_ANYWHERE;
     }
 
-    store.tokenToBehaviorMap = new Map([
-      [ store.restrictHistoryToken, "history" ],
-      [ store.restrictBookmarkToken, "bookmark" ],
-      [ store.restrictTagToken, "tag" ],
-      [ store.restrictOpenPageToken, "openpage" ],
-      [ store.matchTitleToken, "title" ],
-      [ store.matchURLToken, "url" ],
-      [ store.restrictTypedToken, "typed" ],
-      [ store.restrictSearchesToken, "searches" ],
-    ]);
   }
 
   let store = {
     _ignoreNotifications: false,
     observe(subject, topic, data) {
       // Avoid re-entrancy when flipping linked preferences.
       if (this._ignoreNotifications)
         return;
@@ -853,17 +841,17 @@ Search.prototype = {
    * @param tokens
    *        An array of search tokens.
    * @return the filtered list of tokens to search with.
    */
   filterTokens(tokens) {
     let foundToken = false;
     // Set the proper behavior while filtering tokens.
     for (let i = tokens.length - 1; i >= 0; i--) {
-      let behavior = Prefs.tokenToBehaviorMap.get(tokens[i]);
+      let behavior = TOKEN_TO_BEHAVIOR_MAP.get(tokens[i]);
       // Don't remove the token if it didn't match, or if it's an action but
       // actions are not enabled.
       if (behavior && (behavior != "openpage" || this._enableActions)) {
         // Don't use the suggest preferences if it is a token search and
         // set the restrict bit to 1 (to intersect the search results).
         if (!foundToken) {
           foundToken = true;
           // Do not take into account previous behavior (e.g.: history, bookmark)
--- a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
+++ b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
@@ -319,39 +319,16 @@ function addOpenPages(aUri, aCount = 1, 
 function removeOpenPages(aUri, aCount = 1, aUserContextId = 0) {
   let ac = Cc["@mozilla.org/autocomplete/search;1?name=unifiedcomplete"]
              .getService(Ci.mozIPlacesAutoComplete);
   for (let i = 0; i < aCount; i++) {
     ac.unregisterOpenPage(aUri, aUserContextId);
   }
 }
 
-function changeRestrict(aType, aChar) {
-  let branch = "browser.urlbar.";
-  // "title" and "url" are different from everything else, so special case them.
-  if (aType == "title" || aType == "url")
-    branch += "match.";
-  else
-    branch += "restrict.";
-
-  do_print("changing restrict for " + aType + " to '" + aChar + "'");
-  Services.prefs.setCharPref(branch + aType, aChar);
-}
-
-function resetRestrict(aType) {
-  let branch = "browser.urlbar.";
-  // "title" and "url" are different from everything else, so special case them.
-  if (aType == "title" || aType == "url")
-    branch += "match.";
-  else
-    branch += "restrict.";
-
-  Services.prefs.clearUserPref(branch + aType);
-}
-
 /**
  * Strip prefixes from the URI that we don't care about for searching.
  *
  * @param {String} spec
  *        The text to modify.
  * @return {String} the modified spec.
  */
 function stripPrefix(spec) {
--- a/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
@@ -117,144 +117,70 @@ add_task(async function test_special_sea
     search: "foo ^",
     matches: [ { uri: uri2, title: "foo.bar" },
                { uri: uri3, title: "title" },
                { uri: uri4, title: "foo.bar" },
                { uri: uri6, title: "foo.bar" },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
   });
 
-  do_print("foo | -> history (change pref)");
-  changeRestrict("history", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri2, title: "foo.bar" },
-               { uri: uri3, title: "title" },
-               { uri: uri4, title: "foo.bar" },
-               { uri: uri6, title: "foo.bar" },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
-  });
-
   do_print("foo * -> is star");
-  resetRestrict("history");
   await check_autocomplete({
     search: "foo *",
     matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri7, title: "title", style: [ "bookmark" ] },
                { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
                { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
   });
 
-  do_print("foo | -> is star (change pref)");
-  changeRestrict("bookmark", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
-               { uri: uri7, title: "title", style: [ "bookmark" ] },
-               { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
-               { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
-  });
-
   do_print("foo # -> in title");
-  resetRestrict("bookmark");
   await check_autocomplete({
     search: "foo #",
     matches: [ { uri: uri2, title: "foo.bar" },
                { uri: uri4, title: "foo.bar" },
                { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
   });
 
-  do_print("foo | -> in title (change pref)");
-  changeRestrict("title", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri2, title: "foo.bar" },
-               { uri: uri4, title: "foo.bar" },
-               { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
-               { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
-               { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
-  });
-
   do_print("foo @ -> in url");
-  resetRestrict("title");
   await check_autocomplete({
     search: "foo @",
     matches: [ { uri: uri3, title: "title" },
                { uri: uri4, title: "foo.bar" },
                { uri: uri7, title: "title", style: [ "bookmark" ] },
                { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
   });
 
-  do_print("foo | -> in url (change pref)");
-  changeRestrict("url", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri3, title: "title" },
-               { uri: uri4, title: "foo.bar" },
-               { uri: uri7, title: "title", style: [ "bookmark" ] },
-               { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
-  });
-
   do_print("foo + -> is tag");
-  resetRestrict("url");
   await check_autocomplete({
     search: "foo +",
     matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
   });
 
-  do_print("foo | -> is tag (change pref)");
-  changeRestrict("tag", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
-  });
-
   do_print("foo ~ -> is typed");
-  resetRestrict("tag");
   await check_autocomplete({
     search: "foo ~",
     matches: [ { uri: uri4, title: "foo.bar" },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
   });
 
-  do_print("foo | -> is typed (change pref)");
-  changeRestrict("typed", "|");
-  await check_autocomplete({
-    search: "foo |",
-    matches: [ { uri: uri4, title: "foo.bar" },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
-  });
-
   // Test various pairs of special searches
   do_print("foo ^ * -> history, is star");
-  resetRestrict("typed");
   await check_autocomplete({
     search: "foo ^ *",
     matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
   });
 
   do_print("foo ^ # -> history, in title");
   await check_autocomplete({