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

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

Issue 23875032: Expose Zones. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « tests/lib/async/zone_root_bind_test.dart ('k') | tests/lib/async/zone_run_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 // 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: (Zone self, ZoneDelegate parent, Zone origin, e) {
27 Expect.identical(Zone.ROOT, Zone.current);
28 Expect.identical(forked, origin);
29 events.add("forked.handleUncaught $e");
30 return 499;
31 }));
32
33 var result = forked.runGuarded(() {
34 events.add("runGuarded 1");
35 Expect.identical(forked, Zone.current);
36 return 42;
37 });
38 Expect.identical(Zone.ROOT, Zone.current);
39 Expect.equals(42, result);
40 events.add("after runGuarded 1");
41
42 result = forked.runGuarded(() {
43 events.add("runGuarded 2");
44 Expect.identical(forked, Zone.current);
45 throw 42;
46 });
47 Expect.equals(499, result);
48
49 Expect.listEquals(
50 [ "forked.run", "runGuarded 1", "after runGuarded 1",
51 "forked.run", "runGuarded 2", "forked.handleUncaught 42" ],
52 events);
53
54 events.clear();
55 asyncStart();
56 result = forked.runGuarded(() {
57 Expect.identical(forked, Zone.current);
58 events.add("run closure");
59 runAsync(() {
60 events.add("run closure 2");
61 Expect.identical(forked, Zone.current);
62 done.complete(true);
63 throw 88;
64 });
65 throw 1234;
66 });
67 events.add("after nested runAsync");
68 Expect.equals(499, result);
69
70 done.future.whenComplete(() {
71 Expect.listEquals(
72 ["forked.run", "run closure", "forked.handleUncaught 1234",
73 "after nested runAsync", "forked.run", "run closure 2",
74 "forked.handleUncaught 88" ],
75 events);
76 asyncEnd();
77 });
78 }
OLDNEW
« no previous file with comments | « tests/lib/async/zone_root_bind_test.dart ('k') | tests/lib/async/zone_run_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698