Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | var gResultListener = { |
michael@0 | 8 | _lastResult: null, |
michael@0 | 9 | _lastValue: "", |
michael@0 | 10 | _lastRemoveFromDb: false, |
michael@0 | 11 | |
michael@0 | 12 | onValueRemoved: function(aResult, aValue, aRemoveFromDb) { |
michael@0 | 13 | this._lastResult = aResult; |
michael@0 | 14 | this._lastValue = aValue; |
michael@0 | 15 | this._lastRemoveFromDb = aRemoveFromDb; |
michael@0 | 16 | } |
michael@0 | 17 | }; |
michael@0 | 18 | |
michael@0 | 19 | |
michael@0 | 20 | // main |
michael@0 | 21 | function run_test() { |
michael@0 | 22 | var result = Cc["@mozilla.org/autocomplete/simple-result;1"]. |
michael@0 | 23 | createInstance(Ci.nsIAutoCompleteSimpleResult); |
michael@0 | 24 | result.appendMatch("a", ""); |
michael@0 | 25 | result.appendMatch("b", ""); |
michael@0 | 26 | result.appendMatch("c", ""); |
michael@0 | 27 | result.setListener(gResultListener); |
michael@0 | 28 | do_check_eq(result.matchCount, 3); |
michael@0 | 29 | result.removeValueAt(0, true); |
michael@0 | 30 | do_check_eq(result.matchCount, 2); |
michael@0 | 31 | do_check_eq(gResultListener._lastResult, result); |
michael@0 | 32 | do_check_eq(gResultListener._lastValue, "a"); |
michael@0 | 33 | do_check_eq(gResultListener._lastRemoveFromDb, true); |
michael@0 | 34 | |
michael@0 | 35 | result.removeValueAt(0, false); |
michael@0 | 36 | do_check_eq(result.matchCount, 1); |
michael@0 | 37 | do_check_eq(gResultListener._lastValue, "b"); |
michael@0 | 38 | do_check_eq(gResultListener._lastRemoveFromDb, false); |
michael@0 | 39 | |
michael@0 | 40 | // check that we don't get notified if the listener is unset |
michael@0 | 41 | result.setListener(null); |
michael@0 | 42 | result.removeValueAt(0, true); // "c" |
michael@0 | 43 | do_check_eq(result.matchCount, 0); |
michael@0 | 44 | do_check_eq(gResultListener._lastValue, "b"); |
michael@0 | 45 | } |