Chromium Code Reviews| Index: tests/lib/async/zone_create_periodic_timer_test.dart |
| diff --git a/tests/lib/async/zone_create_periodic_timer_test.dart b/tests/lib/async/zone_create_periodic_timer_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c10e3d45cd289c27159080267b1c8b1485b7612 |
| --- /dev/null |
| +++ b/tests/lib/async/zone_create_periodic_timer_test.dart |
| @@ -0,0 +1,57 @@ |
| +// 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. |
|
Lasse Reichstein Nielsen
2013/09/23 14:24:12
Comment seems unrelated to test.
floitsch
2013/09/23 17:12:07
Done.
|
| + |
| + Expect.identical(Zone.ROOT, Zone.current); |
| + Zone forked; |
| + forked = Zone.current.fork(null, new ZoneDescription( |
| + createPeriodicTimer: (Zone self, ZoneDelegate parent, Zone origin, |
| + Duration period, f(Timer timer)) { |
|
Lasse Reichstein Nielsen
2013/09/23 14:24:12
Indent to after '('.
floitsch
2013/09/23 17:12:07
Done.
|
| + events.add("forked.createPeriodicTimer"); |
| + return parent.createPeriodicTimer(origin, period, (Timer timer) { |
| + events.add("wrapped function ${period.inMilliseconds}"); |
| + f(timer); |
| + }); |
| + })); |
| + |
| + asyncStart(); |
| + int tickCount = 0; |
| + forked.run(() { |
| + new Timer.periodic(const Duration(milliseconds: 5), |
| + (Timer timer) { |
| + events.add("periodic Timer $tickCount"); |
| + Expect.identical(forked, Zone.current); |
| + tickCount++; |
| + if (tickCount == 4) { |
| + timer.cancel(); |
| + // Allow some time in case the cancel didn't work. |
| + new Timer(const Duration(milliseconds: 20), done.complete); |
| + } |
| + }); |
| + }); |
| + |
| + Expect.identical(Zone.ROOT, Zone.current); |
| + events.add("after createPeriodicTimer"); |
| + |
| + done.future.whenComplete(() { |
| + Expect.listEquals( |
| + [ "forked.createPeriodicTimer", "after createPeriodicTimer", |
| + "wrapped function 5", "periodic Timer 0", |
| + "wrapped function 5", "periodic Timer 1", |
| + "wrapped function 5", "periodic Timer 2", |
| + "wrapped function 5", "periodic Timer 3" ], |
| + events); |
| + asyncEnd(); |
| + }); |
| +} |