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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib_strong/async/zone_run_guarded_test.dart
diff --git a/tests/lib_strong/async/zone_run_guarded_test.dart b/tests/lib_strong/async/zone_run_guarded_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4145443a947652f51a963a23e9c31e3868fb6acf
--- /dev/null
+++ b/tests/lib_strong/async/zone_run_guarded_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+import 'package:async_helper/async_helper.dart';
+import 'dart:async';
+
+main() {
+ Completer done = new Completer();
+ List events = [];
+
+ // runGuarded calls run, captures the synchronous error (if any) and
+ // gives that one to handleUncaughtError.
+
+ Expect.identical(Zone.ROOT, Zone.current);
+ Zone forked;
+ forked = Zone.current.fork(specification: new ZoneSpecification(
+ run: (Zone self, ZoneDelegate parent, Zone origin, f()) {
+ // The zone is still the same as when origin.run was invoked, which
+ // is the root zone. (The origin zone hasn't been set yet).
+ Expect.identical(Zone.ROOT, Zone.current);
+ events.add("forked.run");
+ return parent.run(origin, f);
+ },
+ handleUncaughtError:
+ (Zone self, ZoneDelegate parent, Zone origin, error, stackTrace) {
+ Expect.identical(Zone.ROOT, Zone.current);
+ Expect.identical(forked, origin);
+ events.add("forked.handleUncaught $error");
+ return 499;
+ }));
+
+ var result = forked.runGuarded(() {
+ events.add("runGuarded 1");
+ Expect.identical(forked, Zone.current);
+ return 42;
+ });
+ Expect.identical(Zone.ROOT, Zone.current);
+ Expect.equals(42, result);
+ events.add("after runGuarded 1");
+
+ result = forked.runGuarded(() {
+ events.add("runGuarded 2");
+ Expect.identical(forked, Zone.current);
+ throw 42;
+ });
+ Expect.equals(499, result);
+
+ Expect.listEquals(
+ [ "forked.run", "runGuarded 1", "after runGuarded 1",
+ "forked.run", "runGuarded 2", "forked.handleUncaught 42" ],
+ events);
+
+ events.clear();
+ asyncStart();
+ result = forked.runGuarded(() {
+ Expect.identical(forked, Zone.current);
+ events.add("run closure");
+ forked.scheduleMicrotask(() {
+ events.add("run closure 2");
+ Expect.identical(forked, Zone.current);
+ done.complete(true);
+ throw 88;
+ });
+ throw 1234;
+ });
+ events.add("after nested scheduleMicrotask");
+ Expect.equals(499, result);
+
+ done.future.whenComplete(() {
+ Expect.listEquals(
+ ["forked.run", "run closure", "forked.handleUncaught 1234",
+ "after nested scheduleMicrotask", "forked.run", "run closure 2",
+ "forked.handleUncaught 88" ],
+ events);
+ asyncEnd();
+ });
+}
« 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