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