Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Side by Side Diff: pkg/mdv_observe/test/observe_test.dart

Issue 14908005: "Reverting 22561" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/mdv_observe/test/observable_map_test.dart ('k') | pkg/mdv_observe/test/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import 'dart:async';
6 import 'package:mdv_observe/mdv_observe.dart';
7 import 'package:unittest/unittest.dart';
8 import 'utils.dart';
9
10 main() {
11 // Note: to test the basic Observable system, we use ObservableBox due to its
12 // simplicity.
13
14 const _VALUE = const Symbol('value');
15
16 group('ObservableBox', () {
17 test('no observers', () {
18 var t = new ObservableBox<int>(123);
19 expect(t.value, 123);
20 t.value = 42;
21 expect(t.value, 42);
22 expect(t.hasObservers, false);
23 });
24
25 test('listen adds an observer', () {
26 var t = new ObservableBox<int>(123);
27 expect(t.hasObservers, false);
28
29 t.changes.listen((n) {});
30 expect(t.hasObservers, true);
31 });
32
33 test('changes delived async', () {
34 var t = new ObservableBox<int>(123);
35 int called = 0;
36
37 t.changes.listen(expectAsync1((records) {
38 called++;
39 expectChanges(records, [_record(_VALUE), _record(_VALUE)]);
40 }));
41 t.value = 41;
42 t.value = 42;
43 expect(called, 0);
44 });
45
46 test('cause changes in handler', () {
47 var t = new ObservableBox<int>(123);
48 int called = 0;
49
50 t.changes.listen(expectAsync1((records) {
51 called++;
52 expectChanges(records, [_record(_VALUE)]);
53 if (called == 1) {
54 // Cause another change
55 t.value = 777;
56 }
57 }, count: 2));
58
59 t.value = 42;
60 });
61
62 test('multiple observers', () {
63 var t = new ObservableBox<int>(123);
64
65 verifyRecords(records) {
66 expectChanges(records, [_record(_VALUE), _record(_VALUE)]);
67 };
68
69 t.changes.listen(expectAsync1(verifyRecords));
70 t.changes.listen(expectAsync1(verifyRecords));
71
72 t.value = 41;
73 t.value = 42;
74 });
75
76 test('deliverChangeRecords', () {
77 var t = new ObservableBox<int>(123);
78 var records = [];
79 t.changes.listen((r) { records.addAll(r); });
80 t.value = 41;
81 t.value = 42;
82 expectChanges(records, [], reason: 'changes delived async');
83
84 deliverChangeRecords();
85 expectChanges(records,
86 [_record(_VALUE), _record(_VALUE)]);
87 records.clear();
88
89 t.value = 777;
90 expectChanges(records, [], reason: 'changes delived async');
91
92 deliverChangeRecords();
93 expectChanges(records, [_record(_VALUE)]);
94
95 // Has no effect if there are no changes
96 deliverChangeRecords();
97 expectChanges(records, [_record(_VALUE)]);
98 });
99
100 test('cancel listening', () {
101 var t = new ObservableBox<int>(123);
102 var sub;
103 sub = t.changes.listen(expectAsync1((records) {
104 expectChanges(records, [_record(_VALUE)]);
105 sub.cancel();
106 t.value = 777;
107 }));
108 t.value = 42;
109 });
110
111 test('cancel and reobserve', () {
112 var t = new ObservableBox<int>(123);
113 var sub;
114 sub = t.changes.listen(expectAsync1((records) {
115 expectChanges(records, [_record(_VALUE)]);
116 sub.cancel();
117
118 runAsync(expectAsync0(() {
119 sub = t.changes.listen(expectAsync1((records) {
120 expectChanges(records, [_record(_VALUE)]);
121 }));
122 t.value = 777;
123 }));
124 }));
125 t.value = 42;
126 });
127 });
128 }
129
130 _record(key) => new PropertyChangeRecord(key);
OLDNEW
« no previous file with comments | « pkg/mdv_observe/test/observable_map_test.dart ('k') | pkg/mdv_observe/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698