toolkit/components/autocomplete/tests/unit/head_autocomplete.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial