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

Side by Side Diff: tests/lib_strong/async/zone_run_unary_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
« no previous file with comments | « tests/lib_strong/async/zone_run_test.dart ('k') | tests/lib_strong/async/zone_value_test.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) 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:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart';
7 import 'dart:async';
8
9 main() {
10 Completer done = new Completer();
11 List events = [];
12
13 bool shouldForward = true;
14 Expect.identical(Zone.ROOT, Zone.current);
15 Zone forked = Zone.current.fork(specification: new ZoneSpecification(
16 runUnary: (Zone self, ZoneDelegate parent, Zone origin, f(arg), arg) {
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).
19 Expect.identical(Zone.current, Zone.ROOT);
20 events.add("forked.run1");
21 if (shouldForward) return parent.runUnary(origin, f, arg + 1);
22 return 42;
23 }));
24
25 events.add("zone forked");
26 Zone expectedZone = forked;
27 var result = forked.runUnary((arg) {
28 Expect.identical(expectedZone, Zone.current);
29 events.add("run closure");
30 return arg + 3;
31 }, 495);
32 Expect.equals(499, result);
33 events.add("executed run");
34
35 shouldForward = false;
36 result = forked.runUnary((arg) {
37 Expect.fail("should not be invoked");
38 }, 99);
39 Expect.equals(42, result);
40 events.add("executed run2");
41
42 asyncStart();
43 shouldForward = true;
44 result = forked.runUnary((arg) {
45 Expect.identical(forked, Zone.current);
46 events.add("run closure 2");
47 scheduleMicrotask(() {
48 events.add("run closure 3");
49 Expect.identical(forked, Zone.current);
50 done.complete(true);
51 });
52 return -arg - 8;
53 }, 490);
54 events.add("after nested scheduleMicrotask");
55 Expect.equals(-499, result);
56
57 done.future.whenComplete(() {
58 Expect.listEquals(
59 ["zone forked", "forked.run1", "run closure", "executed run",
60 "forked.run1", "executed run2", "forked.run1", "run closure 2",
61 "after nested scheduleMicrotask", "run closure 3"],
62 events);
63 asyncEnd();
64 });
65 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/zone_run_test.dart ('k') | tests/lib_strong/async/zone_value_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698