Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function AutoCompleteResult(aValues) { |
michael@0 | 5 | this._values = aValues; |
michael@0 | 6 | this.defaultIndex = -1; |
michael@0 | 7 | this._typeAheadResult = false; |
michael@0 | 8 | } |
michael@0 | 9 | AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); |
michael@0 | 10 | |
michael@0 | 11 | function AutoCompleteTypeAheadResult(aValues) { |
michael@0 | 12 | this._values = aValues; |
michael@0 | 13 | this.defaultIndex = 0; |
michael@0 | 14 | this._typeAheadResult = true; |
michael@0 | 15 | } |
michael@0 | 16 | AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype); |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * Test AutoComplete with multiple AutoCompleteSearch sources, with one of them |
michael@0 | 21 | * being hidden from the popup, but can still do typeahead completion. |
michael@0 | 22 | */ |
michael@0 | 23 | function run_test() { |
michael@0 | 24 | do_test_pending(); |
michael@0 | 25 | |
michael@0 | 26 | var inputStr = "moz"; |
michael@0 | 27 | |
michael@0 | 28 | // Type ahead result |
michael@0 | 29 | var searchTypeAhead = new AutoCompleteSearchBase("search1", |
michael@0 | 30 | new AutoCompleteTypeAheadResult(["mozillaTest1"])); |
michael@0 | 31 | // Regular result |
michael@0 | 32 | var searchNormal = new AutoCompleteSearchBase("search2", |
michael@0 | 33 | new AutoCompleteResult(["mozillaTest2"])); |
michael@0 | 34 | |
michael@0 | 35 | // Register searches so AutoCompleteController can find them |
michael@0 | 36 | registerAutoCompleteSearch(searchNormal); |
michael@0 | 37 | registerAutoCompleteSearch(searchTypeAhead); |
michael@0 | 38 | |
michael@0 | 39 | // Make an AutoCompleteInput that uses our searches |
michael@0 | 40 | // and confirms results on search complete. |
michael@0 | 41 | var input = new AutoCompleteInputBase([searchTypeAhead.name, searchNormal.name]); |
michael@0 | 42 | input.completeDefaultIndex = true; |
michael@0 | 43 | input.textValue = inputStr; |
michael@0 | 44 | |
michael@0 | 45 | // Caret must be at the end. Autofill doesn't happen unless you're typing |
michael@0 | 46 | // characters at the end. |
michael@0 | 47 | var strLen = inputStr.length; |
michael@0 | 48 | input.selectTextRange(strLen, strLen); |
michael@0 | 49 | do_check_eq(input.selectionStart, strLen); |
michael@0 | 50 | do_check_eq(input.selectionEnd, strLen); |
michael@0 | 51 | |
michael@0 | 52 | var controller = Cc["@mozilla.org/autocomplete/controller;1"]. |
michael@0 | 53 | getService(Ci.nsIAutoCompleteController); |
michael@0 | 54 | |
michael@0 | 55 | controller.input = input; |
michael@0 | 56 | controller.startSearch(inputStr); |
michael@0 | 57 | |
michael@0 | 58 | input.onSearchComplete = function() { |
michael@0 | 59 | // Hidden results should still be able to do inline autocomplete |
michael@0 | 60 | do_check_eq(input.textValue, "mozillaTest1"); |
michael@0 | 61 | |
michael@0 | 62 | // Now, let's fill the textbox with the first result of the popup. |
michael@0 | 63 | // The first search is marked as hidden, so we must always get the |
michael@0 | 64 | // second search. |
michael@0 | 65 | controller.handleEnter(true); |
michael@0 | 66 | do_check_eq(input.textValue, "mozillaTest2"); |
michael@0 | 67 | |
michael@0 | 68 | // Only one item in the popup. |
michael@0 | 69 | do_check_eq(controller.matchCount, 1); |
michael@0 | 70 | |
michael@0 | 71 | // Unregister searches |
michael@0 | 72 | unregisterAutoCompleteSearch(searchNormal); |
michael@0 | 73 | unregisterAutoCompleteSearch(searchTypeAhead); |
michael@0 | 74 | do_test_finished(); |
michael@0 | 75 | }; |
michael@0 | 76 | } |