Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 function AutoCompleteResult(aValues) {
6 this._values = aValues;
7 this.defaultIndex = 0;
8 }
9 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
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);
18 function run_test() {
19 run_next_test();
20 }
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 });
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 });
38 function doSearch(aSearchString, aResultValue, aOnCompleteCallback) {
39 let search = new AutoCompleteSearchBase("search",
40 new AutoCompleteResult([ "mozilla", "toolkit" ], 0));
41 registerAutoCompleteSearch(search);
43 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
44 getService(Ci.nsIAutoCompleteController);
46 // Make an AutoCompleteInput that uses our searches and confirms results.
47 let input = new AutoCompleteInput([ search.name ]);
48 input.textValue = aSearchString;
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);
56 input.onSearchComplete = function onSearchComplete() {
57 aOnCompleteCallback(controller);
59 // Clean up.
60 unregisterAutoCompleteSearch(search);
61 run_next_test();
62 };
63 }