toolkit/components/places/tests/autocomplete/test_special_search.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /**
     6  * Test for bug 395161 that allows special searches that restrict results to
     7  * history/bookmark/tagged items and title/url matches.
     8  *
     9  * Test 485122 by making sure results don't have tags when restricting result
    10  * to just history either by default behavior or dynamic query restrict.
    11  */
    13 // Define some shared uris and titles (each page needs its own uri)
    14 let kURIs = [
    15   "http://url/",
    16   "http://url/2",
    17   "http://foo.bar/",
    18   "http://foo.bar/2",
    19   "http://url/star",
    20   "http://url/star/2",
    21   "http://foo.bar/star",
    22   "http://foo.bar/star/2",
    23   "http://url/tag",
    24   "http://url/tag/2",
    25   "http://foo.bar/tag",
    26   "http://foo.bar/tag/2",
    27 ];
    28 let kTitles = [
    29   "title",
    30   "foo.bar",
    31 ];
    33 // Plain page visits
    34 addPageBook(0, 0); // plain page
    35 addPageBook(1, 1); // title
    36 addPageBook(2, 0); // url
    37 addPageBook(3, 1); // title and url
    39 // Bookmarked pages (no tag)
    40 addPageBook(4, 0, 0); // bookmarked page
    41 addPageBook(5, 1, 1); // title
    42 addPageBook(6, 0, 0); // url
    43 addPageBook(7, 1, 1); // title and url
    45 // Tagged pages
    46 addPageBook(8, 0, 0, [1]); // tagged page
    47 addPageBook(9, 1, 1, [1]); // title
    48 addPageBook(10, 0, 0, [1]); // url
    49 addPageBook(11, 1, 1, [1]); // title and url
    51 // Remove pages from history to treat them as unvisited, so pages that do have
    52 // visits are 0,1,2,3,5,10
    53 removePages([4,6,7,8,9,11]);
    54 // Set some pages as typed
    55 markTyped([0,10], 0);
    56 markTyped([3], 1);
    58 // Provide for each test: description; search terms; array of gPages indices of
    59 // pages that should match; optional function to be run before the test
    60 let gTests = [
    61   // Test restricting searches
    62   ["0: History restrict",
    63    "^", [0,1,2,3,5,10], ignoreTags],
    64   ["1: Star restrict",
    65    "*", [4,5,6,7,8,9,10,11]],
    66   ["2: Tag restrict",
    67    "+", [8,9,10,11]],
    69   // Test specials as any word position
    70   ["3: Special as first word",
    71    "^ foo bar", [1,2,3,5,10], ignoreTags],
    72   ["4: Special as middle word",
    73    "foo ^ bar", [1,2,3,5,10], ignoreTags],
    74   ["5: Special as last word",
    75    "foo bar ^", [1,2,3,5,10], ignoreTags],
    77   // Test restricting and matching searches with a term
    78   ["6.1: foo ^ -> history",
    79    "foo ^", [1,2,3,5,10], ignoreTags],
    80   ["6.2: foo | -> history (change pref)",
    81    "foo |", [1,2,3,5,10], function() {ignoreTags(); changeRestrict("history", "|"); }],
    82   ["7.1: foo * -> is star",
    83    "foo *", [5,6,7,8,9,10,11], function() resetRestrict("history")],
    84   ["7.2: foo | -> is star (change pref)",
    85    "foo |", [5,6,7,8,9,10,11], function() changeRestrict("bookmark", "|")],
    86   ["8.1: foo # -> in title",
    87    "foo #", [1,3,5,7,8,9,10,11], function() resetRestrict("bookmark")],
    88   ["8.2: foo | -> in title (change pref)",
    89    "foo |", [1,3,5,7,8,9,10,11], function() changeRestrict("title", "|")],
    90   ["9.1: foo @ -> in url",
    91    "foo @", [2,3,6,7,10,11], function() resetRestrict("title")],
    92   ["9.2: foo | -> in url (change pref)",
    93    "foo |", [2,3,6,7,10,11], function() changeRestrict("url", "|")],
    94   ["10: foo + -> is tag",
    95    "foo +", [8,9,10,11], function() resetRestrict("url")],
    96   ["10.2: foo | -> is tag (change pref)",
    97    "foo |", [8,9,10,11], function() changeRestrict("tag", "|")],
    98   ["10.3: foo ~ -> is typed",
    99    "foo ~", [3,10], function() resetRestrict("tag")],
   100   ["10.4: foo | -> is typed (change pref)",
   101    "foo |", [3,10], function() changeRestrict("typed", "|")],
   103   // Test various pairs of special searches
   104   ["11: foo ^ * -> history, is star",
   105    "foo ^ *", [5,10], function() resetRestrict("typed")],
   106   ["12: foo ^ # -> history, in title",
   107    "foo ^ #", [1,3,5,10], ignoreTags],
   108   ["13: foo ^ @ -> history, in url",
   109    "foo ^ @", [2,3,10], ignoreTags],
   110   ["14: foo ^ + -> history, is tag",
   111    "foo ^ +", [10]],
   112   ["14.1: foo ^ ~ -> history, is typed",
   113    "foo ^ ~", [3,10], ignoreTags],
   114   ["15: foo * # -> is star, in title",
   115    "foo * #", [5,7,8,9,10,11]],
   116   ["16: foo * @ -> is star, in url",
   117    "foo * @", [6,7,10,11]],
   118   ["17: foo * + -> same as +",
   119    "foo * +", [8,9,10,11]],
   120   ["17.1: foo * ~ -> is star, is typed",
   121    "foo * ~", [10]],
   122   ["18: foo # @ -> in title, in url",
   123    "foo # @", [3,7,10,11]],
   124   ["19: foo # + -> in title, is tag",
   125    "foo # +", [8,9,10,11]],
   126   ["19.1: foo # ~ -> in title, is typed",
   127    "foo # ~", [3,10]],
   128   ["20: foo @ + -> in url, is tag",
   129    "foo @ +", [10,11]],
   130   ["20.1: foo @ ~ -> in url, is typed",
   131    "foo @ ~", [3,10]],
   132   ["20.2: foo + ~ -> is tag, is typed",
   133    "foo + ~", [10]],
   135   // Test default usage by setting certain bits of default.behavior to 1
   136   ["21: foo -> default history",
   137    "foo", [1,2,3,5,10], function() makeDefault(1)],
   138   ["22: foo -> default history, is star",
   139    "foo", [5,10], function() makeDefault(3)],
   140   ["22.1: foo -> default history, is star, is typed",
   141    "foo", [10], function() makeDefault(35)],
   142   ["23: foo -> default history, is star, in url",
   143    "foo", [10], function() makeDefault(19)],
   145   // Change the default to be less restrictive to make sure we find more
   146   ["24: foo -> default is star, in url",
   147    "foo", [6,7,10,11], function() makeDefault(18)],
   148   ["25: foo -> default in url",
   149    "foo", [2,3,6,7,10,11], function() makeDefault(16)],
   150 ];
   152 function makeDefault(aDefault) {
   153   // We want to ignore tags if we're restricting to history unless we're showing
   154   if ((aDefault & 1) && !((aDefault & 2) || (aDefault & 4)))
   155     ignoreTags();
   157   prefs.setIntPref("browser.urlbar.default.behavior", aDefault);
   158 }
   160 function changeRestrict(aType, aChar)
   161 {
   162   let branch = "browser.urlbar.";
   163   // "title" and "url" are different from everything else, so special case them.
   164   if (aType == "title" || aType == "url")
   165     branch += "match.";
   166   else
   167     branch += "restrict.";
   169   print("changing restrict for " + aType + " to '" + aChar + "'");
   170   prefs.setCharPref(branch + aType, aChar);
   171 }
   173 function resetRestrict(aType)
   174 {
   175   let branch = "browser.urlbar.";
   176   // "title" and "url" are different from everything else, so special case them.
   177   if (aType == "title" || aType == "url")
   178     branch += "match.";
   179   else
   180     branch += "restrict.";
   182   if (prefs.prefHasUserValue(branch + aType))
   183     prefs.clearUserPref(branch + aType);
   184 }

mercurial