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_660156.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_660156.js')
-rw-r--r-- | toolkit/components/autocomplete/tests/unit/test_660156.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_660156.js b/toolkit/components/autocomplete/tests/unit/test_660156.js new file mode 100644 index 000000000..98acb243e --- /dev/null +++ b/toolkit/components/autocomplete/tests/unit/test_660156.js @@ -0,0 +1,101 @@ +/** + * Search object that returns results at different times. + * First, the search that returns results asynchronously. + */ +function AutoCompleteAsyncSearch(aName, aResult) { + this.name = aName; + this._result = aResult; +} +AutoCompleteAsyncSearch.prototype = Object.create(AutoCompleteSearchBase.prototype); +AutoCompleteAsyncSearch.prototype.startSearch = function(aSearchString, + aSearchParam, + aPreviousResult, + aListener) { + this._result.searchResult = Ci.nsIAutoCompleteResult.RESULT_NOMATCH_ONGOING; + aListener.onSearchResult(this, this._result); + + do_timeout(500, () => { + this._returnResults(aListener); + }); +}; + +AutoCompleteAsyncSearch.prototype._returnResults = function(aListener) { + var result = this._result; + + result.searchResult = Ci.nsIAutoCompleteResult.RESULT_SUCCESS; + aListener.onSearchResult(this, result); +}; + +/** + * The synchronous version + */ +function AutoCompleteSyncSearch(aName, aResult) { + this.name = aName; + this._result = aResult; +} +AutoCompleteSyncSearch.prototype = Object.create(AutoCompleteAsyncSearch.prototype); +AutoCompleteSyncSearch.prototype.startSearch = function(aSearchString, + aSearchParam, + aPreviousResult, + aListener) { + this._returnResults(aListener); +}; + +/** + * Results object + */ +function AutoCompleteResult(aValues, aDefaultIndex) { + this._values = aValues; + this.defaultIndex = aDefaultIndex; +} +AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); + + +/** + * Test AutoComplete with multiple AutoCompleteSearch sources, with one of them + * (index != 0) returning before the rest. + */ +function run_test() { + do_test_pending(); + + var results = ["mozillaTest"]; + var inputStr = "moz"; + + // Async search + var asyncSearch = new AutoCompleteAsyncSearch("Async", + new AutoCompleteResult(results, -1)); + // Sync search + var syncSearch = new AutoCompleteSyncSearch("Sync", + new AutoCompleteResult(results, 0)); + + // Register searches so AutoCompleteController can find them + registerAutoCompleteSearch(asyncSearch); + registerAutoCompleteSearch(syncSearch); + + var controller = Cc["@mozilla.org/autocomplete/controller;1"]. + getService(Ci.nsIAutoCompleteController); + + // Make an AutoCompleteInput that uses our searches + // and confirms results on search complete. + // Async search MUST be FIRST to trigger the bug this tests. + var input = new AutoCompleteInputBase([asyncSearch.name, syncSearch.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. + var strLen = inputStr.length; + input.selectTextRange(strLen, strLen); + + controller.input = input; + controller.startSearch(inputStr); + + input.onSearchComplete = function() { + do_check_eq(input.textValue, results[0]); + + // Unregister searches + unregisterAutoCompleteSearch(asyncSearch); + unregisterAutoCompleteSearch(syncSearch); + do_test_finished(); + }; +} |