1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/autocomplete/tests/unit/test_finalCompleteValue.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 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 +} 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 = 0; 1.17 +} 1.18 +AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype); 1.19 + 1.20 +function run_test() { 1.21 + run_next_test(); 1.22 +} 1.23 + 1.24 +add_test(function test_handleEnter() { 1.25 + doSearch("moz", "mozilla.com", "http://www.mozilla.com", function(aController) { 1.26 + do_check_eq(aController.input.textValue, "moz"); 1.27 + do_check_eq(aController.getFinalCompleteValueAt(0), "http://www.mozilla.com"); 1.28 + aController.handleEnter(false); 1.29 + do_check_eq(aController.input.textValue, "http://www.mozilla.com"); 1.30 + }); 1.31 +}); 1.32 + 1.33 +function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) { 1.34 + let search = new AutoCompleteSearchBase( 1.35 + "search", 1.36 + new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ]) 1.37 + ); 1.38 + registerAutoCompleteSearch(search); 1.39 + 1.40 + let controller = Cc["@mozilla.org/autocomplete/controller;1"]. 1.41 + getService(Ci.nsIAutoCompleteController); 1.42 + 1.43 + // Make an AutoCompleteInput that uses our searches and confirms results. 1.44 + let input = new AutoCompleteInput([ search.name ]); 1.45 + input.textValue = aSearchString; 1.46 + 1.47 + controller.input = input; 1.48 + controller.startSearch(aSearchString); 1.49 + 1.50 + input.onSearchComplete = function onSearchComplete() { 1.51 + aOnCompleteCallback(controller); 1.52 + 1.53 + // Clean up. 1.54 + unregisterAutoCompleteSearch(search); 1.55 + run_next_test(); 1.56 + }; 1.57 +}