summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/animation/test/summary-graph_delay-sign_head.js
blob: fffd653b1d7909c9149292f54ffd4616b73f62a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* import-globals-from head.js */

// Test for following DelaySign component works.
// * element existance
// * marginInlineStart position
// * width
// * additinal class

const TEST_DATA = [
  {
    targetClass: "delay-positive",
    expectedResult: {
      marginInlineStart: "25%",
      width: "25%",
    },
  },
  {
    targetClass: "delay-negative",
    expectedResult: {
      additionalClass: "negative",
      marginInlineStart: "0%",
      width: "25%",
    },
  },
  {
    targetClass: "fill-backwards-with-delay-iterationstart",
    expectedResult: {
      additionalClass: "fill",
      marginInlineStart: "25%",
      width: "25%",
    },
  },
  {
    targetClass: "fill-both",
  },
  {
    targetClass: "fill-both-width-delay-iterationstart",
    expectedResult: {
      additionalClass: "fill",
      marginInlineStart: "25%",
      width: "25%",
    },
  },
  {
    targetClass: "keyframes-easing-step",
  },
];

// eslint-disable-next-line no-unused-vars
async function testSummaryGraphDelaySign() {
  await addTab(URL_ROOT + "doc_multi_timings.html");
  await removeAnimatedElementsExcept(TEST_DATA.map(t => `.${t.targetClass}`));
  const { panel } = await openAnimationInspector();

  for (const { targetClass, expectedResult } of TEST_DATA) {
    const animationItemEl = await findAnimationItemByTargetSelector(
      panel,
      `.${targetClass}`
    );

    info(`Checking delay sign existance for ${targetClass}`);
    const delaySignEl = animationItemEl.querySelector(".animation-delay-sign");

    if (expectedResult) {
      ok(
        delaySignEl,
        "The delay sign element should be in animation item element"
      );

      function assertExpected(key) {
        const actual = parseFloat(delaySignEl.style[key]);
        const expected = parseFloat(expectedResult[key]);
        Assert.less(
          Math.abs(actual - expected),
          0.01,
          `${key} should be ${expected} (got ${actual})`
        );
      }

      assertExpected(`marginInlineStart`);
      assertExpected(`width`);

      if (expectedResult.additionalClass) {
        ok(
          delaySignEl.classList.contains(expectedResult.additionalClass),
          `delay sign element should have ${expectedResult.additionalClass} class`
        );
      } else {
        ok(
          !delaySignEl.classList.contains(expectedResult.additionalClass),
          "delay sign element should not have " +
            `${expectedResult.additionalClass} class`
        );
      }
    } else {
      ok(
        !delaySignEl,
        "The delay sign element should not be in animation item element"
      );
    }
  }
}