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 /**
6 * A results that wants to defaultComplete to 0, but it has no matches,
7 * though it notifies SUCCESS to the controller.
8 */
9 function AutoCompleteNoMatchResult() {
10 this.defaultIndex = 0;
11 }
12 AutoCompleteNoMatchResult.prototype = Object.create(AutoCompleteResultBase.prototype);
14 /**
15 * A results that wants to defaultComplete to an index greater than the number
16 * of matches.
17 */
18 function AutoCompleteBadIndexResult(aValues, aDefaultIndex) {
19 do_check_true(aValues.length <= aDefaultIndex);
20 this._values = aValues;
21 this.defaultIndex = aDefaultIndex;
22 }
23 AutoCompleteBadIndexResult.prototype = Object.create(AutoCompleteResultBase.prototype);
25 add_test(function autocomplete_noMatch_success() {
26 const INPUT_STR = "moz";
28 let searchNoMatch =
29 new AutoCompleteSearchBase("searchNoMatch",
30 new AutoCompleteNoMatchResult());
31 registerAutoCompleteSearch(searchNoMatch);
33 // Make an AutoCompleteInput that uses our search and confirms results.
34 let input = new AutoCompleteInputBase([searchNoMatch.name]);
35 input.completeDefaultIndex = true;
36 input.textValue = INPUT_STR;
38 // Caret must be at the end for autoFill to happen.
39 let strLen = INPUT_STR.length;
40 input.selectTextRange(strLen, strLen);
41 do_check_eq(input.selectionStart, strLen);
42 do_check_eq(input.selectionEnd, strLen);
44 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
45 getService(Ci.nsIAutoCompleteController);
46 controller.input = input;
47 controller.startSearch(INPUT_STR);
49 input.onSearchComplete = function () {
50 // Should not try to autoFill to an empty value.
51 do_check_eq(input.textValue, "moz");
53 // Clean up.
54 unregisterAutoCompleteSearch(searchNoMatch);
55 run_next_test();
56 };
57 });
59 add_test(function autocomplete_defaultIndex_exceeds_matchCount() {
60 const INPUT_STR = "moz";
62 // Result returning matches, but a bad defaultIndex.
63 let searchBadIndex =
64 new AutoCompleteSearchBase("searchBadIndex",
65 new AutoCompleteBadIndexResult(["mozillaTest"], 1));
66 registerAutoCompleteSearch(searchBadIndex);
68 // Make an AutoCompleteInput that uses our search and confirms results.
69 let input = new AutoCompleteInputBase([searchBadIndex.name]);
70 input.completeDefaultIndex = true;
71 input.textValue = INPUT_STR;
73 // Caret must be at the end for autoFill to happen.
74 let strLen = INPUT_STR.length;
75 input.selectTextRange(strLen, strLen);
76 do_check_eq(input.selectionStart, strLen);
77 do_check_eq(input.selectionEnd, strLen);
79 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
80 getService(Ci.nsIAutoCompleteController);
81 controller.input = input;
82 controller.startSearch(INPUT_STR);
84 input.onSearchComplete = function () {
85 // Should not try to autoFill to an empty value.
86 do_check_eq(input.textValue, "moz");
88 // Clean up.
89 unregisterAutoCompleteSearch(searchBadIndex);
90 run_next_test();
91 };
92 });
94 function run_test() {
95 run_next_test();
96 }