toolkit/components/autocomplete/tests/unit/test_hiddenResult.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function AutoCompleteResult(aValues) {
     5   this._values = aValues;
     6   this.defaultIndex = -1;
     7   this._typeAheadResult = false;
     8 }
     9 AutoCompleteResult.prototype = Object.create(AutoCompleteResultBase.prototype);
    11 function AutoCompleteTypeAheadResult(aValues) {
    12   this._values = aValues;
    13   this.defaultIndex = 0;
    14   this._typeAheadResult = true;
    15 }
    16 AutoCompleteTypeAheadResult.prototype = Object.create(AutoCompleteResultBase.prototype);
    19 /** 
    20  * Test AutoComplete with multiple AutoCompleteSearch sources, with one of them
    21  * being hidden from the popup, but can still do typeahead completion.
    22  */
    23 function run_test() {
    24   do_test_pending();
    26   var inputStr = "moz";
    28   // Type ahead result
    29   var searchTypeAhead = new AutoCompleteSearchBase("search1",
    30                                                    new AutoCompleteTypeAheadResult(["mozillaTest1"]));
    31   // Regular result
    32   var searchNormal = new AutoCompleteSearchBase("search2",
    33                                                 new AutoCompleteResult(["mozillaTest2"]));
    35   // Register searches so AutoCompleteController can find them
    36   registerAutoCompleteSearch(searchNormal);
    37   registerAutoCompleteSearch(searchTypeAhead);
    39   // Make an AutoCompleteInput that uses our searches
    40   // and confirms results on search complete.
    41   var input = new AutoCompleteInputBase([searchTypeAhead.name, searchNormal.name]);
    42   input.completeDefaultIndex = true;
    43   input.textValue = inputStr;
    45   // Caret must be at the end. Autofill doesn't happen unless you're typing
    46   // characters at the end.
    47   var strLen = inputStr.length;
    48   input.selectTextRange(strLen, strLen);
    49   do_check_eq(input.selectionStart, strLen);
    50   do_check_eq(input.selectionEnd, strLen);
    52   var controller = Cc["@mozilla.org/autocomplete/controller;1"].
    53                    getService(Ci.nsIAutoCompleteController);  
    55   controller.input = input;
    56   controller.startSearch(inputStr);
    58   input.onSearchComplete = function() {
    59     // Hidden results should still be able to do inline autocomplete
    60     do_check_eq(input.textValue, "mozillaTest1");
    62     // Now, let's fill the textbox with the first result of the popup.
    63     // The first search is marked as hidden, so we must always get the
    64     // second search.
    65     controller.handleEnter(true);
    66     do_check_eq(input.textValue, "mozillaTest2");
    68     // Only one item in the popup.
    69     do_check_eq(controller.matchCount, 1);
    71     // Unregister searches
    72     unregisterAutoCompleteSearch(searchNormal);
    73     unregisterAutoCompleteSearch(searchTypeAhead);
    74     do_test_finished();
    75   };
    76 }

mercurial