diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-04-14 21:49:04 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-04-14 21:49:04 +0200 |
commit | 39dac57259cff8b61db0b22cb2ad0a8adb02692e (patch) | |
tree | 52a026cc8c22793eb17fd0f5e22adce1ae08a1dd /toolkit/components/autocomplete/tests/unit/test_immediate_search.js | |
parent | a1cce3b2b00bbd9f4983013ddd8934a7bccb9e99 (diff) | |
parent | c2d9ab62f3d097c9e0e00184cab1f546554f5eaa (diff) | |
download | UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.gz UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.lz UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.xz UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.zip |
Merge branch 'redwood' into 28.9-platform
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, 0 insertions, 157 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_immediate_search.js b/toolkit/components/autocomplete/tests/unit/test_immediate_search.js deleted file mode 100644 index 0579f5dcb..000000000 --- a/toolkit/components/autocomplete/tests/unit/test_immediate_search.js +++ /dev/null @@ -1,157 +0,0 @@ -/* 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(); -}); |