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

Unified Diff: packages/watcher/test/ready/shared.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/watcher/test/ready/polling_test.dart ('k') | packages/watcher/test/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/watcher/test/ready/shared.dart
diff --git a/packages/watcher/test/ready/shared.dart b/packages/watcher/test/ready/shared.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7be48331e2be7bcd54b41691a15dbec46d75df79
--- /dev/null
+++ b/packages/watcher/test/ready/shared.dart
@@ -0,0 +1,98 @@
+// Copyright (c) 2012, 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 'package:scheduled_test/scheduled_test.dart';
+
+import '../utils.dart';
+
+void sharedTests() {
+ test('ready does not complete until after subscription', () {
+ var watcher = createWatcher(waitForReady: false);
+
+ var ready = false;
+ watcher.ready.then((_) {
+ ready = true;
+ });
+
+ // Should not be ready yet.
+ schedule(() {
+ expect(ready, isFalse);
+ });
+
+ // Subscribe to the events.
+ schedule(() {
+ var subscription = watcher.events.listen((event) {});
+
+ currentSchedule.onComplete.schedule(() {
+ subscription.cancel();
+ });
+ });
+
+ // Should eventually be ready.
+ schedule(() => watcher.ready);
+
+ schedule(() {
+ expect(ready, isTrue);
+ });
+ });
+
+ test('ready completes immediately when already ready', () {
+ var watcher = createWatcher(waitForReady: false);
+
+ // Subscribe to the events.
+ schedule(() {
+ var subscription = watcher.events.listen((event) {});
+
+ currentSchedule.onComplete.schedule(() {
+ subscription.cancel();
+ });
+ });
+
+ // Should eventually be ready.
+ schedule(() => watcher.ready);
+
+ // Now ready should be a future that immediately completes.
+ var ready = false;
+ schedule(() {
+ watcher.ready.then((_) {
+ ready = true;
+ });
+ });
+
+ schedule(() {
+ expect(ready, isTrue);
+ });
+ });
+
+ test('ready returns a future that does not complete after unsubscribing', () {
+ var watcher = createWatcher(waitForReady: false);
+
+ // Subscribe to the events.
+ var subscription;
+ schedule(() {
+ subscription = watcher.events.listen((event) {});
+ });
+
+ var ready = false;
+
+ // Wait until ready.
+ schedule(() => watcher.ready);
+
+ // Now unsubscribe.
+ schedule(() {
+ subscription.cancel();
+
+ // Track when it's ready again.
+ ready = false;
+ watcher.ready.then((_) {
+ ready = true;
+ });
+ });
+
+ // Should be back to not ready.
+ schedule(() {
+ expect(ready, isFalse);
+ });
+ });
+}
« no previous file with comments | « packages/watcher/test/ready/polling_test.dart ('k') | packages/watcher/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698