| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 testEmptyZoneSpecification() { | 9 testEmptyZoneSpecification() { |
| 10 Expect.identical(Zone.ROOT, Zone.current); | 10 Expect.identical(Zone.ROOT, Zone.current); |
| 11 Zone forked = Zone.current.fork(); | 11 Zone forked = Zone.current.fork(); |
| 12 Expect.isFalse(identical(Zone.ROOT, forked)); | 12 Expect.isFalse(identical(Zone.ROOT, forked)); |
| 13 | 13 |
| 14 asyncStart(); | 14 asyncStart(); |
| 15 bool timerDidRun = false; | 15 bool timerDidRun = false; |
| 16 forked.createTimer(const Duration(milliseconds: 20), () { | 16 forked.createTimer(const Duration(milliseconds: 20), () { |
| 17 // The createTimer functions on the Zone binds the closures. | 17 // The createTimer function on the Zone binds the closures. |
| 18 Expect.identical(forked, Zone.current); | 18 Expect.identical(forked, Zone.current); |
| 19 timerDidRun = true; | 19 timerDidRun = true; |
| 20 asyncEnd(); | 20 asyncEnd(); |
| 21 }); | 21 }); |
| 22 Expect.identical(Zone.ROOT, Zone.current); | 22 Expect.identical(Zone.ROOT, Zone.current); |
| 23 | 23 |
| 24 asyncStart(); | 24 asyncStart(); |
| 25 int periodicTimerCount = 0; | 25 int periodicTimerCount = 0; |
| 26 forked.createPeriodicTimer(const Duration(milliseconds: 20), (Timer timer) { | 26 forked.createPeriodicTimer(const Duration(milliseconds: 20), (Timer timer) { |
| 27 periodicTimerCount++; | 27 periodicTimerCount++; |
| 28 if (periodicTimerCount == 4) { | 28 if (periodicTimerCount == 4) { |
| 29 timer.cancel(); | 29 timer.cancel(); |
| 30 asyncEnd(); | 30 asyncEnd(); |
| 31 } | 31 } |
| 32 // The createPeriodicTimer functions on the Zone binds the closures. | 32 // The createPeriodicTimer function on the Zone binds the closures. |
| 33 Expect.identical(forked, Zone.current); | 33 Expect.identical(forked, Zone.current); |
| 34 }); | 34 }); |
| 35 Expect.identical(Zone.ROOT, Zone.current); | 35 Expect.identical(Zone.ROOT, Zone.current); |
| 36 } | 36 } |
| 37 | 37 |
| 38 main() { | 38 main() { |
| 39 testEmptyZoneSpecification(); | 39 testEmptyZoneSpecification(); |
| 40 } | 40 } |
| OLD | NEW |