toolkit/components/autocomplete/tests/unit/test_440866.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 * Unit test for Bug 440866 - First AutoCompleteSearch that returns
michael@0 7 * RESULT_NOMATCH cancels all other searches when popup is open
michael@0 8 */
michael@0 9
michael@0 10
michael@0 11
michael@0 12 /**
michael@0 13 * Dummy nsIAutoCompleteInput source that returns
michael@0 14 * the given list of AutoCompleteSearch names.
michael@0 15 *
michael@0 16 * Implements only the methods needed for this test.
michael@0 17 */
michael@0 18 function AutoCompleteInput(aSearches) {
michael@0 19 this.searches = aSearches;
michael@0 20 }
michael@0 21 AutoCompleteInput.prototype = {
michael@0 22 constructor: AutoCompleteInput,
michael@0 23
michael@0 24 // Array of AutoCompleteSearch names
michael@0 25 searches: null,
michael@0 26
michael@0 27 minResultsForPopup: 0,
michael@0 28 timeout: 10,
michael@0 29 searchParam: "",
michael@0 30 textValue: "",
michael@0 31 disableAutoComplete: false,
michael@0 32 completeDefaultIndex: false,
michael@0 33
michael@0 34 get searchCount() {
michael@0 35 return this.searches.length;
michael@0 36 },
michael@0 37
michael@0 38 getSearchAt: function(aIndex) {
michael@0 39 return this.searches[aIndex];
michael@0 40 },
michael@0 41
michael@0 42 onSearchBegin: function() {},
michael@0 43 onSearchComplete: function() {},
michael@0 44
michael@0 45 popupOpen: false,
michael@0 46
michael@0 47 popup: {
michael@0 48 setSelectedIndex: function(aIndex) {},
michael@0 49 invalidate: function() {},
michael@0 50
michael@0 51 // nsISupports implementation
michael@0 52 QueryInterface: function(iid) {
michael@0 53 if (iid.equals(Ci.nsISupports) ||
michael@0 54 iid.equals(Ci.nsIAutoCompletePopup))
michael@0 55 return this;
michael@0 56
michael@0 57 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 58 }
michael@0 59 },
michael@0 60
michael@0 61 // nsISupports implementation
michael@0 62 QueryInterface: function(iid) {
michael@0 63 if (iid.equals(Ci.nsISupports) ||
michael@0 64 iid.equals(Ci.nsIAutoCompleteInput))
michael@0 65 return this;
michael@0 66
michael@0 67 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 68 }
michael@0 69 }
michael@0 70
michael@0 71
michael@0 72
michael@0 73 /**
michael@0 74 * nsIAutoCompleteResult implementation
michael@0 75 */
michael@0 76 function AutoCompleteResult(aValues, aComments, aStyles) {
michael@0 77 this._values = aValues;
michael@0 78 this._comments = aComments;
michael@0 79 this._styles = aStyles;
michael@0 80
michael@0 81 if (this._values.length > 0) {
michael@0 82 this.searchResult = Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
michael@0 83 } else {
michael@0 84 this.searchResult = Ci.nsIAutoCompleteResult.NOMATCH;
michael@0 85 }
michael@0 86 }
michael@0 87 AutoCompleteResult.prototype = {
michael@0 88 constructor: AutoCompleteResult,
michael@0 89
michael@0 90 // Arrays
michael@0 91 _values: null,
michael@0 92 _comments: null,
michael@0 93 _styles: null,
michael@0 94
michael@0 95 searchString: "",
michael@0 96 searchResult: null,
michael@0 97
michael@0 98 defaultIndex: 0,
michael@0 99
michael@0 100 get matchCount() {
michael@0 101 return this._values.length;
michael@0 102 },
michael@0 103
michael@0 104 getValueAt: function(aIndex) {
michael@0 105 return this._values[aIndex];
michael@0 106 },
michael@0 107
michael@0 108 getLabelAt: function(aIndex) {
michael@0 109 return this.getValueAt(aIndex);
michael@0 110 },
michael@0 111
michael@0 112 getCommentAt: function(aIndex) {
michael@0 113 return this._comments[aIndex];
michael@0 114 },
michael@0 115
michael@0 116 getStyleAt: function(aIndex) {
michael@0 117 return this._styles[aIndex];
michael@0 118 },
michael@0 119
michael@0 120 getImageAt: function(aIndex) {
michael@0 121 return "";
michael@0 122 },
michael@0 123
michael@0 124 getFinalCompleteValueAt: function(aIndex) {
michael@0 125 return this.getValueAt(aIndex);
michael@0 126 },
michael@0 127
michael@0 128 removeValueAt: function (aRowIndex, aRemoveFromDb) {},
michael@0 129
michael@0 130 // nsISupports implementation
michael@0 131 QueryInterface: function(iid) {
michael@0 132 if (iid.equals(Ci.nsISupports) ||
michael@0 133 iid.equals(Ci.nsIAutoCompleteResult))
michael@0 134 return this;
michael@0 135
michael@0 136 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 137 }
michael@0 138 }
michael@0 139
michael@0 140
michael@0 141
michael@0 142 /**
michael@0 143 * nsIAutoCompleteSearch implementation that always returns
michael@0 144 * the same result set.
michael@0 145 */
michael@0 146 function AutoCompleteSearch(aName, aResult) {
michael@0 147 this.name = aName;
michael@0 148 this._result = aResult;
michael@0 149 }
michael@0 150 AutoCompleteSearch.prototype = {
michael@0 151 constructor: AutoCompleteSearch,
michael@0 152
michael@0 153 // Search name. Used by AutoCompleteController
michael@0 154 name: null,
michael@0 155
michael@0 156 // AutoCompleteResult
michael@0 157 _result:null,
michael@0 158
michael@0 159
michael@0 160 /**
michael@0 161 * Return the same result set for every search
michael@0 162 */
michael@0 163 startSearch: function(aSearchString,
michael@0 164 aSearchParam,
michael@0 165 aPreviousResult,
michael@0 166 aListener)
michael@0 167 {
michael@0 168 aListener.onSearchResult(this, this._result);
michael@0 169 },
michael@0 170
michael@0 171 stopSearch: function() {},
michael@0 172
michael@0 173 // nsISupports implementation
michael@0 174 QueryInterface: function(iid) {
michael@0 175 if (iid.equals(Ci.nsISupports) ||
michael@0 176 iid.equals(Ci.nsIFactory) ||
michael@0 177 iid.equals(Ci.nsIAutoCompleteSearch))
michael@0 178 return this;
michael@0 179
michael@0 180 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 181 },
michael@0 182
michael@0 183 // nsIFactory implementation
michael@0 184 createInstance: function(outer, iid) {
michael@0 185 return this.QueryInterface(iid);
michael@0 186 }
michael@0 187 }
michael@0 188
michael@0 189
michael@0 190
michael@0 191 /**
michael@0 192 * Helper to register an AutoCompleteSearch with the given name.
michael@0 193 * Allows the AutoCompleteController to find the search.
michael@0 194 */
michael@0 195 function registerAutoCompleteSearch(aSearch) {
michael@0 196 var name = "@mozilla.org/autocomplete/search;1?name=" + aSearch.name;
michael@0 197
michael@0 198 var uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].
michael@0 199 getService(Ci.nsIUUIDGenerator);
michael@0 200 var cid = uuidGenerator.generateUUID();
michael@0 201
michael@0 202 var desc = "Test AutoCompleteSearch";
michael@0 203
michael@0 204 var componentManager = Components.manager
michael@0 205 .QueryInterface(Ci.nsIComponentRegistrar);
michael@0 206 componentManager.registerFactory(cid, desc, name, aSearch);
michael@0 207
michael@0 208 // Keep the id on the object so we can unregister later
michael@0 209 aSearch.cid = cid;
michael@0 210 }
michael@0 211
michael@0 212
michael@0 213
michael@0 214 /**
michael@0 215 * Helper to unregister an AutoCompleteSearch.
michael@0 216 */
michael@0 217 function unregisterAutoCompleteSearch(aSearch) {
michael@0 218 var componentManager = Components.manager
michael@0 219 .QueryInterface(Ci.nsIComponentRegistrar);
michael@0 220 componentManager.unregisterFactory(aSearch.cid, aSearch);
michael@0 221 }
michael@0 222
michael@0 223
michael@0 224
michael@0 225 /**
michael@0 226 * Test AutoComplete with multiple AutoCompleteSearch sources.
michael@0 227 */
michael@0 228 function run_test() {
michael@0 229
michael@0 230 // Make an AutoCompleteSearch that always returns nothing
michael@0 231 var emptySearch = new AutoCompleteSearch("test-empty-search",
michael@0 232 new AutoCompleteResult([], [], []));
michael@0 233
michael@0 234 // Make an AutoCompleteSearch that returns two values
michael@0 235 var expectedValues = ["test1", "test2"];
michael@0 236 var regularSearch = new AutoCompleteSearch("test-regular-search",
michael@0 237 new AutoCompleteResult(expectedValues, [], []));
michael@0 238
michael@0 239 // Register searches so AutoCompleteController can find them
michael@0 240 registerAutoCompleteSearch(emptySearch);
michael@0 241 registerAutoCompleteSearch(regularSearch);
michael@0 242
michael@0 243 var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
michael@0 244 getService(Components.interfaces.nsIAutoCompleteController);
michael@0 245
michael@0 246 // Make an AutoCompleteInput that uses our searches
michael@0 247 // and confirms results on search complete
michael@0 248 var input = new AutoCompleteInput([emptySearch.name, regularSearch.name]);
michael@0 249 var numSearchesStarted = 0;
michael@0 250
michael@0 251 input.onSearchBegin = function() {
michael@0 252 numSearchesStarted++;
michael@0 253 do_check_eq(numSearchesStarted, 1);
michael@0 254 do_check_eq(input.searchCount, 2);
michael@0 255 };
michael@0 256
michael@0 257 input.onSearchComplete = function() {
michael@0 258 do_check_eq(numSearchesStarted, 1);
michael@0 259
michael@0 260 do_check_eq(controller.searchStatus,
michael@0 261 Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
michael@0 262 do_check_eq(controller.matchCount, 2);
michael@0 263
michael@0 264 // Confirm expected result values
michael@0 265 for (var i = 0; i < expectedValues.length; i++) {
michael@0 266 do_check_eq(expectedValues[i], controller.getValueAt(i));
michael@0 267 }
michael@0 268
michael@0 269 do_check_true(input.popupOpen);
michael@0 270
michael@0 271 // Unregister searches
michael@0 272 unregisterAutoCompleteSearch(emptySearch);
michael@0 273 unregisterAutoCompleteSearch(regularSearch);
michael@0 274
michael@0 275 do_test_finished();
michael@0 276 };
michael@0 277
michael@0 278 controller.input = input;
michael@0 279
michael@0 280 // Search is asynchronous, so don't let the test finish immediately
michael@0 281 do_test_pending();
michael@0 282
michael@0 283 controller.startSearch("test");
michael@0 284 }
michael@0 285

mercurial