toolkit/components/autocomplete/tests/unit/test_finalCompleteValue.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function AutoCompleteResult(aValues, aFinalCompleteValues) {
     6   this._values = aValues;
     7   this._finalCompleteValues = aFinalCompleteValues;
     8 }
     9 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
    11 function AutoCompleteInput(aSearches) {
    12   this.searches = aSearches;
    13   this.popup.selectedIndex = 0;
    14 }
    15 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
    17 function run_test() {
    18   run_next_test();
    19 }
    21 add_test(function test_handleEnter() {
    22   doSearch("moz", "mozilla.com", "http://www.mozilla.com", function(aController) {
    23     do_check_eq(aController.input.textValue, "moz");
    24     do_check_eq(aController.getFinalCompleteValueAt(0), "http://www.mozilla.com");
    25     aController.handleEnter(false);
    26     do_check_eq(aController.input.textValue, "http://www.mozilla.com");
    27   });
    28 });
    30 function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) {
    31   let search = new AutoCompleteSearchBase(
    32     "search",
    33     new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ])
    34   );
    35   registerAutoCompleteSearch(search);
    37   let controller = Cc["@mozilla.org/autocomplete/controller;1"].
    38                    getService(Ci.nsIAutoCompleteController);  
    40   // Make an AutoCompleteInput that uses our searches and confirms results.
    41   let input = new AutoCompleteInput([ search.name ]);
    42   input.textValue = aSearchString;
    44   controller.input = input;
    45   controller.startSearch(aSearchString);
    47   input.onSearchComplete = function onSearchComplete() {
    48     aOnCompleteCallback(controller);
    50     // Clean up.
    51     unregisterAutoCompleteSearch(search);
    52     run_next_test();
    53   };
    54 }

mercurial