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 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
6 const Cc = Components.classes;
7 const Ci = Components.interfaces;
9 /**
10 * Dummy nsIAutoCompleteInput source that returns
11 * the given list of AutoCompleteSearch names.
12 *
13 * Implements only the methods needed for this test.
14 */
15 function AutoCompleteInputBase(aSearches) {
16 this.searches = aSearches;
17 }
18 AutoCompleteInputBase.prototype = {
20 // Array of AutoCompleteSearch names
21 searches: null,
23 minResultsForPopup: 0,
24 timeout: 10,
25 searchParam: "",
26 textValue: "",
27 disableAutoComplete: false,
28 completeDefaultIndex: false,
30 // Text selection range
31 _selStart: 0,
32 _selEnd: 0,
33 get selectionStart() {
34 return this._selStart;
35 },
36 get selectionEnd() {
37 return this._selEnd;
38 },
39 selectTextRange: function(aStart, aEnd) {
40 this._selStart = aStart;
41 this._selEnd = aEnd;
42 },
44 get searchCount() {
45 return this.searches.length;
46 },
48 getSearchAt: function(aIndex) {
49 return this.searches[aIndex];
50 },
52 onSearchBegin: function() {},
53 onSearchComplete: function() {},
55 popupOpen: false,
57 popup: {
58 selectedIndex: 0,
59 invalidate: function() {},
61 // nsISupports implementation
62 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup])
63 },
65 // nsISupports implementation
66 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput])
67 }
69 /**
70 * nsIAutoCompleteResult implementation
71 */
72 function AutoCompleteResultBase(aValues) {
73 this._values = aValues;
74 }
75 AutoCompleteResultBase.prototype = {
77 // Arrays
78 _values: null,
79 _comments: [],
80 _styles: [],
81 _finalCompleteValues: [],
83 searchString: "",
84 searchResult: null,
86 defaultIndex: -1,
88 _typeAheadResult: false,
89 get typeAheadResult() {
90 return this._typeAheadResult;
91 },
93 get matchCount() {
94 return this._values.length;
95 },
97 getValueAt: function(aIndex) {
98 return this._values[aIndex];
99 },
101 getLabelAt: function(aIndex) {
102 return this.getValueAt(aIndex);
103 },
105 getCommentAt: function(aIndex) {
106 return this._comments[aIndex];
107 },
109 getStyleAt: function(aIndex) {
110 return this._styles[aIndex];
111 },
113 getImageAt: function(aIndex) {
114 return "";
115 },
117 getFinalCompleteValueAt: function(aIndex) {
118 return this._finalCompleteValues[aIndex] || this._values[aIndex];
119 },
121 removeValueAt: function (aRowIndex, aRemoveFromDb) {},
123 // nsISupports implementation
124 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteResult])
125 }
127 /**
128 * nsIAutoCompleteSearch implementation that always returns
129 * the same result set.
130 */
131 function AutoCompleteSearchBase(aName, aResult) {
132 this.name = aName;
133 this._result = aResult;
134 }
135 AutoCompleteSearchBase.prototype = {
137 // Search name. Used by AutoCompleteController
138 name: null,
140 // AutoCompleteResult
141 _result: null,
143 startSearch: function(aSearchString,
144 aSearchParam,
145 aPreviousResult,
146 aListener) {
147 var result = this._result;
149 result.searchResult = Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
150 aListener.onSearchResult(this, result);
151 },
153 stopSearch: function() {},
155 // nsISupports implementation
156 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
157 Ci.nsIAutoCompleteSearch]),
159 // nsIFactory implementation
160 createInstance: function(outer, iid) {
161 return this.QueryInterface(iid);
162 }
163 }
165 /**
166 * Helper to register an AutoCompleteSearch with the given name.
167 * Allows the AutoCompleteController to find the search.
168 */
169 function registerAutoCompleteSearch(aSearch) {
170 var name = "@mozilla.org/autocomplete/search;1?name=" + aSearch.name;
171 var cid = Cc["@mozilla.org/uuid-generator;1"].
172 getService(Ci.nsIUUIDGenerator).
173 generateUUID();
175 var desc = "Test AutoCompleteSearch";
176 var componentManager = Components.manager
177 .QueryInterface(Ci.nsIComponentRegistrar);
178 componentManager.registerFactory(cid, desc, name, aSearch);
180 // Keep the id on the object so we can unregister later
181 aSearch.cid = cid;
182 }
184 /**
185 * Helper to unregister an AutoCompleteSearch.
186 */
187 function unregisterAutoCompleteSearch(aSearch) {
188 var componentManager = Components.manager
189 .QueryInterface(Ci.nsIComponentRegistrar);
190 componentManager.unregisterFactory(aSearch.cid, aSearch);
191 }