toolkit/components/autocomplete/tests/unit/test_finalDefaultCompleteValue.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   this.defaultIndex = 0;
     9 }
    10 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
    12 function AutoCompleteInput(aSearches) {
    13   this.searches = aSearches;
    14   this.popup.selectedIndex = -1;
    15   this.completeDefaultIndex = true;
    16 }
    17 AutoCompleteInput.prototype = Object.create(AutoCompleteInputBase.prototype);
    19 function run_test() {
    20   run_next_test();
    21 }
    23 add_test(function test_keyNavigation() {
    24   doSearch("moz", "mozilla.com", "http://www.mozilla.com", function(aController) {
    25     do_check_eq(aController.input.textValue, "mozilla.com");
    26     aController.handleKeyNavigation(Ci.nsIDOMKeyEvent.DOM_VK_RIGHT);
    27     do_check_eq(aController.input.textValue, "mozilla.com");
    28   });
    29 });
    31 add_test(function test_handleEnter() {
    32   doSearch("moz", "mozilla.com", "http://www.mozilla.com", function(aController) {
    33     do_check_eq(aController.input.textValue, "mozilla.com");
    34     aController.handleEnter(false);
    35     do_check_eq(aController.input.textValue, "http://www.mozilla.com");
    36   });
    37 });
    39 function doSearch(aSearchString, aResultValue, aFinalCompleteValue, aOnCompleteCallback) {
    40   let search = new AutoCompleteSearchBase(
    41     "search",
    42     new AutoCompleteResult([ aResultValue ], [ aFinalCompleteValue ])
    43   );
    44   registerAutoCompleteSearch(search);
    46   let controller = Cc["@mozilla.org/autocomplete/controller;1"].
    47                    getService(Ci.nsIAutoCompleteController);  
    49   // Make an AutoCompleteInput that uses our searches and confirms results.
    50   let input = new AutoCompleteInput([ search.name ]);
    51   input.textValue = aSearchString;
    53   // Caret must be at the end for autofill to happen.
    54   let strLen = aSearchString.length;
    55   input.selectTextRange(strLen, strLen);
    56   controller.input = input;
    57   controller.startSearch(aSearchString);
    59   input.onSearchComplete = function onSearchComplete() {
    60     aOnCompleteCallback(controller);
    62     // Clean up.
    63     unregisterAutoCompleteSearch(search);
    64     run_next_test();
    65   };
    66 }

mercurial