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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib_strong/async/zone_run_unary_test.dart
diff --git a/tests/lib_strong/async/zone_run_unary_test.dart b/tests/lib_strong/async/zone_run_unary_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c9dea3e9fd46cd2bcad9f10a941375c76b4c3f15
--- /dev/null
+++ b/tests/lib_strong/async/zone_run_unary_test.dart
@@ -0,0 +1,65 @@
+// 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 = [];
+
+ bool shouldForward = true;
+ Expect.identical(Zone.ROOT, Zone.current);
+ Zone forked = Zone.current.fork(specification: new ZoneSpecification(
+ runUnary: (Zone self, ZoneDelegate parent, Zone origin, f(arg), arg) {
+ // 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.current, Zone.ROOT);
+ events.add("forked.run1");
+ if (shouldForward) return parent.runUnary(origin, f, arg + 1);
+ return 42;
+ }));
+
+ events.add("zone forked");
+ Zone expectedZone = forked;
+ var result = forked.runUnary((arg) {
+ Expect.identical(expectedZone, Zone.current);
+ events.add("run closure");
+ return arg + 3;
+ }, 495);
+ Expect.equals(499, result);
+ events.add("executed run");
+
+ shouldForward = false;
+ result = forked.runUnary((arg) {
+ Expect.fail("should not be invoked");
+ }, 99);
+ Expect.equals(42, result);
+ events.add("executed run2");
+
+ asyncStart();
+ shouldForward = true;
+ result = forked.runUnary((arg) {
+ Expect.identical(forked, Zone.current);
+ events.add("run closure 2");
+ scheduleMicrotask(() {
+ events.add("run closure 3");
+ Expect.identical(forked, Zone.current);
+ done.complete(true);
+ });
+ return -arg - 8;
+ }, 490);
+ events.add("after nested scheduleMicrotask");
+ Expect.equals(-499, result);
+
+ done.future.whenComplete(() {
+ Expect.listEquals(
+ ["zone forked", "forked.run1", "run closure", "executed run",
+ "forked.run1", "executed run2", "forked.run1", "run closure 2",
+ "after nested scheduleMicrotask", "run closure 3"],
+ events);
+ asyncEnd();
+ });
+}
« 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