mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
a2b556b937
Change-Id: Ia5c41dda6503e1fbb8cc6099835d07588425e2ba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128310 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
79 lines
2.2 KiB
Dart
79 lines
2.2 KiB
Dart
// 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';
|
|
|
|
testForkedZone(Zone forked) {
|
|
var result;
|
|
result = forked.run(() {
|
|
Expect.identical(forked, Zone.current);
|
|
return 499;
|
|
});
|
|
Expect.equals(499, result);
|
|
Expect.identical(Zone.root, Zone.current);
|
|
|
|
result = forked.runUnary((x) {
|
|
Expect.equals(42, x);
|
|
Expect.identical(forked, Zone.current);
|
|
return -499;
|
|
}, 42);
|
|
Expect.equals(-499, result);
|
|
Expect.identical(Zone.root, Zone.current);
|
|
|
|
bool runGuardedDidRun = false;
|
|
forked.runGuarded(() {
|
|
runGuardedDidRun = true;
|
|
Expect.identical(forked, Zone.current);
|
|
});
|
|
Expect.identical(Zone.root, Zone.current);
|
|
Expect.isTrue(runGuardedDidRun);
|
|
|
|
runGuardedDidRun = false;
|
|
forked.runUnaryGuarded((x) {
|
|
runGuardedDidRun = true;
|
|
Expect.equals(42, x);
|
|
Expect.identical(forked, Zone.current);
|
|
}, 42);
|
|
Expect.identical(Zone.root, Zone.current);
|
|
Expect.isTrue(runGuardedDidRun);
|
|
|
|
var callback = () => 499;
|
|
Expect.identical(callback, forked.registerCallback(callback));
|
|
Expect.identical(Zone.root, Zone.current);
|
|
|
|
var callback1 = (x) => 42 + x;
|
|
Expect.identical(callback1, forked.registerUnaryCallback(callback1));
|
|
Expect.identical(Zone.root, Zone.current);
|
|
|
|
asyncStart();
|
|
bool asyncDidRun = false;
|
|
forked.scheduleMicrotask(() {
|
|
Expect.identical(forked, Zone.current);
|
|
asyncDidRun = true;
|
|
asyncEnd();
|
|
});
|
|
Expect.isFalse(asyncDidRun);
|
|
Expect.identical(Zone.root, Zone.current);
|
|
|
|
asyncStart();
|
|
bool timerDidRun = false;
|
|
forked.createTimer(const Duration(milliseconds: 0), () {
|
|
Expect.identical(forked, Zone.current);
|
|
timerDidRun = true;
|
|
asyncEnd();
|
|
});
|
|
Expect.identical(Zone.root, Zone.current);
|
|
}
|
|
|
|
main() {
|
|
Expect.identical(Zone.root, Zone.current);
|
|
Zone forked = Zone.current.fork();
|
|
Expect.isFalse(identical(Zone.root, forked));
|
|
testForkedZone(forked);
|
|
Zone forkedChild = forked.fork();
|
|
testForkedZone(forkedChild);
|
|
}
|