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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 import 'package:scheduled_test/scheduled_test.dart';
6
7 import '../utils.dart';
8
9 void sharedTests() {
10 test('ready does not complete until after subscription', () {
11 var watcher = createWatcher(waitForReady: false);
12
13 var ready = false;
14 watcher.ready.then((_) {
15 ready = true;
16 });
17
18 // Should not be ready yet.
19 schedule(() {
20 expect(ready, isFalse);
21 });
22
23 // Subscribe to the events.
24 schedule(() {
25 var subscription = watcher.events.listen((event) {});
26
27 currentSchedule.onComplete.schedule(() {
28 subscription.cancel();
29 });
30 });
31
32 // Should eventually be ready.
33 schedule(() => watcher.ready);
34
35 schedule(() {
36 expect(ready, isTrue);
37 });
38 });
39
40 test('ready completes immediately when already ready', () {
41 var watcher = createWatcher(waitForReady: false);
42
43 // Subscribe to the events.
44 schedule(() {
45 var subscription = watcher.events.listen((event) {});
46
47 currentSchedule.onComplete.schedule(() {
48 subscription.cancel();
49 });
50 });
51
52 // Should eventually be ready.
53 schedule(() => watcher.ready);
54
55 // Now ready should be a future that immediately completes.
56 var ready = false;
57 schedule(() {
58 watcher.ready.then((_) {
59 ready = true;
60 });
61 });
62
63 schedule(() {
64 expect(ready, isTrue);
65 });
66 });
67
68 test('ready returns a future that does not complete after unsubscribing', () {
69 var watcher = createWatcher(waitForReady: false);
70
71 // Subscribe to the events.
72 var subscription;
73 schedule(() {
74 subscription = watcher.events.listen((event) {});
75 });
76
77 var ready = false;
78
79 // Wait until ready.
80 schedule(() => watcher.ready);
81
82 // Now unsubscribe.
83 schedule(() {
84 subscription.cancel();
85
86 // Track when it's ready again.
87 ready = false;
88 watcher.ready.then((_) {
89 ready = true;
90 });
91 });
92
93 // Should be back to not ready.
94 schedule(() {
95 expect(ready, isFalse);
96 });
97 });
98 }
OLDNEW
« 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