browser_animation_playPauseSeveral.js (2119B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Check that the AnimationsActor can pause/play a given list of animations at once. 7 8 // List of selectors that match "all" animated nodes in the test page. 9 // This list misses a bunch of animated nodes on purpose. Only the ones that 10 // have infinite animations are listed. This is done to avoid intermittents 11 // caused when finite animations are already done playing by the time the test 12 // runs. 13 const ALL_ANIMATED_NODES = [ 14 ".simple-animation", 15 ".multiple-animations", 16 ".delayed-animation", 17 ]; 18 19 add_task(async function () { 20 const { target, walker, animations } = await initAnimationsFrontForUrl( 21 MAIN_DOMAIN + "animation.html" 22 ); 23 24 info("Pause all animations in the test document"); 25 await toggleAndCheckStates(walker, animations, ALL_ANIMATED_NODES, "paused"); 26 27 info("Play all animations in the test document"); 28 await toggleAndCheckStates(walker, animations, ALL_ANIMATED_NODES, "running"); 29 30 await target.destroy(); 31 gBrowser.removeCurrentTab(); 32 }); 33 34 async function toggleAndCheckStates(walker, animations, selectors, playState) { 35 info( 36 "Checking the playState of all the nodes that have infinite running " + 37 "animations" 38 ); 39 40 for (const selector of selectors) { 41 const players = await getPlayersFor(walker, animations, selector); 42 43 if (playState === "paused") { 44 await animations.pauseSome(players); 45 } else { 46 await animations.playSome(players); 47 } 48 49 info("Getting the AnimationPlayerFront for node " + selector); 50 const player = players[0]; 51 await checkPlayState(player, selector, playState); 52 } 53 } 54 55 async function getPlayersFor(walker, animations, selector) { 56 const node = await walker.querySelector(walker.rootNode, selector); 57 return animations.getAnimationPlayersForNode(node); 58 } 59 60 async function checkPlayState(player, selector, expectedState) { 61 const state = await player.getCurrentState(); 62 is( 63 state.playState, 64 expectedState, 65 "The playState of node " + selector + " is " + expectedState 66 ); 67 }