Sat, 03 Jan 2015 20:18:00 +0100
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 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * Test for bug 395739 to make sure the feedback to the search results in those |
michael@0 | 9 | * entries getting better ranks. Additionally, exact matches should be ranked |
michael@0 | 10 | * higher. Because the interactions among adaptive rank and visit counts is not |
michael@0 | 11 | * well defined, this test holds one of the two values constant when modifying |
michael@0 | 12 | * the other. |
michael@0 | 13 | * |
michael@0 | 14 | * This also tests bug 395735 for the instrumentation feedback mechanism. |
michael@0 | 15 | * |
michael@0 | 16 | * Bug 411293 is tested to make sure the drop down strongly prefers previously |
michael@0 | 17 | * typed pages that have been selected and are moved to the top with adaptive |
michael@0 | 18 | * learning. |
michael@0 | 19 | */ |
michael@0 | 20 | |
michael@0 | 21 | function AutoCompleteInput(aSearches) { |
michael@0 | 22 | this.searches = aSearches; |
michael@0 | 23 | } |
michael@0 | 24 | AutoCompleteInput.prototype = { |
michael@0 | 25 | constructor: AutoCompleteInput, |
michael@0 | 26 | |
michael@0 | 27 | get minResultsForPopup() 0, |
michael@0 | 28 | get timeout() 10, |
michael@0 | 29 | get searchParam() "", |
michael@0 | 30 | get textValue() "", |
michael@0 | 31 | get disableAutoComplete() false, |
michael@0 | 32 | get completeDefaultIndex() false, |
michael@0 | 33 | |
michael@0 | 34 | get searchCount() this.searches.length, |
michael@0 | 35 | getSearchAt: function (aIndex) this.searches[aIndex], |
michael@0 | 36 | |
michael@0 | 37 | onSearchBegin: function () {}, |
michael@0 | 38 | onSearchComplete: function() {}, |
michael@0 | 39 | |
michael@0 | 40 | get popupOpen() false, |
michael@0 | 41 | popup: { |
michael@0 | 42 | set selectedIndex(aIndex) aIndex, |
michael@0 | 43 | invalidate: function () {}, |
michael@0 | 44 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]) |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput]) |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Checks that autocomplete results are ordered correctly. |
michael@0 | 52 | */ |
michael@0 | 53 | function ensure_results(expected, searchTerm) |
michael@0 | 54 | { |
michael@0 | 55 | let controller = Cc["@mozilla.org/autocomplete/controller;1"]. |
michael@0 | 56 | getService(Ci.nsIAutoCompleteController); |
michael@0 | 57 | |
michael@0 | 58 | // Make an AutoCompleteInput that uses our searches |
michael@0 | 59 | // and confirms results on search complete. |
michael@0 | 60 | let input = new AutoCompleteInput(["history"]); |
michael@0 | 61 | |
michael@0 | 62 | controller.input = input; |
michael@0 | 63 | |
michael@0 | 64 | input.onSearchComplete = function() { |
michael@0 | 65 | do_check_eq(controller.searchStatus, |
michael@0 | 66 | Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH); |
michael@0 | 67 | do_check_eq(controller.matchCount, expected.length); |
michael@0 | 68 | for (let i = 0; i < controller.matchCount; i++) { |
michael@0 | 69 | print("Testing for '" + expected[i].uri.spec + "' got '" + controller.getValueAt(i) + "'"); |
michael@0 | 70 | do_check_eq(controller.getValueAt(i), expected[i].uri.spec); |
michael@0 | 71 | do_check_eq(controller.getStyleAt(i), expected[i].style); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | deferEnsureResults.resolve(); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | controller.startSearch(searchTerm); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Asynchronous task that bumps up the rank for an uri. |
michael@0 | 82 | */ |
michael@0 | 83 | function task_setCountRank(aURI, aCount, aRank, aSearch, aBookmark) |
michael@0 | 84 | { |
michael@0 | 85 | // Bump up the visit count for the uri. |
michael@0 | 86 | let visits = []; |
michael@0 | 87 | for (let i = 0; i < aCount; i++) { |
michael@0 | 88 | visits.push({ uri: aURI, visitDate: d1, transition: TRANSITION_TYPED }); |
michael@0 | 89 | } |
michael@0 | 90 | yield promiseAddVisits(visits); |
michael@0 | 91 | |
michael@0 | 92 | // Make a nsIAutoCompleteController and friends for instrumentation feedback. |
michael@0 | 93 | let thing = { |
michael@0 | 94 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, |
michael@0 | 95 | Ci.nsIAutoCompletePopup, |
michael@0 | 96 | Ci.nsIAutoCompleteController]), |
michael@0 | 97 | get popup() thing, |
michael@0 | 98 | get controller() thing, |
michael@0 | 99 | popupOpen: true, |
michael@0 | 100 | selectedIndex: 0, |
michael@0 | 101 | getValueAt: function() aURI.spec, |
michael@0 | 102 | searchString: aSearch |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | // Bump up the instrumentation feedback. |
michael@0 | 106 | for (let i = 0; i < aRank; i++) { |
michael@0 | 107 | Services.obs.notifyObservers(thing, "autocomplete-will-enter-text", null); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | // If this is supposed to be a bookmark, add it. |
michael@0 | 111 | if (aBookmark) { |
michael@0 | 112 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 113 | aURI, |
michael@0 | 114 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 115 | "test_book"); |
michael@0 | 116 | |
michael@0 | 117 | // And add the tag if we need to. |
michael@0 | 118 | if (aBookmark == "tag") { |
michael@0 | 119 | PlacesUtils.tagging.tagURI(aURI, ["test_tag"]); |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | /** |
michael@0 | 125 | * Decay the adaptive entries by sending the daily idle topic. |
michael@0 | 126 | */ |
michael@0 | 127 | function doAdaptiveDecay() |
michael@0 | 128 | { |
michael@0 | 129 | PlacesUtils.history.runInBatchMode({ |
michael@0 | 130 | runBatched: function() { |
michael@0 | 131 | for (let i = 0; i < 10; i++) { |
michael@0 | 132 | PlacesUtils.history.QueryInterface(Ci.nsIObserver) |
michael@0 | 133 | .observe(null, "idle-daily", null); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | }, this); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | let uri1 = uri("http://site.tld/1"); |
michael@0 | 140 | let uri2 = uri("http://site.tld/2"); |
michael@0 | 141 | |
michael@0 | 142 | // d1 is some date for the page visit |
michael@0 | 143 | let d1 = new Date(Date.now() - 1000 * 60 * 60) * 1000; |
michael@0 | 144 | // c1 is larger (should show up higher) than c2 |
michael@0 | 145 | let c1 = 10; |
michael@0 | 146 | let c2 = 1; |
michael@0 | 147 | // s1 is a partial match of s2 |
michael@0 | 148 | let s0 = ""; |
michael@0 | 149 | let s1 = "si"; |
michael@0 | 150 | let s2 = "site"; |
michael@0 | 151 | |
michael@0 | 152 | let observer = { |
michael@0 | 153 | results: null, |
michael@0 | 154 | search: null, |
michael@0 | 155 | runCount: -1, |
michael@0 | 156 | observe: function(aSubject, aTopic, aData) |
michael@0 | 157 | { |
michael@0 | 158 | if (--this.runCount > 0) |
michael@0 | 159 | return; |
michael@0 | 160 | ensure_results(this.results, this.search); |
michael@0 | 161 | } |
michael@0 | 162 | }; |
michael@0 | 163 | Services.obs.addObserver(observer, PlacesUtils.TOPIC_FEEDBACK_UPDATED, false); |
michael@0 | 164 | |
michael@0 | 165 | /** |
michael@0 | 166 | * Make the result object for a given URI that will be passed to ensure_results. |
michael@0 | 167 | */ |
michael@0 | 168 | function makeResult(aURI) { |
michael@0 | 169 | return { |
michael@0 | 170 | uri: aURI, |
michael@0 | 171 | style: "favicon", |
michael@0 | 172 | }; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | let tests = [ |
michael@0 | 176 | // Test things without a search term. |
michael@0 | 177 | function() { |
michael@0 | 178 | print("Test 0 same count, diff rank, same term; no search"); |
michael@0 | 179 | observer.results = [ |
michael@0 | 180 | makeResult(uri1), |
michael@0 | 181 | makeResult(uri2), |
michael@0 | 182 | ]; |
michael@0 | 183 | observer.search = s0; |
michael@0 | 184 | observer.runCount = c1 + c2; |
michael@0 | 185 | yield task_setCountRank(uri1, c1, c1, s2); |
michael@0 | 186 | yield task_setCountRank(uri2, c1, c2, s2); |
michael@0 | 187 | }, |
michael@0 | 188 | function() { |
michael@0 | 189 | print("Test 1 same count, diff rank, same term; no search"); |
michael@0 | 190 | observer.results = [ |
michael@0 | 191 | makeResult(uri2), |
michael@0 | 192 | makeResult(uri1), |
michael@0 | 193 | ]; |
michael@0 | 194 | observer.search = s0; |
michael@0 | 195 | observer.runCount = c1 + c2; |
michael@0 | 196 | yield task_setCountRank(uri1, c1, c2, s2); |
michael@0 | 197 | yield task_setCountRank(uri2, c1, c1, s2); |
michael@0 | 198 | }, |
michael@0 | 199 | function() { |
michael@0 | 200 | print("Test 2 diff count, same rank, same term; no search"); |
michael@0 | 201 | observer.results = [ |
michael@0 | 202 | makeResult(uri1), |
michael@0 | 203 | makeResult(uri2), |
michael@0 | 204 | ]; |
michael@0 | 205 | observer.search = s0; |
michael@0 | 206 | observer.runCount = c1 + c1; |
michael@0 | 207 | yield task_setCountRank(uri1, c1, c1, s2); |
michael@0 | 208 | yield task_setCountRank(uri2, c2, c1, s2); |
michael@0 | 209 | }, |
michael@0 | 210 | function() { |
michael@0 | 211 | print("Test 3 diff count, same rank, same term; no search"); |
michael@0 | 212 | observer.results = [ |
michael@0 | 213 | makeResult(uri2), |
michael@0 | 214 | makeResult(uri1), |
michael@0 | 215 | ]; |
michael@0 | 216 | observer.search = s0; |
michael@0 | 217 | observer.runCount = c1 + c1; |
michael@0 | 218 | yield task_setCountRank(uri1, c2, c1, s2); |
michael@0 | 219 | yield task_setCountRank(uri2, c1, c1, s2); |
michael@0 | 220 | }, |
michael@0 | 221 | |
michael@0 | 222 | // Test things with a search term (exact match one, partial other). |
michael@0 | 223 | function() { |
michael@0 | 224 | print("Test 4 same count, same rank, diff term; one exact/one partial search"); |
michael@0 | 225 | observer.results = [ |
michael@0 | 226 | makeResult(uri1), |
michael@0 | 227 | makeResult(uri2), |
michael@0 | 228 | ]; |
michael@0 | 229 | observer.search = s1; |
michael@0 | 230 | observer.runCount = c1 + c1; |
michael@0 | 231 | yield task_setCountRank(uri1, c1, c1, s1); |
michael@0 | 232 | yield task_setCountRank(uri2, c1, c1, s2); |
michael@0 | 233 | }, |
michael@0 | 234 | function() { |
michael@0 | 235 | print("Test 5 same count, same rank, diff term; one exact/one partial search"); |
michael@0 | 236 | observer.results = [ |
michael@0 | 237 | makeResult(uri2), |
michael@0 | 238 | makeResult(uri1), |
michael@0 | 239 | ]; |
michael@0 | 240 | observer.search = s1; |
michael@0 | 241 | observer.runCount = c1 + c1; |
michael@0 | 242 | yield task_setCountRank(uri1, c1, c1, s2); |
michael@0 | 243 | yield task_setCountRank(uri2, c1, c1, s1); |
michael@0 | 244 | }, |
michael@0 | 245 | |
michael@0 | 246 | // Test things with a search term (exact match both). |
michael@0 | 247 | function() { |
michael@0 | 248 | print("Test 6 same count, diff rank, same term; both exact search"); |
michael@0 | 249 | observer.results = [ |
michael@0 | 250 | makeResult(uri1), |
michael@0 | 251 | makeResult(uri2), |
michael@0 | 252 | ]; |
michael@0 | 253 | observer.search = s1; |
michael@0 | 254 | observer.runCount = c1 + c2; |
michael@0 | 255 | yield task_setCountRank(uri1, c1, c1, s1); |
michael@0 | 256 | yield task_setCountRank(uri2, c1, c2, s1); |
michael@0 | 257 | }, |
michael@0 | 258 | function() { |
michael@0 | 259 | print("Test 7 same count, diff rank, same term; both exact search"); |
michael@0 | 260 | observer.results = [ |
michael@0 | 261 | makeResult(uri2), |
michael@0 | 262 | makeResult(uri1), |
michael@0 | 263 | ]; |
michael@0 | 264 | observer.search = s1; |
michael@0 | 265 | observer.runCount = c1 + c2; |
michael@0 | 266 | yield task_setCountRank(uri1, c1, c2, s1); |
michael@0 | 267 | yield task_setCountRank(uri2, c1, c1, s1); |
michael@0 | 268 | }, |
michael@0 | 269 | |
michael@0 | 270 | // Test things with a search term (partial match both). |
michael@0 | 271 | function() { |
michael@0 | 272 | print("Test 8 same count, diff rank, same term; both partial search"); |
michael@0 | 273 | observer.results = [ |
michael@0 | 274 | makeResult(uri1), |
michael@0 | 275 | makeResult(uri2), |
michael@0 | 276 | ]; |
michael@0 | 277 | observer.search = s1; |
michael@0 | 278 | observer.runCount = c1 + c2; |
michael@0 | 279 | yield task_setCountRank(uri1, c1, c1, s2); |
michael@0 | 280 | yield task_setCountRank(uri2, c1, c2, s2); |
michael@0 | 281 | }, |
michael@0 | 282 | function() { |
michael@0 | 283 | print("Test 9 same count, diff rank, same term; both partial search"); |
michael@0 | 284 | observer.results = [ |
michael@0 | 285 | makeResult(uri2), |
michael@0 | 286 | makeResult(uri1), |
michael@0 | 287 | ]; |
michael@0 | 288 | observer.search = s1; |
michael@0 | 289 | observer.runCount = c1 + c2; |
michael@0 | 290 | yield task_setCountRank(uri1, c1, c2, s2); |
michael@0 | 291 | yield task_setCountRank(uri2, c1, c1, s2); |
michael@0 | 292 | }, |
michael@0 | 293 | function() { |
michael@0 | 294 | print("Test 10 same count, same rank, same term, decay first; exact match"); |
michael@0 | 295 | observer.results = [ |
michael@0 | 296 | makeResult(uri2), |
michael@0 | 297 | makeResult(uri1), |
michael@0 | 298 | ]; |
michael@0 | 299 | observer.search = s1; |
michael@0 | 300 | observer.runCount = c1 + c1; |
michael@0 | 301 | yield task_setCountRank(uri1, c1, c1, s1); |
michael@0 | 302 | doAdaptiveDecay(); |
michael@0 | 303 | yield task_setCountRank(uri2, c1, c1, s1); |
michael@0 | 304 | }, |
michael@0 | 305 | function() { |
michael@0 | 306 | print("Test 11 same count, same rank, same term, decay second; exact match"); |
michael@0 | 307 | observer.results = [ |
michael@0 | 308 | makeResult(uri1), |
michael@0 | 309 | makeResult(uri2), |
michael@0 | 310 | ]; |
michael@0 | 311 | observer.search = s1; |
michael@0 | 312 | observer.runCount = c1 + c1; |
michael@0 | 313 | yield task_setCountRank(uri2, c1, c1, s1); |
michael@0 | 314 | doAdaptiveDecay(); |
michael@0 | 315 | yield task_setCountRank(uri1, c1, c1, s1); |
michael@0 | 316 | }, |
michael@0 | 317 | // Test that bookmarks or tags are hidden if the preferences are set right. |
michael@0 | 318 | function() { |
michael@0 | 319 | print("Test 12 same count, diff rank, same term; no search; history only"); |
michael@0 | 320 | Services.prefs.setIntPref("browser.urlbar.matchBehavior", |
michael@0 | 321 | Ci.mozIPlacesAutoComplete.BEHAVIOR_HISTORY); |
michael@0 | 322 | observer.results = [ |
michael@0 | 323 | makeResult(uri1), |
michael@0 | 324 | makeResult(uri2), |
michael@0 | 325 | ]; |
michael@0 | 326 | observer.search = s0; |
michael@0 | 327 | observer.runCount = c1 + c2; |
michael@0 | 328 | yield task_setCountRank(uri1, c1, c1, s2, "bookmark"); |
michael@0 | 329 | yield task_setCountRank(uri2, c1, c2, s2); |
michael@0 | 330 | }, |
michael@0 | 331 | function() { |
michael@0 | 332 | print("Test 13 same count, diff rank, same term; no search; history only with tag"); |
michael@0 | 333 | Services.prefs.setIntPref("browser.urlbar.matchBehavior", |
michael@0 | 334 | Ci.mozIPlacesAutoComplete.BEHAVIOR_HISTORY); |
michael@0 | 335 | observer.results = [ |
michael@0 | 336 | makeResult(uri1), |
michael@0 | 337 | makeResult(uri2), |
michael@0 | 338 | ]; |
michael@0 | 339 | observer.search = s0; |
michael@0 | 340 | observer.runCount = c1 + c2; |
michael@0 | 341 | yield task_setCountRank(uri1, c1, c1, s2, "tag"); |
michael@0 | 342 | yield task_setCountRank(uri2, c1, c2, s2); |
michael@0 | 343 | }, |
michael@0 | 344 | ]; |
michael@0 | 345 | |
michael@0 | 346 | /** |
michael@0 | 347 | * This deferred object contains a promise that is resolved when the |
michael@0 | 348 | * ensure_results function has finished its execution. |
michael@0 | 349 | */ |
michael@0 | 350 | let deferEnsureResults; |
michael@0 | 351 | |
michael@0 | 352 | /** |
michael@0 | 353 | * Test adaptive autocomplete. |
michael@0 | 354 | */ |
michael@0 | 355 | function run_test() |
michael@0 | 356 | { |
michael@0 | 357 | run_next_test(); |
michael@0 | 358 | } |
michael@0 | 359 | |
michael@0 | 360 | add_task(function test_adaptive() |
michael@0 | 361 | { |
michael@0 | 362 | for (let [, test] in Iterator(tests)) { |
michael@0 | 363 | // Cleanup. |
michael@0 | 364 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 365 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.tagsFolderId); |
michael@0 | 366 | observer.runCount = -1; |
michael@0 | 367 | |
michael@0 | 368 | yield promiseClearHistory(); |
michael@0 | 369 | |
michael@0 | 370 | deferEnsureResults = Promise.defer(); |
michael@0 | 371 | yield test(); |
michael@0 | 372 | yield deferEnsureResults.promise; |
michael@0 | 373 | } |
michael@0 | 374 | |
michael@0 | 375 | Services.obs.removeObserver(observer, PlacesUtils.TOPIC_FEEDBACK_UPDATED); |
michael@0 | 376 | }); |