|
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/. */ |
|
6 |
|
7 var gResultListener = { |
|
8 _lastResult: null, |
|
9 _lastValue: "", |
|
10 _lastRemoveFromDb: false, |
|
11 |
|
12 onValueRemoved: function(aResult, aValue, aRemoveFromDb) { |
|
13 this._lastResult = aResult; |
|
14 this._lastValue = aValue; |
|
15 this._lastRemoveFromDb = aRemoveFromDb; |
|
16 } |
|
17 }; |
|
18 |
|
19 |
|
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); |
|
34 |
|
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); |
|
39 |
|
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 } |