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.

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

mercurial