summaryrefslogtreecommitdiffstats
path: root/dom/animation/test/mozilla/test_underlying_discrete_value.html
blob: 3961305df36e8c72bf728311546dae7e122a0f5c (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../testcommon.js"></script>
<body>
<div id="log"></div>
<script>
"use strict";

// Tests that we correctly extract the underlying value when the animation
// type is 'discrete'.
const discreteTests = [
  {
    stylesheet: {
      "@keyframes keyframes":
      "from { align-content: flex-start; } to { align-content: flex-end; } "
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "flex-start" },
      { computedOffset: 1, alignContent: "flex-end" }
    ],
    explanation: "Test for fully-specified keyframes"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "from { align-content: flex-start; }"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "flex-start" },
      { computedOffset: 1, alignContent: "normal" }
    ],
    explanation: "Test for 0% keyframe only",
  },
  {
    stylesheet: {
      "@keyframes keyframes": "to { align-content: flex-end; }"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "normal" },
      { computedOffset: 1, alignContent: "flex-end" }
    ],
    explanation: "Test for 100% keyframe only",
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      "#target": "align-content: space-between;"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "space-between" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "space-between" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }"
    },
    attributes: {
      style: "align-content: space-between"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "space-between" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "space-between" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element using style attribute"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      "#target": "align-content: inherit;"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "normal" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "normal" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and 'inherit' specified on target element",
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      ".target": "align-content: space-between;"
    },
    attributes: {
      class: "target"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "space-between" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "space-between" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element using class selector"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      "div": "align-content: space-between;"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "space-between" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "space-between" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element using type selector"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      "div": "align-content: space-between;",
      ".target": "align-content: flex-start;",
      "#target": "align-content: flex-end;"
    },
    attributes: {
      class: "target"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "flex-end" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "flex-end" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element " +
                 "using ID selector that overrides class selector"
  },
  {
    stylesheet: {
      "@keyframes keyframes": "50% { align-content: center; }",
      "div": "align-content: space-between !important;",
      ".target": "align-content: flex-start;",
      "#target": "align-content: flex-end;"
    },
    attributes: {
      class: "target"
    },
    expectedKeyframes: [
      { computedOffset: 0, alignContent: "space-between" },
      { computedOffset: 0.5, alignContent: "center" },
      { computedOffset: 1, alignContent: "space-between" }
    ],
    explanation: "Test for no 0%/100% keyframes " +
                 "and specified style on target element " +
                 "using important type selector that overrides other rules"
  },
];

discreteTests.forEach(testcase => {
  test(t => {
    if (testcase.skip) {
      return;
    }
    addStyle(t, testcase.stylesheet);

    const div = addDiv(t, { "id": "target" });
    if (testcase.attributes) {
      for (let attributeName in testcase.attributes) {
        div.setAttribute(attributeName, testcase.attributes[attributeName]);
      }
    }
    div.style.animation = "keyframes 100s";

    const keyframes = div.getAnimations()[0].effect.getKeyframes();
    const expectedKeyframes = testcase.expectedKeyframes;
    assert_equals(keyframes.length, expectedKeyframes.length,
                  `keyframes.length should be ${ expectedKeyframes.length }`);

    keyframes.forEach((keyframe, index) => {
      const expectedKeyframe = expectedKeyframes[index];
      assert_equals(keyframe.computedOffset, expectedKeyframe.computedOffset,
                    `computedOffset of keyframes[${ index }] should be ` +
                    `${ expectedKeyframe.computedOffset }`);
      assert_equals(keyframe.alignContent, expectedKeyframe.alignContent,
                    `alignContent of keyframes[${ index }] should be ` +
                    `${ expectedKeyframe.alignContent }`);
    });
  }, testcase.explanation);
});

</script>
</body>