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 // Test the event/callback protocol of the stream implementations. |
| 6 // Uses a non-zero timer so it fails on d8. |
| 7 |
| 8 library stream_state_nonzero_timer_test; |
| 9 |
| 10 import "dart:async"; |
| 11 import "../../../pkg/unittest/lib/unittest.dart"; |
| 12 import "stream_state_helper.dart"; |
| 13 |
| 14 const ms5 = const Duration(milliseconds: 5); |
| 15 |
| 16 main() { |
| 17 mainTest(false); |
| 18 mainTest(true); |
| 19 } |
| 20 |
| 21 mainTest(bool broadcast) { |
| 22 var p = broadcast ? "BC" : "SC"; |
| 23 |
| 24 test("$p-sub-data/pause/resume/pause/resume-done", () { |
| 25 var t = new StreamProtocolTest(broadcast); |
| 26 t..expectSubscription(true, false) |
| 27 ..expectData(42, () { |
| 28 t.pause(); |
| 29 }) |
| 30 ..expectPause(true, () { t.resume(); }) |
| 31 ..expectPause(false, () { t.pause(); }) |
| 32 ..expectPause(true, () { t.resume(); }) |
| 33 ..expectPause(false, () { t.close(); }) |
| 34 ..expectDone() |
| 35 ..expectSubscription(false, false); |
| 36 t..subscribe()..add(42); |
| 37 }); |
| 38 |
| 39 test("$p-sub-data/pause-done", () { |
| 40 var t = new StreamProtocolTest(broadcast); |
| 41 t..expectSubscription(true, false) |
| 42 ..expectData(42, () { |
| 43 t.pause(new Future.delayed(ms5, () => null)); |
| 44 }) |
| 45 ..expectPause(true) |
| 46 ..expectDone() |
| 47 ..expectSubscription(false, false); |
| 48 // We are calling "close" while the controller is actually paused, |
| 49 // and it will stay paused until the pending events are sent. |
| 50 t..subscribe()..add(42)..close(); |
| 51 }); |
| 52 |
| 53 test("$p-sub-data/pause-resume/done", () { |
| 54 var t = new StreamProtocolTest(broadcast); |
| 55 t..expectSubscription(true, false) |
| 56 ..expectData(42, () { |
| 57 t.pause(new Future.delayed(ms5, () => null)); |
| 58 }) |
| 59 ..expectPause(true) |
| 60 ..expectPause(false, () { t.close(); }) |
| 61 ..expectDone() |
| 62 ..expectSubscription(false, false); |
| 63 t..subscribe()..add(42); |
| 64 }); |
| 65 |
| 66 test("$p-sub-data/data+pause-data-resume-done", () { |
| 67 var t = new StreamProtocolTest(broadcast); |
| 68 t..expectSubscription(true, false) |
| 69 ..expectData(42, () { |
| 70 t.add(43); |
| 71 t.pause(new Future.delayed(ms5, () => null)); |
| 72 // Should now be paused until the future finishes. |
| 73 // After that, the controller stays paused until the pending queue |
| 74 // is empty. |
| 75 }) |
| 76 ..expectPause(true) |
| 77 ..expectData(43) |
| 78 ..expectPause(false, () { t.close(); }) |
| 79 ..expectDone() |
| 80 ..expectSubscription(false, false); |
| 81 t..subscribe()..add(42); |
| 82 }); |
| 83 } |
OLD | NEW |