diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/autocomplete/tests/unit/test_immediate_search.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/autocomplete/tests/unit/test_immediate_search.js')
-rw-r--r-- | toolkit/components/autocomplete/tests/unit/test_immediate_search.js | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_immediate_search.js b/toolkit/components/autocomplete/tests/unit/test_immediate_search.js new file mode 100644 index 000000000..0579f5dcb --- /dev/null +++ b/toolkit/components/autocomplete/tests/unit/test_immediate_search.js @@ -0,0 +1,157 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +function AutoCompleteImmediateSearch(aName, aResult) { + this.name = aName; + this._result = aResult; +} +AutoCompleteImmediateSearch.prototype = Object.create(AutoCompleteSearchBase.prototype); +AutoCompleteImmediateSearch.prototype.searchType = + Ci.nsIAutoCompleteSearchDescriptor.SEARCH_TYPE_IMMEDIATE; +AutoCompleteImmediateSearch.prototype.QueryInterface = + XPCOMUtils.generateQI([Ci.nsIFactory, + Ci.nsIAutoCompleteSearch, + Ci.nsIAutoCompleteSearchDescriptor]); + +function AutoCompleteDelayedSearch(aName, aResult) { + this.name = aName; + this._result = aResult; +} +AutoCompleteDelayedSearch.prototype = Object.create(AutoCompleteSearchBase.prototype); + +function AutoCompleteResult(aValues, aDefaultIndex) { + this._values = aValues; + this.defaultIndex = aDefaultIndex; +} +AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); + +function run_test() { + run_next_test(); +} + +/** + * An immediate search should be executed synchronously. + */ +add_test(function test_immediate_search() { + let inputStr = "moz"; + + let immediateSearch = new AutoCompleteImmediateSearch( + "immediate", new AutoCompleteResult(["moz-immediate"], 0)); + registerAutoCompleteSearch(immediateSearch); + let delayedSearch = new AutoCompleteDelayedSearch( + "delayed", new AutoCompleteResult(["moz-delayed"], 0)); + registerAutoCompleteSearch(delayedSearch); + + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. + getService(Ci.nsIAutoCompleteController); + + let input = new AutoCompleteInputBase([delayedSearch.name, + immediateSearch.name]); + input.completeDefaultIndex = true; + input.textValue = inputStr; + + // Caret must be at the end. Autofill doesn't happen unless you're typing + // characters at the end. + let strLen = inputStr.length; + input.selectTextRange(strLen, strLen); + + controller.input = input; + controller.startSearch(inputStr); + + // Immediately check the result, the immediate search should have finished. + do_check_eq(input.textValue, "moz-immediate"); + + // Wait for both queries to finish. + input.onSearchComplete = function() { + // Sanity check. + do_check_eq(input.textValue, "moz-immediate"); + + unregisterAutoCompleteSearch(immediateSearch); + unregisterAutoCompleteSearch(delayedSearch); + run_next_test(); + }; +}); + +/** + * An immediate search should be executed before any delayed search. + */ +add_test(function test_immediate_search_notimeout() { + let inputStr = "moz"; + + let immediateSearch = new AutoCompleteImmediateSearch( + "immediate", new AutoCompleteResult(["moz-immediate"], 0)); + registerAutoCompleteSearch(immediateSearch); + + let delayedSearch = new AutoCompleteDelayedSearch( + "delayed", new AutoCompleteResult(["moz-delayed"], 0)); + registerAutoCompleteSearch(delayedSearch); + + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. + getService(Ci.nsIAutoCompleteController); + + let input = new AutoCompleteInputBase([delayedSearch.name, + immediateSearch.name]); + input.completeDefaultIndex = true; + input.textValue = inputStr; + input.timeout = 0; + + // Caret must be at the end. Autofill doesn't happen unless you're typing + // characters at the end. + let strLen = inputStr.length; + input.selectTextRange(strLen, strLen); + + controller.input = input; + let complete = false; + input.onSearchComplete = function() { + complete = true; + }; + controller.startSearch(inputStr); + do_check_true(complete); + + // Immediately check the result, the immediate search should have finished. + do_check_eq(input.textValue, "moz-immediate"); + + unregisterAutoCompleteSearch(immediateSearch); + unregisterAutoCompleteSearch(delayedSearch); + run_next_test(); +}); + +/** + * A delayed search should be executed synchronously with a zero timeout. + */ +add_test(function test_delayed_search_notimeout() { + let inputStr = "moz"; + + let delayedSearch = new AutoCompleteDelayedSearch( + "delayed", new AutoCompleteResult(["moz-delayed"], 0)); + registerAutoCompleteSearch(delayedSearch); + + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. + getService(Ci.nsIAutoCompleteController); + + let input = new AutoCompleteInputBase([delayedSearch.name]); + input.completeDefaultIndex = true; + input.textValue = inputStr; + input.timeout = 0; + + // Caret must be at the end. Autofill doesn't happen unless you're typing + // characters at the end. + let strLen = inputStr.length; + input.selectTextRange(strLen, strLen); + + controller.input = input; + let complete = false; + input.onSearchComplete = function() { + complete = true; + }; + controller.startSearch(inputStr); + do_check_true(complete); + + // Immediately check the result, the delayed search should have finished. + do_check_eq(input.textValue, "moz-delayed"); + + unregisterAutoCompleteSearch(delayedSearch); + run_next_test(); +}); |