| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 asyncStart(); | 10 asyncStart(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class SomeError implements Error { | 25 class SomeError implements Error { |
| 26 final int id; | 26 final int id; |
| 27 const SomeError(this.id); | 27 const SomeError(this.id); |
| 28 StackTrace get stackTrace => stack2; | 28 StackTrace get stackTrace => stack2; |
| 29 String toString() => "SomeError($id)"; | 29 String toString() => "SomeError($id)"; |
| 30 } | 30 } |
| 31 | 31 |
| 32 const error1 = const SomeError(1); | 32 const error1 = const SomeError(1); |
| 33 const error2 = const SomeError(2); | 33 const error2 = const SomeError(2); |
| 34 | 34 |
| 35 void expectError(e, s) { | 35 Null expectError(e, s) { |
| 36 // Remember one asyncStart per use of this callback. | 36 // Remember one asyncStart per use of this callback. |
| 37 Expect.identical(error1, e); | 37 Expect.identical(error1, e); |
| 38 Expect.identical(stack1, s); | 38 Expect.identical(stack1, s); |
| 39 asyncEnd(); | 39 asyncEnd(); |
| 40 return null; |
| 40 } | 41 } |
| 41 | 42 |
| 42 void expectErrorOnly(e, s) { | 43 Null expectErrorOnly(e, s) { |
| 43 // Remember one asyncStart per use of this callback. | 44 // Remember one asyncStart per use of this callback. |
| 44 Expect.identical(error1, e); | 45 Expect.identical(error1, e); |
| 45 asyncEnd(); | 46 asyncEnd(); |
| 47 return null; |
| 46 } | 48 } |
| 47 | 49 |
| 48 AsyncError replace(self, parent, zone, e, s) { | 50 AsyncError replace(self, parent, zone, e, s) { |
| 49 if (e == "ignore") return null; // For testing handleError throwing. | 51 if (e == "ignore") return null; // For testing handleError throwing. |
| 50 Expect.identical(error1, e); // Ensure replacement only called once | 52 Expect.identical(error1, e); // Ensure replacement only called once |
| 51 return new AsyncError(error2, stack2); | 53 return new AsyncError(error2, stack2); |
| 52 } | 54 } |
| 53 | 55 |
| 54 var replaceZoneSpec = new ZoneSpecification(errorCallback: replace); | 56 var replaceZoneSpec = new ZoneSpecification(errorCallback: replace); |
| 55 | 57 |
| 56 // Expectation after replacing. | 58 // Expectation after replacing. |
| 57 void expectReplaced(e, s) { | 59 Null expectReplaced(e, s) { |
| 58 Expect.identical(error2, e); | 60 Expect.identical(error2, e); |
| 59 Expect.identical(stack2, s); | 61 Expect.identical(stack2, s); |
| 60 asyncEnd(); | 62 asyncEnd(); |
| 63 return null; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void testProgrammaticErrors(expectError) { | 66 void testProgrammaticErrors(expectError) { |
| 64 { | 67 { |
| 65 asyncStart(); | 68 asyncStart(); |
| 66 Completer c = new Completer(); | 69 Completer c = new Completer(); |
| 67 c.future.catchError(expectError); | 70 c.future.catchError(expectError); |
| 68 c.completeError(error1, stack1); | 71 c.completeError(error1, stack1); |
| 69 } | 72 } |
| 70 | 73 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 runZoned(testReplaced, zoneSpecification: replaceZoneSpec); | 335 runZoned(testReplaced, zoneSpecification: replaceZoneSpec); |
| 333 }, zoneSpecification: replaceZoneSpec); | 336 }, zoneSpecification: replaceZoneSpec); |
| 334 | 337 |
| 335 // Use delegation to parent which replaces. | 338 // Use delegation to parent which replaces. |
| 336 runZoned(() { | 339 runZoned(() { |
| 337 runZoned(testReplaced, | 340 runZoned(testReplaced, |
| 338 zoneSpecification: new ZoneSpecification( | 341 zoneSpecification: new ZoneSpecification( |
| 339 errorCallback: (s, p, z, e, t) => p.errorCallback(z, e, t))); | 342 errorCallback: (s, p, z, e, t) => p.errorCallback(z, e, t))); |
| 340 }, zoneSpecification: replaceZoneSpec); | 343 }, zoneSpecification: replaceZoneSpec); |
| 341 } | 344 } |
| OLD | NEW |