Print shortest path to expected garbage for unlink deficiencies as well. b=422848...
[mozilla-1.9.git] / toolkit / components / places / tests / unit / test_416214.js
blob8d2706cab0c1d3d74e1a1ad2f1fe39606bfc8d7e
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 /* ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is Bug 378079 unit test code.
17  *
18  * The Initial Developer of the Original Code is POTI Inc.
19  * Portions created by the Initial Developer are Copyright (C) 2007
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   Erwan Loisant <eloisant@gmail.com>
24  *   Edward Lee <edward.lee@engineering.uiuc.edu>
25  *
26  * Alternatively, the contents of this file may be used under the terms of
27  * either the GNU General Public License Version 2 or later (the "GPL"), or
28  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29  * in which case the provisions of the GPL or the LGPL are applicable instead
30  * of those above. If you wish to allow use of your version of this file only
31  * under the terms of either the GPL or the LGPL, and not to allow others to
32  * use your version of this file under the terms of the MPL, indicate your
33  * decision by deleting the provisions above and replace them with the notice
34  * and other provisions required by the GPL or the LGPL. If you do not delete
35  * the provisions above, a recipient may use your version of this file under
36  * the terms of any one of the MPL, the GPL or the LGPL.
37  *
38  * ***** END LICENSE BLOCK ***** */
42 Test autocomplete for non-English URLs that match the tag bug 416214
43 Also test bug 417441 by making sure escaped ascii characters like "+" remain
44 escaped.
46 - add a visit for a page with a non-English URL
47 - add a tag for the page
48 - search for the tag
49 - test number of matches (should be exactly one)
50 - make sure the url is decoded
54 try {
55   var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
56                 getService(Ci.nsINavHistoryService);
57   var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
58               getService(Ci.nsINavBookmarksService);
59   var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
60                 getService(Ci.nsITaggingService);
61 } catch (ex) {
62   do_throw("Could not get services\n");
65 function add_visit(aURI, aVisitDate, aVisitType) {
66   var isRedirect = aVisitType == histsvc.TRANSITION_REDIRECT_PERMANENT ||
67                    aVisitType == histsvc.TRANSITION_REDIRECT_TEMPORARY;
68   var placeID = histsvc.addVisit(aURI, aVisitDate, null,
69                                  aVisitType, isRedirect, 0);
70   do_check_true(placeID > 0);
71   return placeID;
74 // create test data
75 var searchTerm = "ユニコード";
76 var theTag = "superTag";
77 var decoded = "http://www.foobar.com/" + searchTerm + "/blocking-firefox3%2B";
78 var url = uri(decoded);
79 add_visit(url, Date.now(), Ci.nsINavHistoryService.TRANSITION_LINK);
80 tagssvc.tagURI(url, [theTag]);
82 function AutoCompleteInput(aSearches) {
83   this.searches = aSearches;
86 AutoCompleteInput.prototype = {
87   constructor: AutoCompleteInput, 
89   searches: null,
91   minResultsForPopup: 0,
92   timeout: 10,
93   searchParam: "",
94   textValue: "",
95   disableAutoComplete: false,  
96   completeDefaultIndex: false,
98   get searchCount() {
99     return this.searches.length;
100   },
102   getSearchAt: function(aIndex) {
103     return this.searches[aIndex];
104   },
106   onSearchBegin: function() {},
107   onSearchComplete: function() {},
109   popupOpen: false,
111   popup: {
112     setSelectedIndex: function(aIndex) {},
113     invalidate: function() {},
115     // nsISupports implementation
116     QueryInterface: function(iid) {
117       if (iid.equals(Ci.nsISupports) ||
118           iid.equals(Ci.nsIAutoCompletePopup))
119         return this;
121       throw Components.results.NS_ERROR_NO_INTERFACE;
122     }
123   },
125   // nsISupports implementation
126   QueryInterface: function(iid) {
127     if (iid.equals(Ci.nsISupports) ||
128         iid.equals(Ci.nsIAutoCompleteInput))
129       return this;
131     throw Components.results.NS_ERROR_NO_INTERFACE;
132   }
135 function run_test() {
136   var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
137                    getService(Components.interfaces.nsIAutoCompleteController);
139   // Make an AutoCompleteInput that uses our searches
140   // and confirms results on search complete
141   var input = new AutoCompleteInput(["history"]);
143   controller.input = input;
145   // Search is asynchronous, so don't let the test finish immediately
146   do_test_pending();
148   var numSearchesStarted = 0;
149   input.onSearchBegin = function() {
150     numSearchesStarted++;
151     do_check_eq(numSearchesStarted, 1);
152   };
154   input.onSearchComplete = function() {
155     do_check_eq(numSearchesStarted, 1);
156     do_check_eq(controller.searchStatus,
157                 Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
159     // test that we found the entry we added
160     do_check_eq(controller.matchCount, 1);
162     // Make sure the url is the one with the decoded search string
163     do_check_eq(controller.getValueAt(0), url.spec);
165     do_test_finished();
166   };
168   controller.startSearch(theTag);