CSSAnimation-getCurrentTime.tentative.html (1753B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>CSSAnimation.currentTime</title> 4 <!-- TODO: Add a more specific link for this once it is specified. --> 5 <link rel="help" href="https://drafts.csswg.org/css-animations-2/#cssanimation"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="support/testcommon.js"></script> 9 <style> 10 11 .animated-div { 12 margin-left: 10px; 13 /* Make it easier to calculate expected values: */ 14 animation-timing-function: linear ! important; 15 } 16 17 @keyframes anim { 18 from { margin-left: 100px; } 19 to { margin-left: 200px; } 20 } 21 22 </style> 23 <div id="log"></div> 24 <script type="text/javascript"> 25 26 'use strict'; 27 28 promise_test(async t => { 29 const div = addDiv(t, { class: 'animated-div' }); 30 div.style.animation = 'anim 100s'; 31 const animation = div.getAnimations()[0]; 32 33 assert_equals( 34 animation.currentTime, 35 0, 36 'Animation.currentTime should be zero when an animation ' + 37 'is initially created' 38 ); 39 40 await animation.ready; 41 42 animation.currentTime = 50 * MS_PER_SEC; 43 44 assert_time_equals_literal( 45 animation.currentTime, 46 50 * MS_PER_SEC, 47 'Check setting of currentTime actually works' 48 ); 49 assert_equals(getComputedStyle(div).marginLeft, '150px'); 50 }, 'currentTime can be used to seek a CSS animation'); 51 52 promise_test(async t => { 53 const div = addDiv(t, { class: 'animated-div' }); 54 div.style.animation = 'anim 100s'; 55 56 const animation = div.getAnimations()[0]; 57 await animation.ready; 58 59 assert_throws_js( 60 TypeError, 61 () => { 62 animation.currentTime = null; 63 }, 64 'Expect TypeError exception on trying to set Animation.currentTime to null' 65 ); 66 }, 'Setting currentTime to null on a CSS animation throws'); 67 68 </script>