OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 testAbstractObservable() { | |
6 group('addChangeListener()', () { | |
7 test('adding the same listener twice returns false the second time', () { | |
8 final target = new AbstractObservable(); | |
9 final listener = (e) { }; | |
10 | |
11 expect(target.addChangeListener(listener)).isTrue(); | |
12 expect(target.addChangeListener(listener)).isFalse(); | |
13 }); | |
14 | |
15 test('modifies listeners list', () { | |
16 // check that add/remove works, see contents of listeners too | |
17 final target = new AbstractObservable(); | |
18 final l1 = (e) { }; | |
19 final l2 = (e) { }; | |
20 final l3 = (e) { }; | |
21 final l4 = (e) { }; | |
22 | |
23 expect(target.listeners).equalsCollection([]); | |
24 | |
25 target.addChangeListener(l1); | |
26 expect(target.listeners).equalsCollection([l1]); | |
27 | |
28 target.addChangeListener(l2); | |
29 expect(target.listeners).equalsCollection([l1, l2]); | |
30 | |
31 target.addChangeListener(l3); | |
32 target.addChangeListener(l4); | |
33 expect(target.listeners).equalsCollection([l1, l2, l3, l4]); | |
34 | |
35 target.removeChangeListener(l4); | |
36 expect(target.listeners).equalsCollection([l1, l2, l3]); | |
37 | |
38 target.removeChangeListener(l2); | |
39 expect(target.listeners).equalsCollection([l1, l3]); | |
40 | |
41 target.removeChangeListener(l1); | |
42 expect(target.listeners).equalsCollection([l3]); | |
43 | |
44 target.removeChangeListener(l3); | |
45 expect(target.listeners).equalsCollection([]); | |
46 }); | |
47 }); | |
48 | |
49 test('fires immediately if no batch', () { | |
50 // If no batch is created, a summary should be automatically created and | |
51 // fired on each property change. | |
52 final target = new AbstractObservable(); | |
53 EventSummary res = null; | |
54 target.addChangeListener((summary) { | |
55 expect(res).isNull(); | |
56 res = summary; | |
57 expect(res).isNotNull(); | |
58 }); | |
59 | |
60 target.recordPropertyUpdate('pM', 10, 11); | |
61 | |
62 expect(res).isNotNull(); | |
63 expect(res.events.length).equals(1); | |
64 validateUpdate(res.events[0], target, 'pM', null, 10, 11); | |
65 res = null; | |
66 | |
67 target.recordPropertyUpdate('pL', '11', '13'); | |
68 | |
69 expect(res).isNotNull(); | |
70 expect(res.events.length).equals(1); | |
71 validateUpdate(res.events[0], target, 'pL', null, '11', '13'); | |
72 }); | |
73 } | |
OLD | NEW |