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

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

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

Powered by Google App Engine
This is Rietveld 408576698