1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/autocomplete/tests/unit/test_finalCompleteValue_forceComplete.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 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, aFinalCompleteValues) { 1.9 + this._values = aValues; 1.10 + this._finalCompleteValues = aFinalCompleteValues; 1.11 + this.defaultIndex = 0; 1.12 +} 1.13 +AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype); 1.14 + 1.15 +function AutoCompleteInput(aSearches) { 1.16 + this.searches = aSearches; 1.17 + this.popup.selectedIndex = -1; 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_handleEnter() { 1.26 + doSearch("", "mozilla.com", "http://www.mozilla.com", function(aController) { 1.27 + do_check_eq(aController.input.textValue, ""); 1.28 + do_check_eq(aController.getFinalCompleteValueAt(0), "http://www.mozilla.com"); 1.29 + aController.input.forceComplete = true; 1.30 + aController.handleEnter(false); 1.31 + do_check_eq(aController.input.textValue, "http://www.mozilla.com"); 1.32 + }); 1.33 +}); 1.34 + 1.35 +function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) { 1.36 + let search = new AutoCompleteSearchBase( 1.37 + "search", 1.38 + new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ]) 1.39 + ); 1.40 + registerAutoCompleteSearch(search); 1.41 + 1.42 + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. 1.43 + getService(Ci.nsIAutoCompleteController); 1.44 + 1.45 + // Make an AutoCompleteInput that uses our searches and confirms results. 1.46 + let input = new AutoCompleteInput([ search.name ]); 1.47 + input.textValue = aSearchString; 1.48 + 1.49 + controller.input = input; 1.50 + controller.startSearch(aSearchString); 1.51 + 1.52 + input.onSearchComplete = function onSearchComplete() { 1.53 + aOnCompleteCallback(controller); 1.54 + 1.55 + // Clean up. 1.56 + unregisterAutoCompleteSearch(search); 1.57 + run_next_test(); 1.58 + }; 1.59 +}