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: * Test for bug 406358 to make sure frecency works for empty input/search, but michael@0: * this also tests for non-empty inputs as well. Because the interactions among michael@0: * *DIFFERENT* visit counts and visit dates is not well defined, this test michael@0: * holds one of the two values constant when modifying the other. michael@0: * michael@0: * Also test bug 419068 to make sure tagged pages don't necessarily have to be michael@0: * first in the results. michael@0: * michael@0: * Also test bug 426166 to make sure that the results of autocomplete searches michael@0: * are stable. Note that failures of this test will be intermittent by nature michael@0: * since we are testing to make sure that the unstable sort algorithm used michael@0: * by SQLite is not changing the order of the results on us. michael@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: function ensure_results(uris, searchTerm) michael@0: { michael@0: promiseAsyncUpdates().then(function () ensure_results_internal(uris, michael@0: searchTerm)); michael@0: } michael@0: michael@0: function ensure_results_internal(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: 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: for (var i=0; i