browser_animation_playback-rate-selector.js (2905B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test for following PlaybackRateSelector component: 7 // * element existence 8 // * make playback rate of animations by the selector 9 // * in case of animations have mixed playback rate 10 // * in case of animations have playback rate which is not default selectable value 11 12 add_task(async function () { 13 await addTab(URL_ROOT + "doc_custom_playback_rate.html"); 14 const { animationInspector, inspector, panel } = 15 await openAnimationInspector(); 16 17 info("Checking playback rate selector existence"); 18 const selectEl = panel.querySelector(".playback-rate-selector"); 19 ok(selectEl, "scrubber controller should exist"); 20 21 info( 22 "Checking playback rate existence which includes custom rate of animations" 23 ); 24 const expectedPlaybackRates = [0.01, 0.1, 0.25, 0.5, 1, 1.5, 2, 5, 10]; 25 await assertPlaybackRateOptions(selectEl, expectedPlaybackRates); 26 27 info("Checking selected playback rate"); 28 is(Number(selectEl.value), 1.5, "Selected option should be 1.5"); 29 30 info("Checking playback rate of animations"); 31 await changePlaybackRateSelector(animationInspector, panel, 0.5); 32 await assertPlaybackRate(animationInspector, 0.5); 33 34 info("Checking mixed playback rate"); 35 await selectNode("div", inspector); 36 await waitUntil(() => panel.querySelectorAll(".animation-item").length === 1); 37 await changePlaybackRateSelector(animationInspector, panel, 2); 38 await assertPlaybackRate(animationInspector, 2); 39 await selectNode("body", inspector); 40 await waitUntil(() => panel.querySelectorAll(".animation-item").length === 2); 41 await waitUntil(() => selectEl.value === ""); 42 ok(true, "Selected option should be empty"); 43 44 info("Checking playback rate after re-setting"); 45 await changePlaybackRateSelector(animationInspector, panel, 1); 46 await assertPlaybackRate(animationInspector, 1); 47 48 info( 49 "Checking whether custom playback rate exist " + 50 "after selecting another playback rate" 51 ); 52 await assertPlaybackRateOptions(selectEl, expectedPlaybackRates); 53 }); 54 55 async function assertPlaybackRate(animationInspector, rate) { 56 await waitUntil(() => 57 animationInspector.state?.animations.every( 58 ({ state }) => state.playbackRate === rate 59 ) 60 ); 61 ok(true, `Playback rate of animations should be ${rate}`); 62 } 63 64 async function assertPlaybackRateOptions(selectEl, expectedPlaybackRates) { 65 await waitUntil(() => { 66 if (selectEl.options.length !== expectedPlaybackRates.length) { 67 return false; 68 } 69 70 for (let i = 0; i < selectEl.options.length; i++) { 71 const optionEl = selectEl.options[i]; 72 const expectedPlaybackRate = expectedPlaybackRates[i]; 73 if (Number(optionEl.value) !== expectedPlaybackRate) { 74 return false; 75 } 76 } 77 78 return true; 79 }); 80 ok(true, "Content of playback rate options are correct"); 81 }