Bug 509566 - Location bar does not respect tag filter preference
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Tue, 11 Aug 2009 13:38:10 -0700
changeset 26283 016941cc64aa5374ceeec63a993232f326b79db9
parent 26282 43af583d6464a628236e26c258d6535e3890141d
child 26284 dcb2a386b619f6aac910acb380d97dc160b57f7d
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs509566, 455555
Bug 509566 - Location bar does not respect tag filter preference Fixes a regression from Bug 455555 that makes us no longer respect the tag filter preference and always use the default. Also adds tests to make sure we do not break any of our filter preferences in the future. r=dietrich
suite/common/places/src/nsPlacesAutoComplete.js
suite/common/places/tests/autocomplete/test_special_search.js
--- a/suite/common/places/src/nsPlacesAutoComplete.js
+++ b/suite/common/places/src/nsPlacesAutoComplete.js
@@ -686,17 +686,17 @@ nsPlacesAutoComplete.prototype = {
 
     this._enabled = safeGetter("autocomplete.enabled", true);
     this._matchBehavior = safeGetter("matchBehavior", MATCH_BOUNDARY_ANYWHERE);
     this._filterJavaScript = safeGetter("filter.javascript", true);
     this._maxRichResults = safeGetter("maxRichResults", 25);
     this._restrictHistoryToken = safeGetter("restrict.history", "^");
     this._restrictBookmarkToken = safeGetter("restrict.bookmark", "*");
     this._restrictTypedToken = safeGetter("restrict.typed", "~");
-    this._restrictTagToken = safeGetter("restrct.tag", "+");
+    this._restrictTagToken = safeGetter("restrict.tag", "+");
     this._matchTitleToken = safeGetter("match.title", "#");
     this._matchURLToken = safeGetter("match.url", "@");
     this._defaultBehavior = safeGetter("default.behavior", 0);
 
     // Validate matchBehavior; default to MATCH_BOUNDARY_ANYWHERE.
     if (this._matchBehavior != MATCH_ANYWHERE &&
         this._matchBehavior != MATCH_BOUNDARY &&
         this._matchBehavior != MATCH_BEGINNING)
--- a/suite/common/places/tests/autocomplete/test_special_search.js
+++ b/suite/common/places/tests/autocomplete/test_special_search.js
@@ -101,32 +101,44 @@ let gTests = [
   ["3: Special as first word",
    "^ foo bar", [1,2,3,5,10], ignoreTags],
   ["4: Special as middle word",
    "foo ^ bar", [1,2,3,5,10], ignoreTags],
   ["5: Special as last word",
    "foo bar ^", [1,2,3,5,10], ignoreTags],
 
   // Test restricting and matching searches with a term
-  ["6: foo ^ -> history",
+  ["6.1: foo ^ -> history",
    "foo ^", [1,2,3,5,10], ignoreTags],
-  ["7: foo * -> is star",
-   "foo *", [5,6,7,8,9,10,11]],
-  ["8: foo # -> in title",
-   "foo #", [1,3,5,7,8,9,10,11]],
-  ["9: foo @ -> in url",
-   "foo @", [2,3,6,7,10,11]],
+  ["6.2: foo | -> history (change pref)",
+   "foo |", [1,2,3,5,10], function() {ignoreTags(); changeRestrict("history", "|"); }],
+  ["7.1: foo * -> is star",
+   "foo *", [5,6,7,8,9,10,11], function() resetRestrict("history")],
+  ["7.2: foo | -> is star (change pref)",
+   "foo |", [5,6,7,8,9,10,11], function() changeRestrict("bookmark", "|")],
+  ["8.1: foo # -> in title",
+   "foo #", [1,3,5,7,8,9,10,11], function() resetRestrict("bookmark")],
+  ["8.2: foo | -> in title (change pref)",
+   "foo |", [1,3,5,7,8,9,10,11], function() changeRestrict("title", "|")],
+  ["9.1: foo @ -> in url",
+   "foo @", [2,3,6,7,10,11], function() resetRestrict("title")],
+  ["9.2: foo | -> in url (change pref)",
+   "foo |", [2,3,6,7,10,11], function() changeRestrict("url", "|")],
   ["10: foo + -> is tag",
-   "foo +", [8,9,10,11]],
-  ["10.1: foo ~ -> is typed",
-   "foo ~", [3,10]],
+   "foo +", [8,9,10,11], function() resetRestrict("url")],
+  ["10.2: foo | -> is tag (change pref)",
+   "foo |", [8,9,10,11], function() changeRestrict("tag", "|")],
+  ["10.3: foo ~ -> is typed",
+   "foo ~", [3,10], function() resetRestrict("tag")],
+  ["10.4: foo | -> is typed (change pref)",
+   "foo |", [3,10], function() changeRestrict("typed", "|")],
 
   // Test various pairs of special searches
   ["11: foo ^ * -> history, is star",
-   "foo ^ *", [5,10]],
+   "foo ^ *", [5,10], function() resetRestrict("typed")],
   ["12: foo ^ # -> history, in title",
    "foo ^ #", [1,3,5,10], ignoreTags],
   ["13: foo ^ @ -> history, in url",
    "foo ^ @", [2,3,10], ignoreTags],
   ["14: foo ^ + -> history, is tag",
    "foo ^ +", [10]],
   ["14.1: foo ^ ~ -> history, is typed",
    "foo ^ ~", [3,10], ignoreTags],
@@ -170,8 +182,33 @@ let gTests = [
 
 function makeDefault(aDefault) {
   // We want to ignore tags if we're restricting to history unless we're showing
   if ((aDefault & 1) && !((aDefault & 2) || (aDefault & 4)))
     ignoreTags();
 
   prefs.setIntPref("browser.urlbar.default.behavior", aDefault);
 }
+
+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.";
+
+  print("changing restrict for " + aType + " to '" + aChar + "'");
+  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.";
+
+  prefs.clearUserPref(branch + aType);
+}