michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: michael@0: Test autocomplete for non-English URLs michael@0: michael@0: - add a visit for a page with a non-English URL michael@0: - search michael@0: - test number of matches (should be exactly one) michael@0: michael@0: */ michael@0: michael@0: var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. michael@0: getService(Ci.nsINavHistoryService); michael@0: var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: michael@0: // create test data michael@0: var searchTerm = "ユニコード"; michael@0: var decoded = "http://www.foobar.com/" + searchTerm + "/"; michael@0: var url = uri(decoded); michael@0: michael@0: function AutoCompleteInput(aSearches) { michael@0: this.searches = aSearches; michael@0: } michael@0: michael@0: AutoCompleteInput.prototype = { michael@0: constructor: AutoCompleteInput, michael@0: michael@0: searches: null, michael@0: michael@0: minResultsForPopup: 0, michael@0: timeout: 10, michael@0: searchParam: "", michael@0: textValue: "", michael@0: disableAutoComplete: false, michael@0: completeDefaultIndex: false, michael@0: michael@0: get searchCount() { michael@0: return this.searches.length; michael@0: }, michael@0: michael@0: getSearchAt: function(aIndex) { michael@0: return this.searches[aIndex]; michael@0: }, michael@0: michael@0: onSearchBegin: function() {}, michael@0: onSearchComplete: function() {}, michael@0: michael@0: popupOpen: false, michael@0: michael@0: popup: { michael@0: setSelectedIndex: function(aIndex) {}, michael@0: invalidate: function() {}, michael@0: michael@0: // nsISupports implementation michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsISupports) || michael@0: iid.equals(Ci.nsIAutoCompletePopup)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }, michael@0: michael@0: // nsISupports implementation michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsISupports) || michael@0: iid.equals(Ci.nsIAutoCompleteInput)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: do_test_pending(); michael@0: promiseAddVisits(url).then(continue_test); michael@0: } michael@0: michael@0: function continue_test() michael@0: { michael@0: var controller = Components.classes["@mozilla.org/autocomplete/controller;1"]. michael@0: getService(Components.interfaces.nsIAutoCompleteController); michael@0: michael@0: // Make an AutoCompleteInput that uses our searches michael@0: // and confirms results on search complete michael@0: var input = new AutoCompleteInput(["history"]); michael@0: michael@0: controller.input = input; michael@0: michael@0: var numSearchesStarted = 0; michael@0: input.onSearchBegin = function() { michael@0: numSearchesStarted++; michael@0: do_check_eq(numSearchesStarted, 1); michael@0: }; michael@0: michael@0: input.onSearchComplete = function() { michael@0: do_check_eq(numSearchesStarted, 1); michael@0: do_check_eq(controller.searchStatus, michael@0: Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH); michael@0: michael@0: // test that we found the entry we added michael@0: do_check_eq(controller.matchCount, 1); michael@0: michael@0: // Make sure the url is the same according to spec, so it can be deleted michael@0: do_check_eq(controller.getValueAt(0), url.spec); michael@0: michael@0: do_test_finished(); michael@0: }; michael@0: michael@0: controller.startSearch(searchTerm); michael@0: }