1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_413784.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* 1.11 + 1.12 +Test autocomplete for non-English URLs 1.13 + 1.14 +- add a visit for a page with a non-English URL 1.15 +- search 1.16 +- test number of matches (should be exactly one) 1.17 + 1.18 +*/ 1.19 + 1.20 +var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.21 + getService(Ci.nsINavHistoryService); 1.22 +var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.23 + getService(Ci.nsINavBookmarksService); 1.24 + 1.25 +// create test data 1.26 +var searchTerm = "ユニコード"; 1.27 +var decoded = "http://www.foobar.com/" + searchTerm + "/"; 1.28 +var url = uri(decoded); 1.29 + 1.30 +function AutoCompleteInput(aSearches) { 1.31 + this.searches = aSearches; 1.32 +} 1.33 + 1.34 +AutoCompleteInput.prototype = { 1.35 + constructor: AutoCompleteInput, 1.36 + 1.37 + searches: null, 1.38 + 1.39 + minResultsForPopup: 0, 1.40 + timeout: 10, 1.41 + searchParam: "", 1.42 + textValue: "", 1.43 + disableAutoComplete: false, 1.44 + completeDefaultIndex: false, 1.45 + 1.46 + get searchCount() { 1.47 + return this.searches.length; 1.48 + }, 1.49 + 1.50 + getSearchAt: function(aIndex) { 1.51 + return this.searches[aIndex]; 1.52 + }, 1.53 + 1.54 + onSearchBegin: function() {}, 1.55 + onSearchComplete: function() {}, 1.56 + 1.57 + popupOpen: false, 1.58 + 1.59 + popup: { 1.60 + setSelectedIndex: function(aIndex) {}, 1.61 + invalidate: function() {}, 1.62 + 1.63 + // nsISupports implementation 1.64 + QueryInterface: function(iid) { 1.65 + if (iid.equals(Ci.nsISupports) || 1.66 + iid.equals(Ci.nsIAutoCompletePopup)) 1.67 + return this; 1.68 + 1.69 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.70 + } 1.71 + }, 1.72 + 1.73 + // nsISupports implementation 1.74 + QueryInterface: function(iid) { 1.75 + if (iid.equals(Ci.nsISupports) || 1.76 + iid.equals(Ci.nsIAutoCompleteInput)) 1.77 + return this; 1.78 + 1.79 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.80 + } 1.81 +} 1.82 + 1.83 +function run_test() 1.84 +{ 1.85 + do_test_pending(); 1.86 + promiseAddVisits(url).then(continue_test); 1.87 +} 1.88 + 1.89 +function continue_test() 1.90 +{ 1.91 + var controller = Components.classes["@mozilla.org/autocomplete/controller;1"]. 1.92 + getService(Components.interfaces.nsIAutoCompleteController); 1.93 + 1.94 + // Make an AutoCompleteInput that uses our searches 1.95 + // and confirms results on search complete 1.96 + var input = new AutoCompleteInput(["history"]); 1.97 + 1.98 + controller.input = input; 1.99 + 1.100 + var numSearchesStarted = 0; 1.101 + input.onSearchBegin = function() { 1.102 + numSearchesStarted++; 1.103 + do_check_eq(numSearchesStarted, 1); 1.104 + }; 1.105 + 1.106 + input.onSearchComplete = function() { 1.107 + do_check_eq(numSearchesStarted, 1); 1.108 + do_check_eq(controller.searchStatus, 1.109 + Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH); 1.110 + 1.111 + // test that we found the entry we added 1.112 + do_check_eq(controller.matchCount, 1); 1.113 + 1.114 + // Make sure the url is the same according to spec, so it can be deleted 1.115 + do_check_eq(controller.getValueAt(0), url.spec); 1.116 + 1.117 + do_test_finished(); 1.118 + }; 1.119 + 1.120 + controller.startSearch(searchTerm); 1.121 +}