| 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 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 Loading... |
| 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; |
| 145 Zone forked; | 146 Zone forked; |
| 146 int registerCallDelta = 0; | 147 int registerCallDelta = 0; |
| 147 bool callbackCalled = false; | 148 bool callbackCalled = false; |
| 148 Function callback = () { | 149 Function callback = () { |
| 149 expect(callbackCalled, false); | 150 expect(callbackCalled, false); |
| 150 callbackCalled = true; | 151 callbackCalled = true; |
| 151 expect(Zone.current, forked); | 152 expect(Zone.current, forked); |
| 152 return 42; | 153 return 42; |
| 153 }; | 154 }; |
| 154 forked = Zone.current.fork(specification: new ZoneSpecification( | 155 forked = Zone.current.fork(specification: new ZoneSpecification( |
| 155 registerCallback: (Zone self, ZoneDelegate parent, Zone origin, f()) { | 156 registerCallback: (Zone self, ZoneDelegate parent, Zone origin, f()) { |
| 156 if (!identical(f, callback)) return f; | 157 if (!identical(f, callback)) return f; |
| 157 registerCallDelta++; // Increment calls to register. | 158 registerCallDelta++; // Increment calls to register. |
| 158 expect(origin, forked); | 159 expect(origin, forked); |
| 159 expect(self, forked); | 160 expect(self, forked); |
| 160 return expectAsync0(() { registerCallDelta--; return f(); }); | 161 return expectAsync0(() { registerCallDelta--; return f(); }); |
| 161 } | 162 } |
| 162 )); | 163 )); |
| 163 Completer completer = new Completer(); | 164 Completer completer = new Completer(); |
| 164 Future timedOut; | 165 Future timedOut; |
| 165 forked.run(() { | 166 forked.run(() { |
| 166 timedOut = completer.future.timeout(const Duration(milliseconds: 5), | 167 timedOut = completer.future.timeout(const Duration(milliseconds: 5), |
| 167 onTimeout: callback); | 168 onTimeout: callback); |
| 168 }); | 169 }); |
| 169 timedOut.then(expectAsync1((v) { | 170 timedOut.then(expectAsync1((v) { |
| 170 expect(callbackCalled, true); | 171 expect(callbackCalled, true); |
| 171 expect(registerCallDelta, 0); | 172 expect(registerCallDelta, 0); |
| 172 expect(Zone.current, Zone.ROOT); | 173 expect(Zone.current, initialZone); |
| 173 expect(v, 42); | 174 expect(v, 42); |
| 174 })); | 175 })); |
| 175 }); | 176 }); |
| 176 | 177 |
| 177 test("timeoutNoFunction", () { | 178 test("timeoutNoFunction", () { |
| 178 Completer completer = new Completer(); | 179 Completer completer = new Completer(); |
| 179 Future timedOut = completer.future.timeout( | 180 Future timedOut = completer.future.timeout( |
| 180 const Duration(milliseconds: 5)); | 181 const Duration(milliseconds: 5)); |
| 181 timedOut.catchError(expectAsync2((e, s) { | 182 timedOut.catchError(expectAsync2((e, s) { |
| 182 expect(e, new isInstanceOf<TimeoutException>()); | 183 expect(e, new isInstanceOf<TimeoutException>()); |
| 183 expect(e.duration, const Duration(milliseconds: 5)); | 184 expect(e.duration, const Duration(milliseconds: 5)); |
| 184 expect(s, null); | 185 expect(s, null); |
| 185 })); | 186 })); |
| 186 }); | 187 }); |
| 187 } | 188 } |
| OLD | NEW |