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 | /* 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 file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cc = Components.classes; |
michael@0 | 7 | const Cr = Components.results; |
michael@0 | 8 | const Cu = Components.utils; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | |
michael@0 | 12 | // Import common head. |
michael@0 | 13 | let (commonFile = do_get_file("../head_common.js", false)) { |
michael@0 | 14 | let uri = Services.io.newFileURI(commonFile); |
michael@0 | 15 | Services.scriptloader.loadSubScript(uri.spec, this); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | // Put any other stuff relative to this test folder below. |
michael@0 | 19 | |
michael@0 | 20 | XPCOMUtils.defineLazyServiceGetter(this, "gHistory", |
michael@0 | 21 | "@mozilla.org/browser/history;1", |
michael@0 | 22 | "mozIAsyncHistory"); |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * @param aSearches |
michael@0 | 26 | * Array of AutoCompleteSearch names. |
michael@0 | 27 | */ |
michael@0 | 28 | function AutoCompleteInput(aSearches) { |
michael@0 | 29 | this.searches = aSearches; |
michael@0 | 30 | } |
michael@0 | 31 | AutoCompleteInput.prototype = { |
michael@0 | 32 | searches: null, |
michael@0 | 33 | minResultsForPopup: 0, |
michael@0 | 34 | timeout: 10, |
michael@0 | 35 | searchParam: "", |
michael@0 | 36 | textValue: "", |
michael@0 | 37 | disableAutoComplete: false, |
michael@0 | 38 | |
michael@0 | 39 | completeDefaultIndex: true, |
michael@0 | 40 | defaultIndex: 0, |
michael@0 | 41 | |
michael@0 | 42 | // Text selection range |
michael@0 | 43 | _selStart: 0, |
michael@0 | 44 | _selEnd: 0, |
michael@0 | 45 | get selectionStart() { |
michael@0 | 46 | return this._selStart; |
michael@0 | 47 | }, |
michael@0 | 48 | get selectionEnd() { |
michael@0 | 49 | return this._selEnd; |
michael@0 | 50 | }, |
michael@0 | 51 | selectTextRange: function(aStart, aEnd) { |
michael@0 | 52 | this._selStart = aStart; |
michael@0 | 53 | this._selEnd = aEnd; |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | onTextEntered: function() false, |
michael@0 | 57 | onTextReverted: function() false, |
michael@0 | 58 | |
michael@0 | 59 | get searchCount() { |
michael@0 | 60 | return this.searches.length; |
michael@0 | 61 | }, |
michael@0 | 62 | getSearchAt: function(aIndex) { |
michael@0 | 63 | return this.searches[aIndex]; |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | onSearchBegin: function () {}, |
michael@0 | 67 | onSearchComplete: function () {}, |
michael@0 | 68 | |
michael@0 | 69 | popupOpen: false, |
michael@0 | 70 | |
michael@0 | 71 | popup: { |
michael@0 | 72 | selectedIndex: -1, |
michael@0 | 73 | invalidate: function () {}, |
michael@0 | 74 | |
michael@0 | 75 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]) |
michael@0 | 76 | }, |
michael@0 | 77 | |
michael@0 | 78 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput]) |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * @param aSearchString |
michael@0 | 83 | * String to search. |
michael@0 | 84 | * @param aExpectedValue |
michael@0 | 85 | * Expected value returned by autoFill. |
michael@0 | 86 | * May be a string, or an object like |
michael@0 | 87 | * { |
michael@0 | 88 | * autoFilled: the value suggested by autofill, |
michael@0 | 89 | * completed: the value completed on user's confirmation |
michael@0 | 90 | * } |
michael@0 | 91 | * In the latter case this will also check that on user's confirmation |
michael@0 | 92 | * the result's casing is correctly applied. |
michael@0 | 93 | */ |
michael@0 | 94 | function ensure_results(aSearchString, aExpectedValue) { |
michael@0 | 95 | let autoFilledValue, completedValue; |
michael@0 | 96 | if (typeof(aExpectedValue) == "string") { |
michael@0 | 97 | autoFilledValue = aExpectedValue; |
michael@0 | 98 | } |
michael@0 | 99 | else { |
michael@0 | 100 | autoFilledValue = aExpectedValue.autoFilled; |
michael@0 | 101 | completedValue = aExpectedValue.completed; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | // Make an AutoCompleteInput that uses our searches and confirms results. |
michael@0 | 105 | let input = new AutoCompleteInput(["urlinline"]); |
michael@0 | 106 | input.textValue = aSearchString; |
michael@0 | 107 | |
michael@0 | 108 | // Caret must be at the end for autoFill to happen. |
michael@0 | 109 | let strLen = aSearchString.length; |
michael@0 | 110 | input.selectTextRange(strLen, strLen); |
michael@0 | 111 | do_check_eq(input.selectionStart, strLen); |
michael@0 | 112 | do_check_eq(input.selectionEnd, strLen); |
michael@0 | 113 | |
michael@0 | 114 | let controller = Cc["@mozilla.org/autocomplete/controller;1"]. |
michael@0 | 115 | getService(Ci.nsIAutoCompleteController); |
michael@0 | 116 | controller.input = input; |
michael@0 | 117 | |
michael@0 | 118 | let numSearchesStarted = 0; |
michael@0 | 119 | input.onSearchBegin = function() { |
michael@0 | 120 | numSearchesStarted++; |
michael@0 | 121 | do_check_eq(numSearchesStarted, 1); |
michael@0 | 122 | }; |
michael@0 | 123 | |
michael@0 | 124 | input.onSearchComplete = function() { |
michael@0 | 125 | // We should be running only one query. |
michael@0 | 126 | do_check_eq(numSearchesStarted, 1); |
michael@0 | 127 | |
michael@0 | 128 | // Check the autoFilled result. |
michael@0 | 129 | do_check_eq(input.textValue, autoFilledValue); |
michael@0 | 130 | |
michael@0 | 131 | if (completedValue) { |
michael@0 | 132 | // Now force completion and check correct casing of the result. |
michael@0 | 133 | // This ensures the controller is able to do its magic case-preserving |
michael@0 | 134 | // stuff and correct replacement of the user's casing with result's one. |
michael@0 | 135 | controller.handleEnter(false); |
michael@0 | 136 | do_check_eq(input.textValue, completedValue); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | waitForCleanup(run_next_test); |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | do_log_info("Searching for: '" + aSearchString + "'"); |
michael@0 | 143 | controller.startSearch(aSearchString); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | function run_test() { |
michael@0 | 147 | do_register_cleanup(function () { |
michael@0 | 148 | Services.prefs.clearUserPref("browser.urlbar.autocomplete.enabled"); |
michael@0 | 149 | Services.prefs.clearUserPref("browser.urlbar.autoFill"); |
michael@0 | 150 | Services.prefs.clearUserPref("browser.urlbar.autoFill.typed"); |
michael@0 | 151 | }); |
michael@0 | 152 | |
michael@0 | 153 | gAutoCompleteTests.forEach(function (testData) { |
michael@0 | 154 | let [description, searchString, expectedValue, setupFunc] = testData; |
michael@0 | 155 | add_test(function () { |
michael@0 | 156 | do_log_info(description); |
michael@0 | 157 | Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", true); |
michael@0 | 158 | Services.prefs.setBoolPref("browser.urlbar.autoFill", true); |
michael@0 | 159 | Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false); |
michael@0 | 160 | |
michael@0 | 161 | if (setupFunc) { |
michael@0 | 162 | setupFunc(); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | // At this point frecency could still be updating due to latest pages |
michael@0 | 166 | // updates. |
michael@0 | 167 | // This is not a problem in real life, but autocomplete tests should |
michael@0 | 168 | // return reliable resultsets, thus we have to wait. |
michael@0 | 169 | promiseAsyncUpdates().then(function () ensure_results(searchString, |
michael@0 | 170 | expectedValue)); |
michael@0 | 171 | }) |
michael@0 | 172 | }, this); |
michael@0 | 173 | |
michael@0 | 174 | run_next_test(); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | let gAutoCompleteTests = []; |
michael@0 | 178 | function add_autocomplete_test(aTestData) { |
michael@0 | 179 | gAutoCompleteTests.push(aTestData); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function waitForCleanup(aCallback) { |
michael@0 | 183 | remove_all_bookmarks(); |
michael@0 | 184 | promiseClearHistory().then(aCallback); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | function addBookmark(aBookmarkObj) { |
michael@0 | 188 | do_check_true(!!aBookmarkObj.url); |
michael@0 | 189 | let parentId = aBookmarkObj.parentId ? aBookmarkObj.parentId |
michael@0 | 190 | : PlacesUtils.unfiledBookmarksFolderId; |
michael@0 | 191 | let itemId = PlacesUtils.bookmarks |
michael@0 | 192 | .insertBookmark(parentId, |
michael@0 | 193 | NetUtil.newURI(aBookmarkObj.url), |
michael@0 | 194 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 195 | "A bookmark"); |
michael@0 | 196 | if (aBookmarkObj.keyword) { |
michael@0 | 197 | PlacesUtils.bookmarks.setKeywordForBookmark(itemId, aBookmarkObj.keyword); |
michael@0 | 198 | } |
michael@0 | 199 | } |