OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:async/async.dart'; | 5 import 'package:async/async.dart'; |
6 import 'package:fake_async/fake_async.dart'; | 6 import 'package:fake_async/fake_async.dart'; |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 | 8 |
9 main() { | 9 main() { |
10 test("runs the callback once the duration has elapsed", () { | 10 test("runs the callback once the duration has elapsed", () { |
11 new FakeAsync().run((async) { | 11 new FakeAsync().run((async) { |
12 var fired = false; | 12 var fired = false; |
13 var timer = new RestartableTimer(new Duration(seconds: 5), () { | 13 new RestartableTimer(new Duration(seconds: 5), () { |
14 fired = true; | 14 fired = true; |
15 }); | 15 }); |
16 | 16 |
17 async.elapse(new Duration(seconds: 4)); | 17 async.elapse(new Duration(seconds: 4)); |
18 expect(fired, isFalse); | 18 expect(fired, isFalse); |
19 | 19 |
20 async.elapse(new Duration(seconds: 1)); | 20 async.elapse(new Duration(seconds: 1)); |
21 expect(fired, isTrue); | 21 expect(fired, isTrue); |
22 }); | 22 }); |
23 }); | 23 }); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 expect(fired, isFalse); | 92 expect(fired, isFalse); |
93 timer.reset(); | 93 timer.reset(); |
94 | 94 |
95 async.elapse(new Duration(seconds: 5)); | 95 async.elapse(new Duration(seconds: 5)); |
96 expect(fired, isTrue); | 96 expect(fired, isTrue); |
97 }); | 97 }); |
98 }); | 98 }); |
99 | 99 |
100 test("only runs the callback once if the timer isn't reset", () { | 100 test("only runs the callback once if the timer isn't reset", () { |
101 new FakeAsync().run((async) { | 101 new FakeAsync().run((async) { |
102 var timer = new RestartableTimer( | 102 new RestartableTimer( |
103 new Duration(seconds: 5), | 103 new Duration(seconds: 5), |
104 expectAsync(() {}, count: 1)); | 104 expectAsync(() {}, count: 1)); |
105 async.elapse(new Duration(seconds: 10)); | 105 async.elapse(new Duration(seconds: 10)); |
106 }); | 106 }); |
107 }); | 107 }); |
108 } | 108 } |
OLD | NEW |