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