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

Unified Diff: packages/async/test/typed_wrapper/stream_subscription_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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: packages/async/test/typed_wrapper/stream_subscription_test.dart
diff --git a/packages/async/test/typed_wrapper/stream_subscription_test.dart b/packages/async/test/typed_wrapper/stream_subscription_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f52abe7ec148d12243a3ec56cd5df779c2b1f2d3
--- /dev/null
+++ b/packages/async/test/typed_wrapper/stream_subscription_test.dart
@@ -0,0 +1,143 @@
+// Copyright (c) 2016, 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.
+
+import 'dart:async';
+
+import "package:async/src/typed/stream_subscription.dart";
+import "package:test/test.dart";
+
+import '../utils.dart';
+
+void main() {
+ group("with valid types, forwards", () {
+ var controller;
+ var wrapper;
+ var isCanceled;
+ setUp(() {
+ controller = new StreamController<Object>(onCancel: () {
+ isCanceled = true;
+ });
+ wrapper =
+ new TypeSafeStreamSubscription<int>(controller.stream.listen(null));
+ });
+
+ test("onData()", () {
+ wrapper.onData(expectAsync1((data) {
+ expect(data, equals(1));
+ }));
+ controller.add(1);
+ });
+
+ test("onError()", () {
+ wrapper.onError(expectAsync1((error) {
+ expect(error, equals("oh no"));
+ }));
+ controller.addError("oh no");
+ });
+
+ test("onDone()", () {
+ wrapper.onDone(expectAsync0(() {}));
+ controller.close();
+ });
+
+ test("pause(), resume(), and isPaused", () async {
+ expect(wrapper.isPaused, isFalse);
+
+ wrapper.pause();
+ await flushMicrotasks();
+ expect(controller.isPaused, isTrue);
+ expect(wrapper.isPaused, isTrue);
+
+ wrapper.resume();
+ await flushMicrotasks();
+ expect(controller.isPaused, isFalse);
+ expect(wrapper.isPaused, isFalse);
+ });
+
+ test("cancel()", () async {
+ wrapper.cancel();
+ await flushMicrotasks();
+ expect(isCanceled, isTrue);
+ });
+
+ test("asFuture()", () {
+ expect(wrapper.asFuture(12), completion(equals(12)));
+ controller.close();
+ });
+ });
+
+ group("with invalid types,", () {
+ var controller;
+ var wrapper;
+ var isCanceled;
+ setUp(() {
+ controller = new StreamController<Object>(onCancel: () {
+ isCanceled = true;
+ });
+ wrapper =
+ new TypeSafeStreamSubscription<int>(controller.stream.listen(null));
+ });
+
+ group("throws a CastError for", () {
+ test("onData()", () {
+ expect(() {
+ // TODO(nweiz): Use the wrapper declared in setUp when sdk#26226 is
+ // fixed.
+ controller = new StreamController<Object>();
+ wrapper = new TypeSafeStreamSubscription<int>(
+ controller.stream.listen(null));
+
+ wrapper.onData(expectAsync1((_) {}, count: 0));
+ controller.add("foo");
+ }, throwsZonedCastError);
+ });
+ });
+
+ group("doesn't throw a CastError for", () {
+ test("onError()", () {
+ wrapper.onError(expectAsync1((error) {
+ expect(error, equals("oh no"));
+ }));
+ controller.add("foo");
+ controller.addError("oh no");
+ });
+
+ test("onDone()", () {
+ wrapper.onDone(expectAsync0(() {}));
+ controller.add("foo");
+ controller.close();
+ });
+
+ test("pause(), resume(), and isPaused", () async {
+ controller.add("foo");
+
+ expect(wrapper.isPaused, isFalse);
+
+ wrapper.pause();
+ await flushMicrotasks();
+ expect(controller.isPaused, isTrue);
+ expect(wrapper.isPaused, isTrue);
+
+ wrapper.resume();
+ await flushMicrotasks();
+ expect(controller.isPaused, isFalse);
+ expect(wrapper.isPaused, isFalse);
+ });
+
+ test("cancel()", () async {
+ controller.add("foo");
+
+ wrapper.cancel();
+ await flushMicrotasks();
+ expect(isCanceled, isTrue);
+ });
+
+ test("asFuture()", () {
+ expect(wrapper.asFuture(12), completion(equals(12)));
+ controller.add("foo");
+ controller.close();
+ });
+ });
+ });
+}
« no previous file with comments | « packages/async/test/typed_wrapper/future_test.dart ('k') | packages/async/test/typed_wrapper/stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698