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

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

Issue 201483002: Cleanup for pkg/observe and pkg/polymer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixed other pubspec Created 6 years, 9 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/observe/pubspec.yaml ('k') | pkg/observe/test/path_observer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 import 'dart:async'; 5 import 'dart:async';
6 import 'package:logging/logging.dart'; 6 import 'package:logging/logging.dart';
7 import 'package:observe/observe.dart'; 7 import 'package:observe/observe.dart';
8 import 'package:observe/src/dirty_check.dart' as dirty_check; 8 import 'package:observe/src/dirty_check.dart' as dirty_check;
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'observe_test_utils.dart'; 10 import 'observe_test_utils.dart';
(...skipping 25 matching lines...) Expand all
36 }); 36 });
37 37
38 tearDown(() { 38 tearDown(() {
39 subscription.cancel(); 39 subscription.cancel();
40 }); 40 });
41 41
42 test('logs debug information', () { 42 test('logs debug information', () {
43 var maxNumIterations = dirty_check.MAX_DIRTY_CHECK_CYCLES; 43 var maxNumIterations = dirty_check.MAX_DIRTY_CHECK_CYCLES;
44 44
45 var x = new WatcherModel(0); 45 var x = new WatcherModel(0);
46 var sub = x.changes.listen(expectAsync1((_) { x.value++; }, 46 var sub = x.changes.listen(expectAsync((_) { x.value++; },
47 count: maxNumIterations)); 47 count: maxNumIterations));
48 x.value = 1; 48 x.value = 1;
49 Observable.dirtyCheck(); 49 Observable.dirtyCheck();
50 expect(x.value, maxNumIterations + 1); 50 expect(x.value, maxNumIterations + 1);
51 expect(messages.length, 2); 51 expect(messages.length, 2);
52 52
53 expect(messages[0], contains('Possible loop')); 53 expect(messages[0], contains('Possible loop'));
54 expect(messages[1], contains('index 0')); 54 expect(messages[1], contains('index 0'));
55 expect(messages[1], contains('object: $x')); 55 expect(messages[1], contains('object: $x'));
56 56
(...skipping 18 matching lines...) Expand all
75 75
76 tearDown(() { 76 tearDown(() {
77 for (var sub in subs) sub.cancel(); 77 for (var sub in subs) sub.cancel();
78 return new Future(() { 78 return new Future(() {
79 expect(dirty_check.allObservablesCount, initialObservers, 79 expect(dirty_check.allObservablesCount, initialObservers,
80 reason: 'Observable object leaked'); 80 reason: 'Observable object leaked');
81 }); 81 });
82 }); 82 });
83 83
84 test('handle future result', () { 84 test('handle future result', () {
85 var callback = expectAsync0((){}); 85 var callback = expectAsync((){});
86 return new Future(callback); 86 return new Future(callback);
87 }); 87 });
88 88
89 test('no observers', () { 89 test('no observers', () {
90 var t = createModel(123); 90 var t = createModel(123);
91 expect(t.value, 123); 91 expect(t.value, 123);
92 t.value = 42; 92 t.value = 42;
93 expect(t.value, 42); 93 expect(t.value, 42);
94 expect(t.hasObservers, false); 94 expect(t.hasObservers, false);
95 }); 95 });
96 96
97 test('listen adds an observer', () { 97 test('listen adds an observer', () {
98 var t = createModel(123); 98 var t = createModel(123);
99 expect(t.hasObservers, false); 99 expect(t.hasObservers, false);
100 100
101 subs.add(t.changes.listen((n) {})); 101 subs.add(t.changes.listen((n) {}));
102 expect(t.hasObservers, true); 102 expect(t.hasObservers, true);
103 }); 103 });
104 104
105 test('changes delived async', () { 105 test('changes delived async', () {
106 var t = createModel(123); 106 var t = createModel(123);
107 int called = 0; 107 int called = 0;
108 108
109 subs.add(t.changes.listen(expectAsync1((records) { 109 subs.add(t.changes.listen(expectAsync((records) {
110 called++; 110 called++;
111 expectPropertyChanges(records, watch ? 1 : 2); 111 expectPropertyChanges(records, watch ? 1 : 2);
112 }))); 112 })));
113 113
114 t.value = 41; 114 t.value = 41;
115 t.value = 42; 115 t.value = 42;
116 expect(called, 0); 116 expect(called, 0);
117 }); 117 });
118 118
119 test('cause changes in handler', () { 119 test('cause changes in handler', () {
120 var t = createModel(123); 120 var t = createModel(123);
121 int called = 0; 121 int called = 0;
122 122
123 subs.add(t.changes.listen(expectAsync1((records) { 123 subs.add(t.changes.listen(expectAsync((records) {
124 called++; 124 called++;
125 expectPropertyChanges(records, 1); 125 expectPropertyChanges(records, 1);
126 if (called == 1) { 126 if (called == 1) {
127 // Cause another change 127 // Cause another change
128 t.value = 777; 128 t.value = 777;
129 } 129 }
130 }, count: 2))); 130 }, count: 2)));
131 131
132 t.value = 42; 132 t.value = 42;
133 }); 133 });
134 134
135 test('multiple observers', () { 135 test('multiple observers', () {
136 var t = createModel(123); 136 var t = createModel(123);
137 137
138 verifyRecords(records) { 138 verifyRecords(records) {
139 expectPropertyChanges(records, watch ? 1 : 2); 139 expectPropertyChanges(records, watch ? 1 : 2);
140 }; 140 };
141 141
142 subs.add(t.changes.listen(expectAsync1(verifyRecords))); 142 subs.add(t.changes.listen(expectAsync(verifyRecords)));
143 subs.add(t.changes.listen(expectAsync1(verifyRecords))); 143 subs.add(t.changes.listen(expectAsync(verifyRecords)));
144 144
145 t.value = 41; 145 t.value = 41;
146 t.value = 42; 146 t.value = 42;
147 }); 147 });
148 148
149 test('async processing model', () { 149 test('async processing model', () {
150 var t = createModel(123); 150 var t = createModel(123);
151 var records = []; 151 var records = [];
152 subs.add(t.changes.listen((r) { records.addAll(r); })); 152 subs.add(t.changes.listen((r) { records.addAll(r); }));
153 t.value = 41; 153 t.value = 41;
(...skipping 12 matching lines...) Expand all
166 166
167 // Has no effect if there are no changes 167 // Has no effect if there are no changes
168 Observable.dirtyCheck(); 168 Observable.dirtyCheck();
169 expectPropertyChanges(records, 1); 169 expectPropertyChanges(records, 1);
170 }); 170 });
171 }); 171 });
172 172
173 test('cancel listening', () { 173 test('cancel listening', () {
174 var t = createModel(123); 174 var t = createModel(123);
175 var sub; 175 var sub;
176 sub = t.changes.listen(expectAsync1((records) { 176 sub = t.changes.listen(expectAsync((records) {
177 expectPropertyChanges(records, 1); 177 expectPropertyChanges(records, 1);
178 sub.cancel(); 178 sub.cancel();
179 t.value = 777; 179 t.value = 777;
180 scheduleMicrotask(Observable.dirtyCheck); 180 scheduleMicrotask(Observable.dirtyCheck);
181 })); 181 }));
182 t.value = 42; 182 t.value = 42;
183 }); 183 });
184 184
185 test('cancel and reobserve', () { 185 test('cancel and reobserve', () {
186 var t = createModel(123); 186 var t = createModel(123);
187 var sub; 187 var sub;
188 sub = t.changes.listen(expectAsync1((records) { 188 sub = t.changes.listen(expectAsync((records) {
189 expectPropertyChanges(records, 1); 189 expectPropertyChanges(records, 1);
190 sub.cancel(); 190 sub.cancel();
191 191
192 scheduleMicrotask(expectAsync0(() { 192 scheduleMicrotask(expectAsync(() {
193 subs.add(t.changes.listen(expectAsync1((records) { 193 subs.add(t.changes.listen(expectAsync((records) {
194 expectPropertyChanges(records, 1); 194 expectPropertyChanges(records, 1);
195 }))); 195 })));
196 t.value = 777; 196 t.value = 777;
197 scheduleMicrotask(Observable.dirtyCheck); 197 scheduleMicrotask(Observable.dirtyCheck);
198 })); 198 }));
199 })); 199 }));
200 t.value = 42; 200 t.value = 42;
201 }); 201 });
202 202
203 test('cannot modify changes list', () { 203 test('cannot modify changes list', () {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 @observable T value; 262 @observable T value;
263 263
264 WatcherModel([T initialValue]) : value = initialValue; 264 WatcherModel([T initialValue]) : value = initialValue;
265 265
266 String toString() => '#<$runtimeType value: $value>'; 266 String toString() => '#<$runtimeType value: $value>';
267 } 267 }
268 268
269 class ModelSubclass<T> extends WatcherModel<T> { 269 class ModelSubclass<T> extends WatcherModel<T> {
270 ModelSubclass([T initialValue]) : super(initialValue); 270 ModelSubclass([T initialValue]) : super(initialValue);
271 } 271 }
OLDNEW
« no previous file with comments | « pkg/observe/pubspec.yaml ('k') | pkg/observe/test/path_observer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698