toolkit/components/autocomplete/tests/unit/test_330578.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 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 var gResultListener = {
     8   _lastResult: null,
     9   _lastValue: "",
    10   _lastRemoveFromDb: false,
    12   onValueRemoved: function(aResult, aValue, aRemoveFromDb) {
    13     this._lastResult = aResult;
    14     this._lastValue = aValue;
    15     this._lastRemoveFromDb = aRemoveFromDb;
    16   }
    17 };
    20 // main
    21 function run_test() {
    22   var result = Cc["@mozilla.org/autocomplete/simple-result;1"].
    23                createInstance(Ci.nsIAutoCompleteSimpleResult);
    24   result.appendMatch("a", "");
    25   result.appendMatch("b", "");
    26   result.appendMatch("c", "");
    27   result.setListener(gResultListener);
    28   do_check_eq(result.matchCount, 3);
    29   result.removeValueAt(0, true);
    30   do_check_eq(result.matchCount, 2);
    31   do_check_eq(gResultListener._lastResult, result);
    32   do_check_eq(gResultListener._lastValue, "a");
    33   do_check_eq(gResultListener._lastRemoveFromDb, true);
    35   result.removeValueAt(0, false);
    36   do_check_eq(result.matchCount, 1);
    37   do_check_eq(gResultListener._lastValue, "b");
    38   do_check_eq(gResultListener._lastRemoveFromDb, false);
    40   // check that we don't get notified if the listener is unset
    41   result.setListener(null);
    42   result.removeValueAt(0, true); // "c"
    43   do_check_eq(result.matchCount, 0);
    44   do_check_eq(gResultListener._lastValue, "b");
    45 }

mercurial