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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function AutoCompleteTypeAheadResult(aValues, aFinalCompleteValues) { |
michael@0 | 6 | this._values = aValues; |
michael@0 | 7 | this._finalCompleteValues = aFinalCompleteValues; |
michael@0 | 8 | this.defaultIndex = 0; |
michael@0 | 9 | this._typeAheadResult = true; |
michael@0 | 10 | } |
michael@0 | 11 | AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype); |
michael@0 | 12 | |
michael@0 | 13 | function AutoCompleteResult(aValues) { |
michael@0 | 14 | this._values = aValues; |
michael@0 | 15 | } |
michael@0 | 16 | AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); |
michael@0 | 17 | |
michael@0 | 18 | function AutoCompleteInput(aSearches) { |
michael@0 | 19 | this.searches = aSearches; |
michael@0 | 20 | this.popupOpen = true; |
michael@0 | 21 | this.completeDefaultIndex = true; |
michael@0 | 22 | this.completeSelectedIndex = true; |
michael@0 | 23 | } |
michael@0 | 24 | AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype); |
michael@0 | 25 | |
michael@0 | 26 | function run_test() { |
michael@0 | 27 | run_next_test(); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | add_test(function test_handleEnter() { |
michael@0 | 31 | doSearch("moz", function(aController) { |
michael@0 | 32 | do_check_eq(aController.input.textValue, "mozilla.com"); |
michael@0 | 33 | aController.handleEnter(true); |
michael@0 | 34 | do_check_eq(aController.input.textValue, "mozilla.org"); |
michael@0 | 35 | }); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | function doSearch(aSearchString, aOnCompleteCallback) { |
michael@0 | 39 | let typeAheadSearch = new AutoCompleteSearchBase( |
michael@0 | 40 | "typeAheadSearch", |
michael@0 | 41 | new AutoCompleteTypeAheadResult([ "mozilla.com" ], [ "http://www.mozilla.com" ]) |
michael@0 | 42 | ); |
michael@0 | 43 | registerAutoCompleteSearch(typeAheadSearch); |
michael@0 | 44 | |
michael@0 | 45 | let search = new AutoCompleteSearchBase( |
michael@0 | 46 | "search", |
michael@0 | 47 | new AutoCompleteResult([ "mozilla.org" ]) |
michael@0 | 48 | ); |
michael@0 | 49 | registerAutoCompleteSearch(search); |
michael@0 | 50 | |
michael@0 | 51 | let controller = Cc["@mozilla.org/autocomplete/controller;1"]. |
michael@0 | 52 | getService(Ci.nsIAutoCompleteController); |
michael@0 | 53 | |
michael@0 | 54 | // Make an AutoCompleteInput that uses our searches and confirms results. |
michael@0 | 55 | let input = new AutoCompleteInput([ typeAheadSearch.name, search.name ]); |
michael@0 | 56 | input.textValue = aSearchString; |
michael@0 | 57 | |
michael@0 | 58 | // Caret must be at the end for autofill to happen. |
michael@0 | 59 | let strLen = aSearchString.length; |
michael@0 | 60 | input.selectTextRange(strLen, strLen); |
michael@0 | 61 | controller.input = input; |
michael@0 | 62 | controller.startSearch(aSearchString); |
michael@0 | 63 | |
michael@0 | 64 | input.onSearchComplete = function onSearchComplete() { |
michael@0 | 65 | aOnCompleteCallback(controller); |
michael@0 | 66 | |
michael@0 | 67 | // Clean up. |
michael@0 | 68 | unregisterAutoCompleteSearch(search); |
michael@0 | 69 | run_next_test(); |
michael@0 | 70 | }; |
michael@0 | 71 | } |