michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function AutoCompleteResult(aValues) { michael@0: this._values = aValues; michael@0: this.defaultIndex = -1; michael@0: this._typeAheadResult = false; michael@0: } michael@0: AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); michael@0: michael@0: function AutoCompleteTypeAheadResult(aValues) { michael@0: this._values = aValues; michael@0: this.defaultIndex = 0; michael@0: this._typeAheadResult = true; michael@0: } michael@0: AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype); michael@0: michael@0: michael@0: /** michael@0: * Test AutoComplete with multiple AutoCompleteSearch sources, with one of them michael@0: * being hidden from the popup, but can still do typeahead completion. michael@0: */ michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: var inputStr = "moz"; michael@0: michael@0: // Type ahead result michael@0: var searchTypeAhead = new AutoCompleteSearchBase("search1", michael@0: new AutoCompleteTypeAheadResult(["mozillaTest1"])); michael@0: // Regular result michael@0: var searchNormal = new AutoCompleteSearchBase("search2", michael@0: new AutoCompleteResult(["mozillaTest2"])); michael@0: michael@0: // Register searches so AutoCompleteController can find them michael@0: registerAutoCompleteSearch(searchNormal); michael@0: registerAutoCompleteSearch(searchTypeAhead); michael@0: michael@0: // Make an AutoCompleteInput that uses our searches michael@0: // and confirms results on search complete. michael@0: var input = new AutoCompleteInputBase([searchTypeAhead.name, searchNormal.name]); michael@0: input.completeDefaultIndex = true; michael@0: input.textValue = inputStr; michael@0: michael@0: // Caret must be at the end. Autofill doesn't happen unless you're typing michael@0: // characters at the end. michael@0: var strLen = inputStr.length; michael@0: input.selectTextRange(strLen, strLen); michael@0: do_check_eq(input.selectionStart, strLen); michael@0: do_check_eq(input.selectionEnd, strLen); michael@0: michael@0: var controller = Cc["@mozilla.org/autocomplete/controller;1"]. michael@0: getService(Ci.nsIAutoCompleteController); michael@0: michael@0: controller.input = input; michael@0: controller.startSearch(inputStr); michael@0: michael@0: input.onSearchComplete = function() { michael@0: // Hidden results should still be able to do inline autocomplete michael@0: do_check_eq(input.textValue, "mozillaTest1"); michael@0: michael@0: // Now, let's fill the textbox with the first result of the popup. michael@0: // The first search is marked as hidden, so we must always get the michael@0: // second search. michael@0: controller.handleEnter(true); michael@0: do_check_eq(input.textValue, "mozillaTest2"); michael@0: michael@0: // Only one item in the popup. michael@0: do_check_eq(controller.matchCount, 1); michael@0: michael@0: // Unregister searches michael@0: unregisterAutoCompleteSearch(searchNormal); michael@0: unregisterAutoCompleteSearch(searchTypeAhead); michael@0: do_test_finished(); michael@0: }; michael@0: }