worklet-animation-without-target.https.html (2842B)
1 <!DOCTYPE html> 2 <title>Verify that effect without target is supported</title> 3 <link rel="help" href="https://drafts.css-houdini.org/css-animationworklet/"> 4 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/web-animations/testcommon.js"></script> 8 <script src="common.js"></script> 9 10 <div id="box"></div> 11 12 <script> 13 14 setup(setupAndRegisterTests, {explicit_done: true}); 15 16 async function setupAndRegisterTests() { 17 await registerPassthroughAnimator(); 18 19 promise_test(async t => { 20 const effect = new KeyframeEffect(null, 21 { transform: ['translateY(100px)', 'translateY(200px)'] }, 22 { duration: Infinity, iterations: 1 } 23 ); 24 const animation = new WorkletAnimation('passthrough', effect); 25 animation.play(); 26 27 // Allow one async animation frame to pass so that animation is running. 28 await waitForAsyncAnimationFrames(1); 29 assert_equals(animation.playState, "running"); 30 // Allow time to advance so that we have a non-zero current time. 31 await waitForDocumentTimelineAdvance(); 32 const t0 = document.timeline.currentTime; 33 assert_greater_than(animation.currentTime, 0); 34 assert_times_equal(animation.currentTime, (t0 - animation.startTime)); 35 assert_equals(animation.playState, "running"); 36 37 animation.cancel(); 38 }, 'Animating effect with no target should work.'); 39 40 promise_test(async t => { 41 const effect = new KeyframeEffect(document.getElementById('box'), 42 { transform: ['translateY(100px)', 'translateY(200px)'] }, 43 { duration: Infinity, iterations: 1 } 44 ); 45 46 const animation = new WorkletAnimation('passthrough', effect); 47 animation.play(); 48 49 // Allow one async animation frame to pass so that animation is running. 50 await waitForAsyncAnimationFrames(1); 51 assert_equals(animation.playState, "running"); 52 // Allow time to advance so that we have a non-zero current time. 53 await waitForDocumentTimelineAdvance(); 54 const t0 = document.timeline.currentTime; 55 assert_greater_than(animation.currentTime, 0); 56 assert_times_equal(animation.currentTime, (t0 - animation.startTime)); 57 assert_equals(animation.playState, "running"); 58 59 await waitForDocumentTimelineAdvance(); 60 animation.effect.target = null; 61 const t1 = document.timeline.currentTime; 62 assert_times_equal(animation.currentTime, (t1 - animation.startTime)); 63 assert_equals(animation.playState, "running"); 64 65 await waitForDocumentTimelineAdvance(); 66 animation.effect.target = document.getElementById('box'); 67 const t2 = document.timeline.currentTime; 68 assert_times_equal(animation.currentTime, (t2 - animation.startTime)); 69 assert_equals(animation.playState, "running"); 70 71 animation.cancel(); 72 }, 'The existence of a target does not affect the animation.'); 73 74 done(); 75 } 76 </script>