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: var current_test = 0; michael@0: michael@0: function AutoCompleteInput(aSearches) { michael@0: this.searches = aSearches; 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: // Get tagging service michael@0: try { michael@0: var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"]. michael@0: getService(Ci.nsITaggingService); michael@0: } catch(ex) { michael@0: do_throw("Could not get tagging service\n"); michael@0: } michael@0: michael@0: function ensure_tag_results(uris, searchTerm) 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: // Search is asynchronous, so don't let the test finish immediately michael@0: do_test_pending(); 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: do_check_eq(controller.matchCount, uris.length); michael@0: let vals = []; michael@0: for (var i=0; i