1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/autocomplete/tests/unit/test_330578.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +var gResultListener = { 1.11 + _lastResult: null, 1.12 + _lastValue: "", 1.13 + _lastRemoveFromDb: false, 1.14 + 1.15 + onValueRemoved: function(aResult, aValue, aRemoveFromDb) { 1.16 + this._lastResult = aResult; 1.17 + this._lastValue = aValue; 1.18 + this._lastRemoveFromDb = aRemoveFromDb; 1.19 + } 1.20 +}; 1.21 + 1.22 + 1.23 +// main 1.24 +function run_test() { 1.25 + var result = Cc["@mozilla.org/autocomplete/simple-result;1"]. 1.26 + createInstance(Ci.nsIAutoCompleteSimpleResult); 1.27 + result.appendMatch("a", ""); 1.28 + result.appendMatch("b", ""); 1.29 + result.appendMatch("c", ""); 1.30 + result.setListener(gResultListener); 1.31 + do_check_eq(result.matchCount, 3); 1.32 + result.removeValueAt(0, true); 1.33 + do_check_eq(result.matchCount, 2); 1.34 + do_check_eq(gResultListener._lastResult, result); 1.35 + do_check_eq(gResultListener._lastValue, "a"); 1.36 + do_check_eq(gResultListener._lastRemoveFromDb, true); 1.37 + 1.38 + result.removeValueAt(0, false); 1.39 + do_check_eq(result.matchCount, 1); 1.40 + do_check_eq(gResultListener._lastValue, "b"); 1.41 + do_check_eq(gResultListener._lastRemoveFromDb, false); 1.42 + 1.43 + // check that we don't get notified if the listener is unset 1.44 + result.setListener(null); 1.45 + result.removeValueAt(0, true); // "c" 1.46 + do_check_eq(result.matchCount, 0); 1.47 + do_check_eq(gResultListener._lastValue, "b"); 1.48 +}