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

Unified Diff: pkg/barback/test/stream_replayer_test.dart

Issue 23469003: Add an AssetStream class to Barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/barback/test/stream_replayer_test.dart
diff --git a/pkg/barback/test/stream_replayer_test.dart b/pkg/barback/test/stream_replayer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f341a2927fc2005d188b6b70cfd33580285852d9
--- /dev/null
+++ b/pkg/barback/test/stream_replayer_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library barback.test.stream_replayer_test;
+
+import 'dart:async';
+
+import 'package:barback/src/stream_replayer.dart';
+import 'package:barback/src/utils.dart';
+import 'package:unittest/unittest.dart';
+
+import 'utils.dart';
+
+main() {
+ initConfig();
+
+ test("a replay that's retrieved before the stream is finished replays the "
+ "stream", () {
+ var controller = new StreamController<int>();
+ var replay = new StreamReplayer<int>(controller.stream).getReplay();
+
+ controller.add(1);
+ controller.add(2);
+ controller.add(3);
+ controller.close();
+
+ expect(replay.toList(), completion(equals([1, 2, 3])));
+ });
+
+ test("a replay that's retrieved after the stream is finished replays the "
+ "stream", () {
+ var controller = new StreamController<int>();
+ var replayer = new StreamReplayer<int>(controller.stream);
+
+ controller.add(1);
+ controller.add(2);
+ controller.add(3);
+ controller.close();
+
+ expect(replayer.getReplay().toList(), completion(equals([1, 2, 3])));
+ });
+
+ test("multiple replays each replay the stream", () {
+ var controller = new StreamController<int>();
+ var replayer = new StreamReplayer<int>(controller.stream);
+
+ var replay1 = replayer.getReplay();
+ controller.add(1);
+ controller.add(2);
+ controller.add(3);
+ controller.close();
+ var replay2 = replayer.getReplay();
+
+ expect(replay1.toList(), completion(equals([1, 2, 3])));
+ expect(replay2.toList(), completion(equals([1, 2, 3])));
+ });
+
+ test("the replayed stream doesn't close until the source stream closes", () {
+ var controller = new StreamController<int>();
+ var replay = new StreamReplayer<int>(controller.stream).getReplay();
+ var isClosed = false;
+ replay.last.then((_) {
+ isClosed = true;
+ });
+
+ controller.add(1);
+ controller.add(2);
+ controller.add(3);
+
+ expect(pumpEventQueue().then((_) {
+ expect(isClosed, isFalse);
+ controller.close();
+ return pumpEventQueue();
+ }).then((_) {
+ expect(isClosed, isTrue);
+ }), completes);
+ });
+}
« pkg/barback/lib/src/stream_replayer.dart ('K') | « pkg/barback/test/asset_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698