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

Side by Side Diff: tests/lib_strong/async/zone_run_guarded_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: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 // runGuarded calls run, captures the synchronous error (if any) and
14 // gives that one to handleUncaughtError.
15
16 Expect.identical(Zone.ROOT, Zone.current);
17 Zone forked;
18 forked = Zone.current.fork(specification: new ZoneSpecification(
19 run: (Zone self, ZoneDelegate parent, Zone origin, f()) {
20 // The zone is still the same as when origin.run was invoked, which
21 // is the root zone. (The origin zone hasn't been set yet).
22 Expect.identical(Zone.ROOT, Zone.current);
23 events.add("forked.run");
24 return parent.run(origin, f);
25 },
26 handleUncaughtError:
27 (Zone self, ZoneDelegate parent, Zone origin, error, stackTrace) {
28 Expect.identical(Zone.ROOT, Zone.current);
29 Expect.identical(forked, origin);
30 events.add("forked.handleUncaught $error");
31 return 499;
32 }));
33
34 var result = forked.runGuarded(() {
35 events.add("runGuarded 1");
36 Expect.identical(forked, Zone.current);
37 return 42;
38 });
39 Expect.identical(Zone.ROOT, Zone.current);
40 Expect.equals(42, result);
41 events.add("after runGuarded 1");
42
43 result = forked.runGuarded(() {
44 events.add("runGuarded 2");
45 Expect.identical(forked, Zone.current);
46 throw 42;
47 });
48 Expect.equals(499, result);
49
50 Expect.listEquals(
51 [ "forked.run", "runGuarded 1", "after runGuarded 1",
52 "forked.run", "runGuarded 2", "forked.handleUncaught 42" ],
53 events);
54
55 events.clear();
56 asyncStart();
57 result = forked.runGuarded(() {
58 Expect.identical(forked, Zone.current);
59 events.add("run closure");
60 forked.scheduleMicrotask(() {
61 events.add("run closure 2");
62 Expect.identical(forked, Zone.current);
63 done.complete(true);
64 throw 88;
65 });
66 throw 1234;
67 });
68 events.add("after nested scheduleMicrotask");
69 Expect.equals(499, result);
70
71 done.future.whenComplete(() {
72 Expect.listEquals(
73 ["forked.run", "run closure", "forked.handleUncaught 1234",
74 "after nested scheduleMicrotask", "forked.run", "run closure 2",
75 "forked.handleUncaught 88" ],
76 events);
77 asyncEnd();
78 });
79 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/zone_root_bind_test.dart ('k') | tests/lib_strong/async/zone_run_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698