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