1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/autocomplete/tests/unit/test_completeDefaultIndex_casing.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function AutoCompleteResult(aValues) { 1.9 + this._values = aValues; 1.10 + this.defaultIndex = 0; 1.11 +} 1.12 +AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); 1.13 + 1.14 +function AutoCompleteInput(aSearches) { 1.15 + this.searches = aSearches; 1.16 + this.popup.selectedIndex = -1; 1.17 + this.completeDefaultIndex = true; 1.18 +} 1.19 +AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype); 1.20 + 1.21 +function run_test() { 1.22 + run_next_test(); 1.23 +} 1.24 + 1.25 +add_test(function test_keyNavigation() { 1.26 + doSearch("MOZ", "mozilla", function(aController) { 1.27 + do_check_eq(aController.input.textValue, "MOZilla"); 1.28 + aController.handleKeyNavigation(Ci.nsIDOMKeyEvent.DOM_VK_RIGHT); 1.29 + do_check_eq(aController.input.textValue, "mozilla"); 1.30 + }); 1.31 +}); 1.32 + 1.33 +add_test(function test_handleEnter() { 1.34 + doSearch("MOZ", "mozilla", function(aController) { 1.35 + do_check_eq(aController.input.textValue, "MOZilla"); 1.36 + aController.handleEnter(false); 1.37 + do_check_eq(aController.input.textValue, "mozilla"); 1.38 + }); 1.39 +}); 1.40 + 1.41 +function doSearch(aSearchString, aResultValue, aOnCompleteCallback) { 1.42 + let search = new AutoCompleteSearchBase("search", 1.43 + new AutoCompleteResult([ "mozilla", "toolkit" ], 0)); 1.44 + registerAutoCompleteSearch(search); 1.45 + 1.46 + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. 1.47 + getService(Ci.nsIAutoCompleteController); 1.48 + 1.49 + // Make an AutoCompleteInput that uses our searches and confirms results. 1.50 + let input = new AutoCompleteInput([ search.name ]); 1.51 + input.textValue = aSearchString; 1.52 + 1.53 + // Caret must be at the end for autofill to happen. 1.54 + let strLen = aSearchString.length; 1.55 + input.selectTextRange(strLen, strLen); 1.56 + controller.input = input; 1.57 + controller.startSearch(aSearchString); 1.58 + 1.59 + input.onSearchComplete = function onSearchComplete() { 1.60 + aOnCompleteCallback(controller); 1.61 + 1.62 + // Clean up. 1.63 + unregisterAutoCompleteSearch(search); 1.64 + run_next_test(); 1.65 + }; 1.66 +}