browser_animation_updatedState.js (1909B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint-disable mozilla/no-arbitrary-setTimeout */ 4 5 "use strict"; 6 7 // Check the animation player's updated state 8 9 add_task(async function () { 10 const { target, walker, animations } = await initAnimationsFrontForUrl( 11 MAIN_DOMAIN + "animation.html" 12 ); 13 14 await playStateIsUpdatedDynamically(walker, animations); 15 16 await target.destroy(); 17 gBrowser.removeCurrentTab(); 18 }); 19 20 async function playStateIsUpdatedDynamically(walker, animations) { 21 info("Getting the test node (which runs a very long animation)"); 22 // The animation lasts for 100s, to avoid intermittents. 23 const node = await walker.querySelector(walker.rootNode, ".long-animation"); 24 25 info("Getting the animation player front for this node"); 26 const [player] = await animations.getAnimationPlayersForNode(node); 27 28 let state = await player.getCurrentState(); 29 is( 30 state.playState, 31 "running", 32 "The playState is running while the animation is running" 33 ); 34 35 info( 36 "Change the animation's currentTime to be near the end and wait for " + 37 "it to finish" 38 ); 39 const onFinished = waitForAnimationPlayState(player, "finished"); 40 // Set the currentTime to 98s, knowing that the animation lasts for 100s. 41 await animations.setCurrentTimes([player], 98 * 1000, false); 42 state = await onFinished; 43 is( 44 state.playState, 45 "finished", 46 "The animation has ended and the state has been updated" 47 ); 48 Assert.greater( 49 state.currentTime, 50 player.initialState.currentTime, 51 "The currentTime has been updated" 52 ); 53 } 54 55 async function waitForAnimationPlayState(player, playState) { 56 let state = {}; 57 while (state.playState !== playState) { 58 state = await player.getCurrentState(); 59 await wait(500); 60 } 61 return state; 62 } 63 64 function wait(ms) { 65 return new Promise(r => setTimeout(r, ms)); 66 }