summary-graph_delay-sign_head.js (2751B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from head.js */ 7 8 // Test for following DelaySign component works. 9 // * element existance 10 // * marginInlineStart position 11 // * width 12 // * additinal class 13 14 const TEST_DATA = [ 15 { 16 targetClass: "delay-positive", 17 expectedResult: { 18 marginInlineStart: "25%", 19 width: "25%", 20 }, 21 }, 22 { 23 targetClass: "delay-negative", 24 expectedResult: { 25 additionalClass: "negative", 26 marginInlineStart: "0%", 27 width: "25%", 28 }, 29 }, 30 { 31 targetClass: "fill-backwards-with-delay-iterationstart", 32 expectedResult: { 33 additionalClass: "fill", 34 marginInlineStart: "25%", 35 width: "25%", 36 }, 37 }, 38 { 39 targetClass: "fill-both", 40 }, 41 { 42 targetClass: "fill-both-width-delay-iterationstart", 43 expectedResult: { 44 additionalClass: "fill", 45 marginInlineStart: "25%", 46 width: "25%", 47 }, 48 }, 49 { 50 targetClass: "keyframes-easing-step", 51 }, 52 ]; 53 54 // eslint-disable-next-line no-unused-vars 55 async function testSummaryGraphDelaySign() { 56 await addTab(URL_ROOT + "doc_multi_timings.html"); 57 await removeAnimatedElementsExcept(TEST_DATA.map(t => `.${t.targetClass}`)); 58 const { panel } = await openAnimationInspector(); 59 60 for (const { targetClass, expectedResult } of TEST_DATA) { 61 const animationItemEl = await findAnimationItemByTargetSelector( 62 panel, 63 `.${targetClass}` 64 ); 65 66 info(`Checking delay sign existance for ${targetClass}`); 67 const delaySignEl = animationItemEl.querySelector(".animation-delay-sign"); 68 69 if (expectedResult) { 70 ok( 71 delaySignEl, 72 "The delay sign element should be in animation item element" 73 ); 74 75 function assertExpected(key) { 76 const actual = parseFloat(delaySignEl.style[key]); 77 const expected = parseFloat(expectedResult[key]); 78 Assert.less( 79 Math.abs(actual - expected), 80 0.01, 81 `${key} should be ${expected} (got ${actual})` 82 ); 83 } 84 85 assertExpected(`marginInlineStart`); 86 assertExpected(`width`); 87 88 if (expectedResult.additionalClass) { 89 ok( 90 delaySignEl.classList.contains(expectedResult.additionalClass), 91 `delay sign element should have ${expectedResult.additionalClass} class` 92 ); 93 } else { 94 ok( 95 !delaySignEl.classList.contains(expectedResult.additionalClass), 96 "delay sign element should not have " + 97 `${expectedResult.additionalClass} class` 98 ); 99 } 100 } else { 101 ok( 102 !delaySignEl, 103 "The delay sign element should not be in animation item element" 104 ); 105 } 106 } 107 }