| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 class TimerRepeatTest { | 5 class TimerRepeatTest { |
| 6 | 6 |
| 7 static final int _TIMEOUT = 500; | 7 static final int _TIMEOUT = 500; |
| 8 static final int _ITERATIONS = 5; | 8 static final int _ITERATIONS = 5; |
| 9 | 9 |
| 10 static void testRepeatTimer() { | 10 static void testRepeatTimer() { |
| 11 | 11 |
| 12 void timeoutHandler(Timer timer) { | 12 void timeoutHandler(Timer timer) { |
| 13 int endTime = (new Date.now()).value; | 13 int endTime = (new Date.now()).value; |
| 14 _iteration++; | 14 _iteration++; |
| 15 if (_iteration < _ITERATIONS) { | 15 if (_iteration < _ITERATIONS) { |
| 16 _startTime = (new Date.now()).value; | 16 _startTime = (new Date.now()).value; |
| 17 } else { | 17 } else { |
| 18 Expect.equals(_iteration, _ITERATIONS); | 18 Expect.equals(_iteration, _ITERATIONS); |
| 19 timer.cancel(); | 19 timer.cancel(); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 _iteration = 0; | 23 _iteration = 0; |
| 24 _startTime = (new Date.now()).value; | 24 _startTime = (new Date.now()).value; |
| 25 timer = new Timer(timeoutHandler, _TIMEOUT, true); | 25 timer = new Timer.repeating(timeoutHandler, _TIMEOUT); |
| 26 } | 26 } |
| 27 | 27 |
| 28 static void testMain() { | 28 static void testMain() { |
| 29 testRepeatTimer(); | 29 testRepeatTimer(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static Timer timer; | 32 static Timer timer; |
| 33 static int _startTime; | 33 static int _startTime; |
| 34 static int _iteration; | 34 static int _iteration; |
| 35 } | 35 } |
| 36 | 36 |
| 37 main() { | 37 main() { |
| 38 TimerRepeatTest.testMain(); | 38 TimerRepeatTest.testMain(); |
| 39 } | 39 } |
| OLD | NEW |