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

Side by Side Diff: tests/lib/async/future_timeout_test.dart

Issue 135013006: Reverting 32284 - unittest using zones - investigating breaks in html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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/unittest/test/unittest_protect_async_test.dart ('k') | no next file » | 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) 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 library future_timeout_test; 5 library future_timeout_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import '../../../pkg/unittest/lib/unittest.dart'; 8 import '../../../pkg/unittest/lib/unittest.dart';
9 9
10 main() { 10 main() {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const Duration(milliseconds: 5), onTimeout: () { 135 const Duration(milliseconds: 5), onTimeout: () {
136 result.completeError("EXN6"); 136 result.completeError("EXN6");
137 return result.future; 137 return result.future;
138 }); 138 });
139 timedOut.catchError(expectAsync2((e, s) { 139 timedOut.catchError(expectAsync2((e, s) {
140 expect(e, "EXN6"); 140 expect(e, "EXN6");
141 })); 141 }));
142 }); 142 });
143 143
144 test("timeoutZone", () { 144 test("timeoutZone", () {
145 var initialZone = Zone.current;
146 Zone forked; 145 Zone forked;
147 int registerCallDelta = 0; 146 int registerCallDelta = 0;
148 bool callbackCalled = false; 147 bool callbackCalled = false;
149 Function callback = () { 148 Function callback = () {
150 expect(callbackCalled, false); 149 expect(callbackCalled, false);
151 callbackCalled = true; 150 callbackCalled = true;
152 expect(Zone.current, forked); 151 expect(Zone.current, forked);
153 return 42; 152 return 42;
154 }; 153 };
155 forked = Zone.current.fork(specification: new ZoneSpecification( 154 forked = Zone.current.fork(specification: new ZoneSpecification(
156 registerCallback: (Zone self, ZoneDelegate parent, Zone origin, f()) { 155 registerCallback: (Zone self, ZoneDelegate parent, Zone origin, f()) {
157 if (!identical(f, callback)) return f; 156 if (!identical(f, callback)) return f;
158 registerCallDelta++; // Increment calls to register. 157 registerCallDelta++; // Increment calls to register.
159 expect(origin, forked); 158 expect(origin, forked);
160 expect(self, forked); 159 expect(self, forked);
161 return expectAsync0(() { registerCallDelta--; return f(); }); 160 return expectAsync0(() { registerCallDelta--; return f(); });
162 } 161 }
163 )); 162 ));
164 Completer completer = new Completer(); 163 Completer completer = new Completer();
165 Future timedOut; 164 Future timedOut;
166 forked.run(() { 165 forked.run(() {
167 timedOut = completer.future.timeout(const Duration(milliseconds: 5), 166 timedOut = completer.future.timeout(const Duration(milliseconds: 5),
168 onTimeout: callback); 167 onTimeout: callback);
169 }); 168 });
170 timedOut.then(expectAsync1((v) { 169 timedOut.then(expectAsync1((v) {
171 expect(callbackCalled, true); 170 expect(callbackCalled, true);
172 expect(registerCallDelta, 0); 171 expect(registerCallDelta, 0);
173 expect(Zone.current, initialZone); 172 expect(Zone.current, Zone.ROOT);
174 expect(v, 42); 173 expect(v, 42);
175 })); 174 }));
176 }); 175 });
177 176
178 test("timeoutNoFunction", () { 177 test("timeoutNoFunction", () {
179 Completer completer = new Completer(); 178 Completer completer = new Completer();
180 Future timedOut = completer.future.timeout( 179 Future timedOut = completer.future.timeout(
181 const Duration(milliseconds: 5)); 180 const Duration(milliseconds: 5));
182 timedOut.catchError(expectAsync2((e, s) { 181 timedOut.catchError(expectAsync2((e, s) {
183 expect(e, new isInstanceOf<TimeoutException>()); 182 expect(e, new isInstanceOf<TimeoutException>());
184 expect(e.duration, const Duration(milliseconds: 5)); 183 expect(e.duration, const Duration(milliseconds: 5));
185 expect(s, null); 184 expect(s, null);
186 })); 185 }));
187 }); 186 });
188 } 187 }
OLDNEW
« no previous file with comments | « pkg/unittest/test/unittest_protect_async_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698