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, aFinalCompleteValues) {
6 this._values = aValues;
7 this._finalCompleteValues = aFinalCompleteValues;
8 this.defaultIndex = 0;
9 }
10 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
12 function AutoCompleteInput(aSearches) {
13 this.searches = aSearches;
14 this.popup.selectedIndex = -1;
15 }
16 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
18 function run_test() {
19 run_next_test();
20 }
22 add_test(function test_handleEnter() {
23 doSearch("", "mozilla.com", "http://www.mozilla.com", function(aController) {
24 do_check_eq(aController.input.textValue, "");
25 do_check_eq(aController.getFinalCompleteValueAt(0), "http://www.mozilla.com");
26 aController.input.forceComplete = true;
27 aController.handleEnter(false);
28 do_check_eq(aController.input.textValue, "http://www.mozilla.com");
29 });
30 });
32 function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) {
33 let search = new AutoCompleteSearchBase(
34 "search",
35 new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ])
36 );
37 registerAutoCompleteSearch(search);
39 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
40 getService(Ci.nsIAutoCompleteController);
42 // Make an AutoCompleteInput that uses our searches and confirms results.
43 let input = new AutoCompleteInput([ search.name ]);
44 input.textValue = aSearchString;
46 controller.input = input;
47 controller.startSearch(aSearchString);
49 input.onSearchComplete = function onSearchComplete() {
50 aOnCompleteCallback(controller);
52 // Clean up.
53 unregisterAutoCompleteSearch(search);
54 run_next_test();
55 };
56 }