browser_animation_pause-resume-button_respectively.js (2613B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test whether pausing/resuming the each animations correctly. 7 8 add_task(async function () { 9 await addTab(URL_ROOT + "doc_simple_animation.html"); 10 await removeAnimatedElementsExcept([".animated", ".compositor-all"]); 11 const { animationInspector, inspector, panel } = 12 await openAnimationInspector(); 13 const buttonEl = panel.querySelector(".pause-resume-button"); 14 15 info( 16 "Check '.compositor-all' animation is still running " + 17 "after even pausing '.animated' animation" 18 ); 19 await selectNode(".animated", inspector); 20 clickOnPauseResumeButton(animationInspector, panel); 21 await waitUntilAnimationsPlayState(animationInspector, "paused"); 22 ok(buttonEl.classList.contains("paused"), "State of button should be paused"); 23 await selectNode("body", inspector); 24 await assertStatus( 25 animationInspector.state.animations, 26 buttonEl, 27 ["paused", "running"], 28 false 29 ); 30 31 info( 32 "Check both animations are paused after clicking pause/resume " + 33 "while displaying both animations" 34 ); 35 clickOnPauseResumeButton(animationInspector, panel); 36 await assertStatus( 37 animationInspector.state.animations, 38 buttonEl, 39 ["paused", "paused"], 40 true 41 ); 42 43 info( 44 "Check '.animated' animation is still paused " + 45 "after even resuming '.compositor-all' animation" 46 ); 47 await selectNode(".compositor-all", inspector); 48 clickOnPauseResumeButton(animationInspector, panel); 49 await waitUntil(() => 50 animationInspector.state.animations.some( 51 a => a.state.playState === "running" 52 ) 53 ); 54 ok( 55 !buttonEl.classList.contains("paused"), 56 "State of button should be running" 57 ); 58 await selectNode("body", inspector); 59 await assertStatus( 60 animationInspector.state.animations, 61 buttonEl, 62 ["paused", "running"], 63 false 64 ); 65 }); 66 67 async function assertStatus( 68 animations, 69 buttonEl, 70 expectedAnimationStates, 71 shouldButtonPaused 72 ) { 73 await waitUntil(() => { 74 for (let i = 0; i < expectedAnimationStates.length; i++) { 75 const animation = animations[i]; 76 const state = expectedAnimationStates[i]; 77 if (animation.state.playState !== state) { 78 return false; 79 } 80 } 81 return true; 82 }); 83 expectedAnimationStates.forEach((state, index) => { 84 is( 85 animations[index].state.playState, 86 state, 87 `Animation ${index} should be ${state}` 88 ); 89 }); 90 91 is( 92 buttonEl.classList.contains("paused"), 93 shouldButtonPaused, 94 "State of button is correct" 95 ); 96 }