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 AutoCompleteTypeAheadResult(aValues, aFinalCompleteValues) {
6 this._values = aValues;
7 this._finalCompleteValues = aFinalCompleteValues;
8 this.defaultIndex = 0;
9 this._typeAheadResult = true;
10 }
11 AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype);
13 function AutoCompleteResult(aValues) {
14 this._values = aValues;
15 }
16 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
18 function AutoCompleteInput(aSearches) {
19 this.searches = aSearches;
20 this.popupOpen = true;
21 this.completeDefaultIndex = true;
22 this.completeSelectedIndex = true;
23 }
24 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
26 function run_test() {
27 run_next_test();
28 }
30 add_test(function test_handleEnter() {
31 doSearch("moz", function(aController) {
32 do_check_eq(aController.input.textValue, "mozilla.com");
33 aController.handleEnter(true);
34 do_check_eq(aController.input.textValue, "mozilla.org");
35 });
36 });
38 function doSearch(aSearchString, aOnCompleteCallback) {
39 let typeAheadSearch = new AutoCompleteSearchBase(
40 "typeAheadSearch",
41 new AutoCompleteTypeAheadResult([ "mozilla.com" ], [ "http://www.mozilla.com" ])
42 );
43 registerAutoCompleteSearch(typeAheadSearch);
45 let search = new AutoCompleteSearchBase(
46 "search",
47 new AutoCompleteResult([ "mozilla.org" ])
48 );
49 registerAutoCompleteSearch(search);
51 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
52 getService(Ci.nsIAutoCompleteController);
54 // Make an AutoCompleteInput that uses our searches and confirms results.
55 let input = new AutoCompleteInput([ typeAheadSearch.name, search.name ]);
56 input.textValue = aSearchString;
58 // Caret must be at the end for autofill to happen.
59 let strLen = aSearchString.length;
60 input.selectTextRange(strLen, strLen);
61 controller.input = input;
62 controller.startSearch(aSearchString);
64 input.onSearchComplete = function onSearchComplete() {
65 aOnCompleteCallback(controller);
67 // Clean up.
68 unregisterAutoCompleteSearch(search);
69 run_next_test();
70 };
71 }