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 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const TEST_URL = "http://adapt.mozilla.org/";
8 const SEARCH_STRING = "adapt";
10 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
12 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
13 getService(Ci.nsINavHistoryService);
14 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
15 getService(Ci.nsINavBookmarksService);
16 let os = Cc["@mozilla.org/observer-service;1"].
17 getService(Ci.nsIObserverService);
18 let ps = Cc["@mozilla.org/preferences-service;1"].
19 getService(Ci.nsIPrefBranch);
21 const PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC =
22 "places-autocomplete-feedback-updated";
24 function AutoCompleteInput(aSearches) {
25 this.searches = aSearches;
26 }
27 AutoCompleteInput.prototype = {
28 constructor: AutoCompleteInput,
29 searches: null,
30 minResultsForPopup: 0,
31 timeout: 10,
32 searchParam: "",
33 textValue: "",
34 disableAutoComplete: false,
35 completeDefaultIndex: false,
37 get searchCount() {
38 return this.searches.length;
39 },
41 getSearchAt: function ACI_getSearchAt(aIndex) {
42 return this.searches[aIndex];
43 },
45 onSearchComplete: function ACI_onSearchComplete() {},
47 popupOpen: false,
49 popup: {
50 setSelectedIndex: function() {},
51 invalidate: function() {},
53 QueryInterface: function(iid) {
54 if (iid.equals(Ci.nsISupports) ||
55 iid.equals(Ci.nsIAutoCompletePopup))
56 return this;
58 throw Components.results.NS_ERROR_NO_INTERFACE;
59 }
60 },
62 onSearchBegin: function() {},
64 QueryInterface: function(iid) {
65 if (iid.equals(Ci.nsISupports) ||
66 iid.equals(Ci.nsIAutoCompleteInput))
67 return this;
69 throw Components.results.NS_ERROR_NO_INTERFACE;
70 }
71 }
74 function check_results() {
75 let controller = Cc["@mozilla.org/autocomplete/controller;1"].
76 getService(Ci.nsIAutoCompleteController);
77 let input = new AutoCompleteInput(["history"]);
78 controller.input = input;
80 input.onSearchComplete = function() {
81 do_check_eq(controller.searchStatus,
82 Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
83 do_check_eq(controller.matchCount, 0);
85 remove_all_bookmarks();
86 do_test_finished();
87 };
89 controller.startSearch(SEARCH_STRING);
90 }
93 function addAdaptiveFeedback(aUrl, aSearch, aCallback) {
94 let observer = {
95 observe: function(aSubject, aTopic, aData) {
96 os.removeObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
97 do_timeout(0, aCallback);
98 }
99 };
100 os.addObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC, false);
102 let thing = {
103 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput,
104 Ci.nsIAutoCompletePopup,
105 Ci.nsIAutoCompleteController]),
106 get popup() { return thing; },
107 get controller() { return thing; },
108 popupOpen: true,
109 selectedIndex: 0,
110 getValueAt: function() aUrl,
111 searchString: aSearch
112 };
114 os.notifyObservers(thing, "autocomplete-will-enter-text", null);
115 }
118 function run_test() {
119 do_test_pending();
121 // Add a bookmark to our url.
122 bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URL),
123 bs.DEFAULT_INDEX, "test_book");
124 // We want to search only history.
125 ps.setIntPref("browser.urlbar.default.behavior",
126 Ci.mozIPlacesAutoComplete.BEHAVIOR_HISTORY);
127 // Add an adaptive entry.
128 addAdaptiveFeedback(TEST_URL, SEARCH_STRING, check_results);
129 }