toolkit/components/autocomplete/tests/unit/test_660156.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Search object that returns results at different times.
michael@0 6 * First, the search that returns results asynchronously.
michael@0 7 */
michael@0 8 function AutoCompleteAsyncSearch(aName, aResult) {
michael@0 9 this.name = aName;
michael@0 10 this._result = aResult;
michael@0 11 }
michael@0 12 AutoCompleteAsyncSearch.prototype = Object.create(AutoCompleteSearchBase.prototype);
michael@0 13 AutoCompleteAsyncSearch.prototype.startSearch = function(aSearchString,
michael@0 14 aSearchParam,
michael@0 15 aPreviousResult,
michael@0 16 aListener) {
michael@0 17 setTimeout(this._returnResults.bind(this), 500, aListener);
michael@0 18 };
michael@0 19
michael@0 20 AutoCompleteAsyncSearch.prototype._returnResults = function(aListener) {
michael@0 21 var result = this._result;
michael@0 22
michael@0 23 result.searchResult = Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
michael@0 24 aListener.onSearchResult(this, result);
michael@0 25 };
michael@0 26
michael@0 27 /**
michael@0 28 * The synchronous version
michael@0 29 */
michael@0 30 function AutoCompleteSyncSearch(aName, aResult) {
michael@0 31 this.name = aName;
michael@0 32 this._result = aResult;
michael@0 33 }
michael@0 34 AutoCompleteSyncSearch.prototype = Object.create(AutoCompleteAsyncSearch.prototype);
michael@0 35 AutoCompleteSyncSearch.prototype.startSearch = function(aSearchString,
michael@0 36 aSearchParam,
michael@0 37 aPreviousResult,
michael@0 38 aListener) {
michael@0 39 this._returnResults(aListener);
michael@0 40 };
michael@0 41
michael@0 42 /**
michael@0 43 * Results object
michael@0 44 */
michael@0 45 function AutoCompleteResult(aValues, aDefaultIndex) {
michael@0 46 this._values = aValues;
michael@0 47 this.defaultIndex = aDefaultIndex;
michael@0 48 }
michael@0 49 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
michael@0 50
michael@0 51
michael@0 52 /**
michael@0 53 * Test AutoComplete with multiple AutoCompleteSearch sources, with one of them
michael@0 54 * (index != 0) returning before the rest.
michael@0 55 */
michael@0 56 function run_test() {
michael@0 57 do_test_pending();
michael@0 58
michael@0 59 var results = ["mozillaTest"];
michael@0 60 var inputStr = "moz";
michael@0 61
michael@0 62 // Async search
michael@0 63 var asyncSearch = new AutoCompleteAsyncSearch("Async",
michael@0 64 new AutoCompleteResult(results, -1));
michael@0 65 // Sync search
michael@0 66 var syncSearch = new AutoCompleteSyncSearch("Sync",
michael@0 67 new AutoCompleteResult(results, 0));
michael@0 68
michael@0 69 // Register searches so AutoCompleteController can find them
michael@0 70 registerAutoCompleteSearch(asyncSearch);
michael@0 71 registerAutoCompleteSearch(syncSearch);
michael@0 72
michael@0 73 var controller = Cc["@mozilla.org/autocomplete/controller;1"].
michael@0 74 getService(Ci.nsIAutoCompleteController);
michael@0 75
michael@0 76 // Make an AutoCompleteInput that uses our searches
michael@0 77 // and confirms results on search complete.
michael@0 78 // Async search MUST be FIRST to trigger the bug this tests.
michael@0 79 var input = new AutoCompleteInputBase([asyncSearch.name, syncSearch.name]);
michael@0 80 input.completeDefaultIndex = true;
michael@0 81 input.textValue = inputStr;
michael@0 82
michael@0 83 // Caret must be at the end. Autofill doesn't happen unless you're typing
michael@0 84 // characters at the end.
michael@0 85 var strLen = inputStr.length;
michael@0 86 input.selectTextRange(strLen, strLen);
michael@0 87
michael@0 88 controller.input = input;
michael@0 89 controller.startSearch(inputStr);
michael@0 90
michael@0 91 input.onSearchComplete = function() {
michael@0 92 do_check_eq(input.textValue, results[0]);
michael@0 93
michael@0 94 // Unregister searches
michael@0 95 unregisterAutoCompleteSearch(asyncSearch);
michael@0 96 unregisterAutoCompleteSearch(syncSearch);
michael@0 97 do_test_finished();
michael@0 98 };
michael@0 99 }

mercurial