OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library RequestAnimationFrameTest; | 5 library RequestAnimationFrameTest; |
| 6 |
6 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 8 import 'package:unittest/html_config.dart'; |
8 import 'dart:html'; | 9 import 'dart:html'; |
9 | 10 |
10 main() { | 11 main() { |
11 useHtmlConfiguration(); | 12 useHtmlConfiguration(); |
12 | 13 |
13 test('oneShot', () { | 14 test('oneShot', () { |
14 var frame = window.requestAnimationFrame( | 15 var frame = window.requestAnimationFrame(expectAsync((timestamp) {})); |
15 expectAsync((timestamp) { })); | 16 }); |
16 }); | |
17 | 17 |
18 test('twoShot', () { | 18 test('twoShot', () { |
19 var frame = window.requestAnimationFrame( | 19 var frame = window.requestAnimationFrame(expectAsync((timestamp1) { |
20 expectAsync((timestamp1) { | 20 window.requestAnimationFrame(expectAsync((timestamp2) { |
21 window.requestAnimationFrame( | 21 // Not monotonic on Safari and IE. |
22 expectAsync((timestamp2) { | 22 // expect(timestamp2, greaterThan(timestamp1), |
23 // Not monotonic on Safari and IE. | 23 // reason: 'timestamps ordered'); |
24 // expect(timestamp2, greaterThan(timestamp1), | 24 })); |
25 // reason: 'timestamps ordered'); | 25 })); |
26 })); | 26 }); |
27 })); | |
28 }); | |
29 | |
30 | 27 |
31 // How do we test that a callback is never called? We can't wrap the uncalled | 28 // How do we test that a callback is never called? We can't wrap the uncalled |
32 // callback with 'expectAsync'. Will request several frames and try | 29 // callback with 'expectAsync'. Will request several frames and try |
33 // cancelling the one that is not the last. | 30 // cancelling the one that is not the last. |
34 test('cancel1', () { | 31 test('cancel1', () { |
35 var frame1 = window.requestAnimationFrame( | 32 var frame1 = window.requestAnimationFrame((timestamp1) { |
36 (timestamp1) { | 33 throw new Exception('Should have been cancelled'); |
37 throw new Exception('Should have been cancelled'); | |
38 }); | |
39 var frame2 = window.requestAnimationFrame( | |
40 expectAsync((timestamp2) { })); | |
41 window.cancelAnimationFrame(frame1); | |
42 }); | 34 }); |
| 35 var frame2 = window.requestAnimationFrame(expectAsync((timestamp2) {})); |
| 36 window.cancelAnimationFrame(frame1); |
| 37 }); |
43 | 38 |
44 test('cancel2', () { | 39 test('cancel2', () { |
45 var frame1 = window.requestAnimationFrame( | 40 var frame1 = window.requestAnimationFrame(expectAsync((timestamp1) {})); |
46 expectAsync((timestamp1) { })); | 41 var frame2 = window.requestAnimationFrame((timestamp2) { |
47 var frame2 = window.requestAnimationFrame( | 42 throw new Exception('Should have been cancelled'); |
48 (timestamp2) { | |
49 throw new Exception('Should have been cancelled'); | |
50 }); | |
51 var frame3 = window.requestAnimationFrame( | |
52 expectAsync((timestamp3) { })); | |
53 window.cancelAnimationFrame(frame2); | |
54 }); | 43 }); |
| 44 var frame3 = window.requestAnimationFrame(expectAsync((timestamp3) {})); |
| 45 window.cancelAnimationFrame(frame2); |
| 46 }); |
55 } | 47 } |
OLD | NEW |