OLD | NEW |
(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 testForkedZone(Zone forked) { |
| 10 var result; |
| 11 result = forked.run(() { |
| 12 Expect.identical(forked, Zone.current); |
| 13 return 499; |
| 14 }); |
| 15 Expect.equals(499, result); |
| 16 Expect.identical(Zone.ROOT, Zone.current); |
| 17 |
| 18 result = forked.runUnary((x) { |
| 19 Expect.equals(42, x); |
| 20 Expect.identical(forked, Zone.current); |
| 21 return -499; |
| 22 }, 42); |
| 23 Expect.equals(-499, result); |
| 24 Expect.identical(Zone.ROOT, Zone.current); |
| 25 |
| 26 bool runGuardedDidRun = false; |
| 27 forked.runGuarded(() { |
| 28 runGuardedDidRun = true; |
| 29 Expect.identical(forked, Zone.current); |
| 30 }); |
| 31 Expect.identical(Zone.ROOT, Zone.current); |
| 32 Expect.isTrue(runGuardedDidRun); |
| 33 |
| 34 runGuardedDidRun = false; |
| 35 forked.runUnaryGuarded((x) { |
| 36 runGuardedDidRun = true; |
| 37 Expect.equals(42, x); |
| 38 Expect.identical(forked, Zone.current); |
| 39 }, 42); |
| 40 Expect.identical(Zone.ROOT, Zone.current); |
| 41 Expect.isTrue(runGuardedDidRun); |
| 42 |
| 43 var callback = () => 499; |
| 44 Expect.identical(callback, forked.registerCallback(callback)); |
| 45 Expect.identical(Zone.ROOT, Zone.current); |
| 46 |
| 47 var callback1 = (x) => 42 + x; |
| 48 Expect.identical(callback1, forked.registerUnaryCallback(callback1)); |
| 49 Expect.identical(Zone.ROOT, Zone.current); |
| 50 |
| 51 asyncStart(); |
| 52 bool asyncDidRun = false; |
| 53 forked.scheduleMicrotask(() { |
| 54 Expect.identical(forked, Zone.current); |
| 55 asyncDidRun = true; |
| 56 asyncEnd(); |
| 57 }); |
| 58 Expect.isFalse(asyncDidRun); |
| 59 Expect.identical(Zone.ROOT, Zone.current); |
| 60 |
| 61 asyncStart(); |
| 62 bool timerDidRun = false; |
| 63 forked.createTimer(const Duration(milliseconds: 0), () { |
| 64 Expect.identical(forked, Zone.current); |
| 65 timerDidRun = true; |
| 66 asyncEnd(); |
| 67 }); |
| 68 Expect.identical(Zone.ROOT, Zone.current); |
| 69 } |
| 70 |
| 71 main() { |
| 72 Expect.identical(Zone.ROOT, Zone.current); |
| 73 Zone forked = Zone.current.fork(); |
| 74 Expect.isFalse(identical(Zone.ROOT, forked)); |
| 75 testForkedZone(forked); |
| 76 Zone forkedChild = forked.fork(); |
| 77 testForkedZone(forkedChild); |
| 78 } |
OLD | NEW |