|
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, aFinalCompleteValues) { |
|
6 this._values = aValues; |
|
7 this._finalCompleteValues = aFinalCompleteValues; |
|
8 this.defaultIndex = 0; |
|
9 } |
|
10 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); |
|
11 |
|
12 function AutoCompleteInput(aSearches) { |
|
13 this.searches = aSearches; |
|
14 this.popup.selectedIndex = -1; |
|
15 } |
|
16 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype); |
|
17 |
|
18 function run_test() { |
|
19 run_next_test(); |
|
20 } |
|
21 |
|
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 }); |
|
31 |
|
32 function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) { |
|
33 let search = new AutoCompleteSearchBase( |
|
34 "search", |
|
35 new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ]) |
|
36 ); |
|
37 registerAutoCompleteSearch(search); |
|
38 |
|
39 let controller = Cc["@mozilla.org/autocomplete/controller;1"]. |
|
40 getService(Ci.nsIAutoCompleteController); |
|
41 |
|
42 // Make an AutoCompleteInput that uses our searches and confirms results. |
|
43 let input = new AutoCompleteInput([ search.name ]); |
|
44 input.textValue = aSearchString; |
|
45 |
|
46 controller.input = input; |
|
47 controller.startSearch(aSearchString); |
|
48 |
|
49 input.onSearchComplete = function onSearchComplete() { |
|
50 aOnCompleteCallback(controller); |
|
51 |
|
52 // Clean up. |
|
53 unregisterAutoCompleteSearch(search); |
|
54 run_next_test(); |
|
55 }; |
|
56 } |