toolkit/components/places/tests/unit/test_413784.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:8583fdbd8cdc
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/. */
6
7 /*
8
9 Test autocomplete for non-English URLs
10
11 - add a visit for a page with a non-English URL
12 - search
13 - test number of matches (should be exactly one)
14
15 */
16
17 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
18 getService(Ci.nsINavHistoryService);
19 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
20 getService(Ci.nsINavBookmarksService);
21
22 // create test data
23 var searchTerm = "ユニコード";
24 var decoded = "http://www.foobar.com/" + searchTerm + "/";
25 var url = uri(decoded);
26
27 function AutoCompleteInput(aSearches) {
28 this.searches = aSearches;
29 }
30
31 AutoCompleteInput.prototype = {
32 constructor: AutoCompleteInput,
33
34 searches: null,
35
36 minResultsForPopup: 0,
37 timeout: 10,
38 searchParam: "",
39 textValue: "",
40 disableAutoComplete: false,
41 completeDefaultIndex: false,
42
43 get searchCount() {
44 return this.searches.length;
45 },
46
47 getSearchAt: function(aIndex) {
48 return this.searches[aIndex];
49 },
50
51 onSearchBegin: function() {},
52 onSearchComplete: function() {},
53
54 popupOpen: false,
55
56 popup: {
57 setSelectedIndex: function(aIndex) {},
58 invalidate: function() {},
59
60 // nsISupports implementation
61 QueryInterface: function(iid) {
62 if (iid.equals(Ci.nsISupports) ||
63 iid.equals(Ci.nsIAutoCompletePopup))
64 return this;
65
66 throw Components.results.NS_ERROR_NO_INTERFACE;
67 }
68 },
69
70 // nsISupports implementation
71 QueryInterface: function(iid) {
72 if (iid.equals(Ci.nsISupports) ||
73 iid.equals(Ci.nsIAutoCompleteInput))
74 return this;
75
76 throw Components.results.NS_ERROR_NO_INTERFACE;
77 }
78 }
79
80 function run_test()
81 {
82 do_test_pending();
83 promiseAddVisits(url).then(continue_test);
84 }
85
86 function continue_test()
87 {
88 var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
89 getService(Components.interfaces.nsIAutoCompleteController);
90
91 // Make an AutoCompleteInput that uses our searches
92 // and confirms results on search complete
93 var input = new AutoCompleteInput(["history"]);
94
95 controller.input = input;
96
97 var numSearchesStarted = 0;
98 input.onSearchBegin = function() {
99 numSearchesStarted++;
100 do_check_eq(numSearchesStarted, 1);
101 };
102
103 input.onSearchComplete = function() {
104 do_check_eq(numSearchesStarted, 1);
105 do_check_eq(controller.searchStatus,
106 Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
107
108 // test that we found the entry we added
109 do_check_eq(controller.matchCount, 1);
110
111 // Make sure the url is the same according to spec, so it can be deleted
112 do_check_eq(controller.getValueAt(0), url.spec);
113
114 do_test_finished();
115 };
116
117 controller.startSearch(searchTerm);
118 }

mercurial