| 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 TimerTest { | 5 class TimerTest { |
| 6 | 6 |
| 7 static final int _STARTTIMEOUT = 1050; | 7 static final int _STARTTIMEOUT = 1050; |
| 8 static final int _DECREASE = 200; | 8 static final int _DECREASE = 200; |
| 9 static final int _ITERATIONS = 5; | 9 static final int _ITERATIONS = 5; |
| 10 | 10 |
| 11 static void testSimpleTimer() { | 11 static void testSimpleTimer() { |
| 12 | 12 |
| 13 void timeoutHandler(Timer timer) { | 13 void timeoutHandler(Timer timer) { |
| 14 int endTime = (new Date.now()).value; | 14 int endTime = (new Date.now()).value; |
| 15 Expect.equals(true, (endTime - _startTime) >= _timeout); | 15 Expect.equals(true, (endTime - _startTime) >= _timeout); |
| 16 if (_iteration < _ITERATIONS) { | 16 if (_iteration < _ITERATIONS) { |
| 17 _iteration++; | 17 _iteration++; |
| 18 _timeout = _timeout - _DECREASE; | 18 _timeout = _timeout - _DECREASE; |
| 19 _startTime = (new Date.now()).value; | 19 _startTime = (new Date.now()).value; |
| 20 new Timer(timeoutHandler, _timeout, false); | 20 new Timer(timeoutHandler, _timeout); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 | 23 |
| 24 _iteration = 0; | 24 _iteration = 0; |
| 25 _timeout = _STARTTIMEOUT; | 25 _timeout = _STARTTIMEOUT; |
| 26 _startTime = (new Date.now()).value; | 26 _startTime = (new Date.now()).value; |
| 27 new Timer(timeoutHandler, _timeout, false); | 27 new Timer(timeoutHandler, _timeout); |
| 28 } | 28 } |
| 29 | 29 |
| 30 static void testMain() { | 30 static void testMain() { |
| 31 testSimpleTimer(); | 31 testSimpleTimer(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 static int _startTime; | 34 static int _startTime; |
| 35 static int _timeout; | 35 static int _timeout; |
| 36 static int _iteration; | 36 static int _iteration; |
| 37 } | 37 } |
| 38 | 38 |
| 39 main() { | 39 main() { |
| 40 TimerTest.testMain(); | 40 TimerTest.testMain(); |
| 41 } | 41 } |
| OLD | NEW |