summaryrefslogtreecommitdiffstats
path: root/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js')
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js b/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js
new file mode 100644
index 0000000000..a5a0f9aa0f
--- /dev/null
+++ b/toolkit/components/autocomplete/tests/unit/test_search_zerotimeout.js
@@ -0,0 +1,58 @@
+/* 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 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);
+
+/**
+ * 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);
+ Assert.ok(complete);
+
+ // Immediately check the result, the delayed search should have finished.
+ Assert.equal(input.textValue, "moz-delayed");
+
+ unregisterAutoCompleteSearch(delayedSearch);
+ run_next_test();
+});