summaryrefslogtreecommitdiffstats
path: root/toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-25 15:48:44 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-25 15:48:44 +0200
commit3ab6c7feee8126bdfc5c9ab9371db41102e12e95 (patch)
treea309c45826300b888238b6a517051fe7e71d63eb /toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js
parentb18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a (diff)
parentb069dabc91b7e0f5f8d161cdbe598276a21d6d68 (diff)
downloadUXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.gz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.lz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.xz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.zip
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into pm_url_1
Diffstat (limited to 'toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js')
-rw-r--r--toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js b/toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js
new file mode 100644
index 000000000..fb4153355
--- /dev/null
+++ b/toolkit/components/autocomplete/tests/unit/test_popupSelectionVsDefaultCompleteValue.js
@@ -0,0 +1,71 @@
+/* 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 AutoCompleteTypeAheadResult(aValues, aFinalCompleteValues) {
+ this._values = aValues;
+ this._finalCompleteValues = aFinalCompleteValues;
+ this.defaultIndex = 0;
+ this._typeAheadResult = true;
+}
+AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype);
+
+function AutoCompleteResult(aValues) {
+ this._values = aValues;
+}
+AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
+
+function AutoCompleteInput(aSearches) {
+ this.searches = aSearches;
+ this.popupOpen = true;
+ this.completeDefaultIndex = true;
+ this.completeSelectedIndex = true;
+}
+AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
+
+function run_test() {
+ run_next_test();
+}
+
+add_test(function test_handleEnter() {
+ doSearch("moz", function(aController) {
+ do_check_eq(aController.input.textValue, "mozilla.com");
+ aController.handleEnter(true);
+ do_check_eq(aController.input.textValue, "mozilla.org");
+ });
+});
+
+function doSearch(aSearchString, aOnCompleteCallback) {
+ let typeAheadSearch = new AutoCompleteSearchBase(
+ "typeAheadSearch",
+ new AutoCompleteTypeAheadResult([ "mozilla.com" ], [ "http://www.mozilla.com" ])
+ );
+ registerAutoCompleteSearch(typeAheadSearch);
+
+ let search = new AutoCompleteSearchBase(
+ "search",
+ new AutoCompleteResult([ "mozilla.org" ])
+ );
+ registerAutoCompleteSearch(search);
+
+ let controller = Cc["@mozilla.org/autocomplete/controller;1"].
+ getService(Ci.nsIAutoCompleteController);
+
+ // Make an AutoCompleteInput that uses our searches and confirms results.
+ let input = new AutoCompleteInput([ typeAheadSearch.name, search.name ]);
+ input.textValue = aSearchString;
+
+ // Caret must be at the end for autofill to happen.
+ let strLen = aSearchString.length;
+ input.selectTextRange(strLen, strLen);
+ controller.input = input;
+ controller.startSearch(aSearchString);
+
+ input.onSearchComplete = function onSearchComplete() {
+ aOnCompleteCallback(controller);
+
+ // Clean up.
+ unregisterAutoCompleteSearch(search);
+ run_next_test();
+ };
+}