| OLD | NEW |
| 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:async/stream_zip.dart"; | |
| 7 import "package:unittest/unittest.dart"; | 6 import "package:unittest/unittest.dart"; |
| 8 | 7 |
| 9 // Test that stream listener callbacks all happen in the zone where the | 8 // Test that stream listener callbacks all happen in the zone where the |
| 10 // listen occurred. | 9 // listen occurred. |
| 11 | 10 |
| 12 main() { | 11 main() { |
| 13 StreamController controller; | 12 StreamController controller; |
| 14 controller = new StreamController(); | 13 controller = new StreamController(); |
| 15 testStream("singlesub-async", controller, controller.stream); | 14 testStream("singlesub-async", controller, controller.stream); |
| 16 controller = new StreamController.broadcast(); | 15 controller = new StreamController.broadcast(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 testStream("asbroadcast-sync", controller, | 26 testStream("asbroadcast-sync", controller, |
| 28 controller.stream.asBroadcastStream()); | 27 controller.stream.asBroadcastStream()); |
| 29 } | 28 } |
| 30 | 29 |
| 31 void testStream(String name, StreamController controller, Stream stream) { | 30 void testStream(String name, StreamController controller, Stream stream) { |
| 32 test(name, () { | 31 test(name, () { |
| 33 Zone outer = Zone.current; | 32 Zone outer = Zone.current; |
| 34 runZoned(() { | 33 runZoned(() { |
| 35 Zone newZone1 = Zone.current; | 34 Zone newZone1 = Zone.current; |
| 36 StreamSubscription sub; | 35 StreamSubscription sub; |
| 37 sub = stream.listen(expectAsync1((v) { | 36 sub = stream.listen(expectAsync((v) { |
| 38 expect(v, 42); | 37 expect(v, 42); |
| 39 expect(Zone.current, newZone1); | 38 expect(Zone.current, newZone1); |
| 40 outer.run(() { | 39 outer.run(() { |
| 41 sub.onData(expectAsync1((v) { | 40 sub.onData(expectAsync((v) { |
| 42 expect(v, 37); | 41 expect(v, 37); |
| 43 expect(Zone.current, newZone1); | 42 expect(Zone.current, newZone1); |
| 44 runZoned(() { | 43 runZoned(() { |
| 45 Zone newZone2 = Zone.current; | 44 Zone newZone2 = Zone.current; |
| 46 sub.onData(expectAsync1((v) { | 45 sub.onData(expectAsync((v) { |
| 47 expect(v, 87); | 46 expect(v, 87); |
| 48 expect(Zone.current, newZone1); | 47 expect(Zone.current, newZone1); |
| 49 })); | 48 })); |
| 50 }); | 49 }); |
| 51 controller.add(87); | 50 controller.add(87); |
| 52 })); | 51 })); |
| 53 }); | 52 }); |
| 54 controller.add(37); | 53 controller.add(37); |
| 55 })); | 54 })); |
| 56 }); | 55 }); |
| 57 controller.add(42); | 56 controller.add(42); |
| 58 }); | 57 }); |
| 59 } | 58 } |
| OLD | NEW |