Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, 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 'dart:async'; | |
| 6 import '../../../pkg/unittest/lib/unittest.dart'; | |
| 7 | |
| 8 main() { | |
| 9 | |
| 10 test("timer isActive test", () { | |
| 11 Timer t; | |
| 12 | |
| 13 void checkNotActive() => expect(t.isActive, equals(false)); | |
|
floitsch
2013/07/01 12:49:43
nit: if the function is that small, just use it at
zarah
2013/07/01 16:15:35
Done.
| |
| 14 | |
| 15 t = new Timer(new Duration(seconds: 1), expectAsync0(checkNotActive)); | |
| 16 expect(t.isActive, equals(true)); | |
| 17 }); | |
| 18 | |
| 19 test("periodic timer cancel test", () { | |
| 20 Timer t; | |
| 21 | |
| 22 int i = 0; | |
| 23 void checkActive(Timer timer) { | |
| 24 expect(t.isActive, equals(true)); | |
| 25 if (i == 2) { | |
| 26 t.cancel(); | |
| 27 expect(t.isActive, equals(false)); | |
| 28 } | |
| 29 i++; | |
| 30 } | |
| 31 | |
| 32 t = new Timer.periodic(new Duration(milliseconds: 1), | |
| 33 expectAsync1(checkActive, count: 3)); | |
| 34 }); | |
|
floitsch
2013/07/01 12:49:43
check that timer is active outside callback.
zarah
2013/07/01 16:15:35
Done.
| |
| 35 | |
| 36 test("timer cancel test", () { | |
| 37 Timer timer; | |
| 38 Timer canceller; | |
| 39 | |
| 40 void unreachable() { | |
| 41 fail("Cancelled timer should not be reached"); | |
| 42 } | |
| 43 | |
| 44 void cancelOtherTimer() { | |
| 45 expect(timer.isActive, equals(true)); | |
| 46 timer.cancel(); | |
| 47 expect(timer.isActive, equals(t)); | |
|
floitsch
2013/07/01 12:49:43
t?
zarah
2013/07/01 16:15:35
t-> true
| |
| 48 } | |
| 49 | |
| 50 timer = new Timer(new Duration(milliseconds: 1), | |
|
floitsch
2013/07/01 12:49:43
nits:
no need to assign it if you don't use it lat
zarah
2013/07/01 16:15:35
Done.
| |
| 51 expectAsync0(cancelOtherTimer)); | |
| 52 timer = new Timer(new Duration(milliseconds: 1000), | |
|
floitsch
2013/07/01 12:49:43
seconds: 1
zarah
2013/07/01 16:15:35
Done.
| |
| 53 expectAsync0(unreachable, count: 0)); | |
|
floitsch
2013/07/01 12:49:43
this line should not be reached. -> don't expectAs
zarah
2013/07/01 16:15:35
Done.
| |
| 54 }); | |
| 55 } | |
| OLD | NEW |