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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files 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
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:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 main() { 9 main() {
10 Completer done = new Completer(); 10 Completer done = new Completer();
11 List events = []; 11 List events = [];
12 12
13 bool shouldForward = true; 13 bool shouldForward = true;
14 Expect.identical(Zone.ROOT, Zone.current); 14 Expect.identical(Zone.ROOT, Zone.current);
15 Zone forked = Zone.current.fork(specification: new ZoneSpecification( 15 Zone forked = Zone.current.fork(specification: new ZoneSpecification(
16 run: (Zone self, ZoneDelegate parent, Zone origin, f()) { 16 run: (Zone self, ZoneDelegate parent, Zone origin, f()) {
17 // The zone is still the same as when origin.run was invoked, which 17 // The zone is still the same as when origin.run was invoked, which
18 // is the root zone. (The origin zone hasn't been set yet). 18 // is the root zone. (The origin zone hasn't been set yet).
19 Expect.identical(Zone.ROOT, Zone.current); 19 Expect.identical(Zone.ROOT, Zone.current);
20 events.add("forked.run"); 20 events.add("forked.run");
21 if (shouldForward) return parent.run(origin, f); 21 if (shouldForward) return parent.run(origin, f);
22 return 42; 22 return 42;
23 })); 23 }));
24 24
25 events.add("zone forked"); 25 events.add("zone forked");
26 Zone expectedZone = forked; 26 Zone expectedZone = forked;
27 var result = forked.run(() { 27 var result = forked.run(() {
28 Expect.identical(expectedZone, Zone.current); 28 Expect.identical(expectedZone, Zone.current);
29 events.add("run closure"); 29 events.add("run closure");
30 return 499; 30 return 499;
31 }); 31 });
32 Expect.equals(499, result); 32 Expect.equals(499, result);
33 events.add("executed run"); 33 events.add("executed run");
(...skipping 14 matching lines...) Expand all
48 events.add("run closure 3"); 48 events.add("run closure 3");
49 Expect.identical(forked, Zone.current); 49 Expect.identical(forked, Zone.current);
50 done.complete(true); 50 done.complete(true);
51 }); 51 });
52 return 1234; 52 return 1234;
53 }); 53 });
54 events.add("after nested scheduleMicrotask"); 54 events.add("after nested scheduleMicrotask");
55 Expect.equals(1234, result); 55 Expect.equals(1234, result);
56 56
57 done.future.whenComplete(() { 57 done.future.whenComplete(() {
58 Expect.listEquals( 58 Expect.listEquals([
59 ["zone forked", "forked.run", "run closure", "executed run", 59 "zone forked",
60 "forked.run", "executed run2", "forked.run", "run closure 2", 60 "forked.run",
61 "after nested scheduleMicrotask", "forked.run", "run closure 3"], 61 "run closure",
62 events); 62 "executed run",
63 "forked.run",
64 "executed run2",
65 "forked.run",
66 "run closure 2",
67 "after nested scheduleMicrotask",
68 "forked.run",
69 "run closure 3"
70 ], events);
63 asyncEnd(); 71 asyncEnd();
64 }); 72 });
65 73
66 var zone1 = Zone.ROOT.fork(); 74 var zone1 = Zone.ROOT.fork();
67 var zone2 = Zone.ROOT.fork(); 75 var zone2 = Zone.ROOT.fork();
68 var zone3 = Zone.ROOT.fork(); 76 var zone3 = Zone.ROOT.fork();
69 asyncStart(); 77 asyncStart();
70 asyncStart(); 78 asyncStart();
71 zone1.run(() { 79 zone1.run(() {
72 var future = new Future.value(); 80 var future = new Future.value();
73 zone2.run(() { 81 zone2.run(() {
74 future.then((_) { 82 future.then((_) {
75 Expect.identical(zone2, Zone.current); 83 Expect.identical(zone2, Zone.current);
76 asyncEnd(); 84 asyncEnd();
77 }); 85 });
78 }); 86 });
79 zone3.run(() { 87 zone3.run(() {
80 future.then((_) { 88 future.then((_) {
81 Expect.identical(zone3, Zone.current); 89 Expect.identical(zone3, Zone.current);
82 asyncEnd(); 90 asyncEnd();
83 }); 91 });
84 }); 92 });
85 }); 93 });
86 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698