toolkit/components/autocomplete/tests/unit/test_completeDefaultIndex_casing.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:15db422d2f4c
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 function AutoCompleteResult(aValues) {
6 this._values = aValues;
7 this.defaultIndex = 0;
8 }
9 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
10
11 function AutoCompleteInput(aSearches) {
12 this.searches = aSearches;
13 this.popup.selectedIndex = -1;
14 this.completeDefaultIndex = true;
15 }
16 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
17
18 function run_test() {
19 run_next_test();
20 }
21
22 add_test(function test_keyNavigation() {
23 doSearch("MOZ", "mozilla", function(aController) {
24 do_check_eq(aController.input.textValue, "MOZilla");
25 aController.handleKeyNavigation(Ci.nsIDOMKeyEvent.DOM_VK_RIGHT);
26 do_check_eq(aController.input.textValue, "mozilla");
27 });
28 });
29
30 add_test(function test_handleEnter() {
31 doSearch("MOZ", "mozilla", function(aController) {
32 do_check_eq(aController.input.textValue, "MOZilla");
33 aController.handleEnter(false);
34 do_check_eq(aController.input.textValue, "mozilla");
35 });
36 });
37
38 function doSearch(aSearchString, aResultValue, aOnCompleteCallback) {
39 let search = new AutoCompleteSearchBase("search",
40 new AutoCompleteResult([ "mozilla", "toolkit" ], 0));
41 registerAutoCompleteSearch(search);
42
43 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
44 getService(Ci.nsIAutoCompleteController);
45
46 // Make an AutoCompleteInput that uses our searches and confirms results.
47 let input = new AutoCompleteInput([ search.name ]);
48 input.textValue = aSearchString;
49
50 // Caret must be at the end for autofill to happen.
51 let strLen = aSearchString.length;
52 input.selectTextRange(strLen, strLen);
53 controller.input = input;
54 controller.startSearch(aSearchString);
55
56 input.onSearchComplete = function onSearchComplete() {
57 aOnCompleteCallback(controller);
58
59 // Clean up.
60 unregisterAutoCompleteSearch(search);
61 run_next_test();
62 };
63 }

mercurial