| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| |
| <script> |
| var duration = 100000; |
| |
| function assert_unresolved(value) { |
| assert_equals(value, null); |
| } |
| |
| function idleAnimation() { |
| var animation = document.documentElement.animate([], duration); |
| animation.cancel(); |
| return animation; |
| } |
| |
| function runningAnimation() { |
| var animation = idleAnimation(); |
| animation.play(); |
| animation.startTime = document.timeline.currentTime; |
| return animation; |
| } |
| |
| function pendingStartTimeAnimation() { |
| var animation = idleAnimation(); |
| animation.play(); |
| return animation; |
| } |
| |
| function pendingStartTimeAndCurrentTimeAnimation() { |
| var animation = idleAnimation(); |
| animation.play(); |
| animation.pause(); |
| animation.play(); |
| return animation; |
| } |
| |
| function pausedAnimation() { |
| var animation = idleAnimation(); |
| animation.pause(); |
| animation.currentTime = 0; |
| return animation; |
| } |
| |
| function finishedAnimation() { |
| var animation = idleAnimation(); |
| animation.play(); |
| animation.finish(); |
| return animation; |
| } |
| |
| test(function() { |
| var animation = idleAnimation(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "idle"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "pending startTime"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'running'); |
| }, "running"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'paused'); |
| }, "paused"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "finished"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.play(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "idle -> play()"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.pause(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "idle -> pause()"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.cancel(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "idle -> cancel()"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.finish(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "idle -> finish()"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.reverse(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "idle -> reverse()"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.currentTime = 1000; |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'paused'); |
| }, "idle -> set currentTime"); |
| |
| test(function() { |
| var animation = idleAnimation(); |
| animation.startTime = document.timeline.currentTime - 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - 1000); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "idle -> set startTime"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.play(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "pending startTime -> play()"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.pause(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "pending startTime -> pause()"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.cancel(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "pending startTime -> cancel()"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.finish(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "pending startTime -> finish()"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.reverse(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "pending startTime -> reverse()"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.currentTime = 1000; |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'pending'); |
| }, "pending startTime -> set currentTime"); |
| |
| test(function() { |
| var animation = pendingStartTimeAnimation(); |
| animation.startTime = document.timeline.currentTime - 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - 1000); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "pending startTime -> set startTime"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| var startTime = animation.startTime; |
| var currentTime = animation.currentTime; |
| animation.play(); |
| assert_equals(animation.startTime, startTime); |
| assert_equals(animation.currentTime, currentTime); |
| assert_equals(animation.playState, 'running'); |
| }, "running -> play()"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.pause(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "running -> pause()"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.cancel(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "running -> cancel()"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.finish(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "running -> finish()"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.reverse(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "running -> reverse()"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.currentTime = 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "running -> set currentTime"); |
| |
| test(function() { |
| var animation = runningAnimation(); |
| animation.startTime = document.timeline.currentTime - 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - 1000); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "running -> set startTime"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.play(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "paused -> play()"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.pause(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'paused'); |
| }, "paused -> pause()"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.cancel(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "paused -> cancel()"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.finish(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "paused -> finish()"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.reverse(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "paused -> reverse()"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.currentTime = 1000; |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'paused'); |
| }, "paused -> set currentTime"); |
| |
| test(function() { |
| var animation = pausedAnimation(); |
| animation.startTime = document.timeline.currentTime - 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - 1000); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "paused -> set startTime"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.play(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, 0); |
| assert_equals(animation.playState, 'pending'); |
| }, "finished -> play()"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.pause(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "finished -> pause()"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.cancel(); |
| assert_unresolved(animation.startTime); |
| assert_unresolved(animation.currentTime); |
| assert_equals(animation.playState, 'idle'); |
| }, "finished -> cancel()"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.finish(); |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'finished'); |
| }, "finished -> finish()"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.reverse(); |
| assert_unresolved(animation.startTime); |
| assert_equals(animation.currentTime, duration); |
| assert_equals(animation.playState, 'pending'); |
| }, "finished -> reverse()"); |
| |
| test(function() { |
| var animation = finishedAnimation(); |
| animation.currentTime = 1000; |
| assert_equals(animation.startTime, document.timeline.currentTime - animation.currentTime); |
| assert_equals(animation.currentTime, 1000); |
| assert_equals(animation.playState, 'running'); |
| }, "finished -> set currentTime"); |
| |
| { |
| let test = async_test("pending (play) -> ready.then()"); |
| let animation = idleAnimation(); |
| animation.play(); |
| let animationCurrentTime = animation.currentTime; |
| let timelineCurrentTime = document.timeline.currentTime; |
| animation.ready.then(() => { |
| test.step(() => { |
| assert_equals(animation.playState, 'running'); |
| assert_greater_than_equal(animation.startTime, timelineCurrentTime); |
| assert_greater_than_equal(animation.currentTime, animationCurrentTime); |
| }); |
| test.done(); |
| }); |
| } |
| |
| { |
| let test = async_test("pending (pause) -> ready.then()"); |
| let animation = runningAnimation(); |
| animation.pause(); |
| let animationCurrentTime = animation.currentTime; |
| animation.ready.then(() => { |
| test.step(() => { |
| assert_equals(animation.playState, 'paused'); |
| assert_unresolved(animation.startTime); |
| assert_greater_than_equal(animation.currentTime, animationCurrentTime); |
| }); |
| test.done(); |
| }); |
| } |
| </script> |