OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library RequestAnimationFrameTest; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/html_config.dart'; |
| 8 import 'dart:html'; |
| 9 |
| 10 main() { |
| 11 useHtmlConfiguration(); |
| 12 |
| 13 test('oneShot', () { |
| 14 var frame = window.requestAnimationFrame( |
| 15 expectAsync((timestamp) { })); |
| 16 }); |
| 17 |
| 18 test('twoShot', () { |
| 19 var frame = window.requestAnimationFrame( |
| 20 expectAsync((timestamp1) { |
| 21 window.requestAnimationFrame( |
| 22 expectAsync((timestamp2) { |
| 23 // Not monotonic on Safari and IE. |
| 24 // expect(timestamp2, greaterThan(timestamp1), |
| 25 // reason: 'timestamps ordered'); |
| 26 })); |
| 27 })); |
| 28 }); |
| 29 |
| 30 |
| 31 // 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 |
| 33 // cancelling the one that is not the last. |
| 34 test('cancel1', () { |
| 35 var frame1 = window.requestAnimationFrame( |
| 36 (timestamp1) { |
| 37 throw new Exception('Should have been cancelled'); |
| 38 }); |
| 39 var frame2 = window.requestAnimationFrame( |
| 40 expectAsync((timestamp2) { })); |
| 41 window.cancelAnimationFrame(frame1); |
| 42 }); |
| 43 |
| 44 test('cancel2', () { |
| 45 var frame1 = window.requestAnimationFrame( |
| 46 expectAsync((timestamp1) { })); |
| 47 var frame2 = window.requestAnimationFrame( |
| 48 (timestamp2) { |
| 49 throw new Exception('Should have been cancelled'); |
| 50 }); |
| 51 var frame3 = window.requestAnimationFrame( |
| 52 expectAsync((timestamp3) { })); |
| 53 window.cancelAnimationFrame(frame2); |
| 54 }); |
| 55 } |
OLD | NEW |