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

Side by Side Diff: tests/lib_strong/async/schedule_microtask_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:async_helper/async_helper.dart';
6 import "package:expect/expect.dart";
7 import 'dart:async';
8
9
10 Future testOneScheduleMicrotask() {
11 var completer = new Completer();
12 Timer.run(() {
13 scheduleMicrotask(completer.complete);
14 });
15 return completer.future;
16 }
17
18
19 Future testMultipleScheduleMicrotask() {
20 var completer = new Completer();
21 Timer.run(() {
22 const TOTAL = 10;
23 int done = 0;
24 for (int i = 0; i < TOTAL; i++) {
25 scheduleMicrotask(() {
26 done++;
27 if (done == TOTAL) completer.complete();;
28 });
29 }
30 });
31 return completer.future;
32 }
33
34
35 Future testScheduleMicrotaskThenTimer() {
36 var completer = new Completer();
37 Timer.run(() {
38 bool scheduleMicrotaskDone = false;
39 scheduleMicrotask(() {
40 Expect.isFalse(scheduleMicrotaskDone);
41 scheduleMicrotaskDone = true;
42 });
43 Timer.run(() {
44 Expect.isTrue(scheduleMicrotaskDone);
45 completer.complete();
46 });
47 });
48 return completer.future;
49 }
50
51
52 Future testTimerThenScheduleMicrotask() {
53 var completer = new Completer();
54 Timer.run(() {
55 bool scheduleMicrotaskDone = false;
56 Timer.run(() {
57 Expect.isTrue(scheduleMicrotaskDone);
58 completer.complete();
59 });
60 scheduleMicrotask(() {
61 Expect.isFalse(scheduleMicrotaskDone);
62 scheduleMicrotaskDone = true;
63 });
64 });
65 return completer.future;
66 }
67
68
69 Future testTimerThenScheduleMicrotaskChain() {
70 var completer = new Completer();
71 Timer.run(() {
72 const TOTAL = 10;
73 int scheduleMicrotaskDone = 0;
74 Timer.run(() {
75 Expect.equals(TOTAL, scheduleMicrotaskDone);
76 completer.complete();
77 });
78 Future scheduleMicrotaskCallback() {
79 scheduleMicrotaskDone++;
80 if (scheduleMicrotaskDone != TOTAL) {
81 scheduleMicrotask(scheduleMicrotaskCallback);
82 }
83 }
84 scheduleMicrotask(scheduleMicrotaskCallback);
85 });
86 return completer.future;
87 }
88
89
90 main() {
91 asyncStart();
92 testOneScheduleMicrotask()
93 .then((_) => testMultipleScheduleMicrotask())
94 .then((_) => testScheduleMicrotaskThenTimer())
95 .then((_) => testTimerThenScheduleMicrotask())
96 .then((_) => testTimerThenScheduleMicrotaskChain())
97 .then((_) => asyncEnd());
98 }
99
OLDNEW
« no previous file with comments | « tests/lib_strong/async/schedule_microtask5_test.dart ('k') | tests/lib_strong/async/slow_consumer2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698