Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: tests/lib/async/stream_state_nonzero_timer_test.dart

Issue 17490002: Make asBroadcastStream take two callbacks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reintroduce zone. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/async/stream_state_helper.dart ('k') | tests/lib/async/stream_state_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Test the event/callback protocol of the stream implementations. 5 // Test the event/callback protocol of the stream implementations.
6 // Uses a non-zero timer so it fails on d8. 6 // Uses a non-zero timer so it fails on d8.
7 7
8 library stream_state_nonzero_timer_test; 8 library stream_state_nonzero_timer_test;
9 9
10 import "dart:async"; 10 import "dart:async";
11 import "../../../pkg/unittest/lib/unittest.dart"; 11 import "../../../pkg/unittest/lib/unittest.dart";
12 import "stream_state_helper.dart"; 12 import "stream_state_helper.dart";
13 13
14 const ms5 = const Duration(milliseconds: 5); 14 const ms5 = const Duration(milliseconds: 5);
15 15
16 // Testing pause/resume, some with non-zero duration. This only makes sense for
17 // non-broadcast streams, since broadcast stream subscriptions handle their
18 // own pauses.
19
16 main() { 20 main() {
17 mainTest(false); 21 var p = "StreamController";
18 // TODO(floitsch): reenable?
19 // mainTest(true);
20 }
21
22 mainTest(bool broadcast) {
23 var p = broadcast ? "BC" : "SC";
24 22
25 test("$p-sub-data/pause/resume/pause/resume-done", () { 23 test("$p-sub-data/pause/resume/pause/resume-done", () {
26 var t = new StreamProtocolTest(broadcast: broadcast); 24 var t = new StreamProtocolTest();
27 t..expectListen() 25 t..expectListen()
28 ..expectData(42, () { 26 ..expectData(42, () {
29 t.pause(); 27 t.pause();
30 }) 28 })
31 ..expectPause(() { t.resume(); }) 29 ..expectPause(() { t.resume(); })
32 ..expectResume(() { t.pause(); }) 30 ..expectResume(() { t.pause(); })
33 ..expectPause(() { t.resume(); }) 31 ..expectPause(() { t.resume(); })
34 ..expectResume(() { t.close(); }) 32 ..expectResume(() { t.close(); })
35 ..expectDone() 33 ..expectDone()
36 ..expectCancel(); 34 ..expectCancel(t.terminate);
37 t..listen()..add(42); 35 t..listen()..add(42);
38 }); 36 });
39 37
40 test("$p-sub-data/pause-done", () { 38 test("$p-sub-data/pause-done", () {
41 var t = new StreamProtocolTest(broadcast: broadcast); 39 var t = new StreamProtocolTest();
42 t..expectListen() 40 t..expectListen()
43 ..expectData(42, () { 41 ..expectData(42, () {
44 t.pause(new Future.delayed(ms5, () => null)); 42 t.pause(new Future.delayed(ms5, () => null));
45 }) 43 })
46 ..expectPause() 44 ..expectPause()
47 ..expectDone() 45 ..expectDone()
48 ..expectCancel(); 46 ..expectCancel(t.terminate);
49 // We are calling "close" while the controller is actually paused, 47 // We are calling "close" while the controller is actually paused,
50 // and it will stay paused until the pending events are sent. 48 // and it will stay paused until the pending events are sent.
51 t..listen()..add(42)..close(); 49 t..listen()..add(42)..close();
52 }); 50 });
53 51
54 test("$p-sub-data/pause-resume/done", () { 52 test("$p-sub-data/pause-resume/done", () {
55 var t = new StreamProtocolTest(broadcast: broadcast); 53 var t = new StreamProtocolTest();
56 t..expectListen() 54 t..expectListen()
57 ..expectData(42, () { 55 ..expectData(42, () {
58 t.pause(new Future.delayed(ms5, () => null)); 56 t.pause(new Future.delayed(ms5, () => null));
59 }) 57 })
60 ..expectPause() 58 ..expectPause()
61 ..expectResume(t.close) 59 ..expectResume(t.close)
62 ..expectDone() 60 ..expectDone()
63 ..expectCancel(); 61 ..expectCancel(t.terminate);
64 t..listen()..add(42); 62 t..listen()..add(42);
65 }); 63 });
66 64
67 test("$p-sub-data/data+pause-data-resume-done", () { 65 test("$p-sub-data/data+pause-data-resume-done", () {
68 var t = new StreamProtocolTest(broadcast: broadcast); 66 var t = new StreamProtocolTest();
69 t..expectListen() 67 t..expectListen()
70 ..expectData(42, () { 68 ..expectData(42, () {
71 t.add(43); 69 t.add(43);
72 t.pause(new Future.delayed(ms5, () => null)); 70 t.pause(new Future.delayed(ms5, () => null));
73 // Should now be paused until the future finishes. 71 // Should now be paused until the future finishes.
74 // After that, the controller stays paused until the pending queue 72 // After that, the controller stays paused until the pending queue
75 // is empty. 73 // is empty.
76 }) 74 })
77 ..expectPause() 75 ..expectPause()
78 ..expectData(43) 76 ..expectData(43)
79 ..expectResume(t.close) 77 ..expectResume(t.close)
80 ..expectDone() 78 ..expectDone()
81 ..expectCancel(); 79 ..expectCancel(t.terminate);
82 t..listen()..add(42); 80 t..listen()..add(42);
83 }); 81 });
84 82
85 test("$p-pause-during-callback", () { 83 test("$p-pause-during-callback", () {
86 var t = new StreamProtocolTest(broadcast: broadcast); 84 var t = new StreamProtocolTest();
87 t..expectListen() 85 t..expectListen()
88 ..expectData(42, () { 86 ..expectData(42, () {
89 t.pause(); 87 t.pause();
90 }) 88 })
91 ..expectPause(() { 89 ..expectPause(() {
92 t.resume(); 90 t.resume();
93 }) 91 })
94 ..expectResume(() { 92 ..expectResume(() {
95 t.pause(); 93 t.pause();
96 t.resume(); 94 t.resume();
97 t.close(); 95 t.close();
98 }) 96 })
99 ..expectDone() 97 ..expectDone()
100 ..expectCancel(); 98 ..expectCancel(t.terminate);
101 t..listen() 99 t..listen()
102 ..add(42); 100 ..add(42);
103 }); 101 });
104 } 102 }
OLDNEW
« no previous file with comments | « tests/lib/async/stream_state_helper.dart ('k') | tests/lib/async/stream_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698