summaryrefslogtreecommitdiffstats
path: root/toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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_badDefaultIndex.js')
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js b/toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js
new file mode 100644
index 000000000..17f735388
--- /dev/null
+++ b/toolkit/components/autocomplete/tests/unit/test_badDefaultIndex.js
@@ -0,0 +1,96 @@
+/* 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/. */
+
+/**
+ * A results that wants to defaultComplete to 0, but it has no matches,
+ * though it notifies SUCCESS to the controller.
+ */
+function AutoCompleteNoMatchResult() {
+ this.defaultIndex = 0;
+}
+AutoCompleteNoMatchResult.prototype = Object.create(AutoCompleteResultBase.prototype);
+
+/**
+ * A results that wants to defaultComplete to an index greater than the number
+ * of matches.
+ */
+function AutoCompleteBadIndexResult(aValues, aDefaultIndex) {
+ do_check_true(aValues.length <= aDefaultIndex);
+ this._values = aValues;
+ this.defaultIndex = aDefaultIndex;
+}
+AutoCompleteBadIndexResult.prototype = Object.create(AutoCompleteResultBase.prototype);
+
+add_test(function autocomplete_noMatch_success() {
+ const INPUT_STR = "moz";
+
+ let searchNoMatch =
+ new AutoCompleteSearchBase("searchNoMatch",
+ new AutoCompleteNoMatchResult());
+ registerAutoCompleteSearch(searchNoMatch);
+
+ // Make an AutoCompleteInput that uses our search and confirms results.
+ let input = new AutoCompleteInputBase([searchNoMatch.name]);
+ input.completeDefaultIndex = true;
+ input.textValue = INPUT_STR;
+
+ // Caret must be at the end for autoFill to happen.
+ let strLen = INPUT_STR.length;
+ input.selectTextRange(strLen, strLen);
+ do_check_eq(input.selectionStart, strLen);
+ do_check_eq(input.selectionEnd, strLen);
+
+ let controller = Cc["@mozilla.org/autocomplete/controller;1"].
+ getService(Ci.nsIAutoCompleteController);
+ controller.input = input;
+ controller.startSearch(INPUT_STR);
+
+ input.onSearchComplete = function () {
+ // Should not try to autoFill to an empty value.
+ do_check_eq(input.textValue, "moz");
+
+ // Clean up.
+ unregisterAutoCompleteSearch(searchNoMatch);
+ run_next_test();
+ };
+});
+
+add_test(function autocomplete_defaultIndex_exceeds_matchCount() {
+ const INPUT_STR = "moz";
+
+ // Result returning matches, but a bad defaultIndex.
+ let searchBadIndex =
+ new AutoCompleteSearchBase("searchBadIndex",
+ new AutoCompleteBadIndexResult(["mozillaTest"], 1));
+ registerAutoCompleteSearch(searchBadIndex);
+
+ // Make an AutoCompleteInput that uses our search and confirms results.
+ let input = new AutoCompleteInputBase([searchBadIndex.name]);
+ input.completeDefaultIndex = true;
+ input.textValue = INPUT_STR;
+
+ // Caret must be at the end for autoFill to happen.
+ let strLen = INPUT_STR.length;
+ input.selectTextRange(strLen, strLen);
+ do_check_eq(input.selectionStart, strLen);
+ do_check_eq(input.selectionEnd, strLen);
+
+ let controller = Cc["@mozilla.org/autocomplete/controller;1"].
+ getService(Ci.nsIAutoCompleteController);
+ controller.input = input;
+ controller.startSearch(INPUT_STR);
+
+ input.onSearchComplete = function () {
+ // Should not try to autoFill to an empty value.
+ do_check_eq(input.textValue, "moz");
+
+ // Clean up.
+ unregisterAutoCompleteSearch(searchBadIndex);
+ run_next_test();
+ };
+});
+
+function run_test() {
+ run_next_test();
+}