summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-properties-values-api/at-property-animation.html
blob: 233b63239fc3b4a9b8d07cb24e8e4d405ad7c6ca (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api-1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/utils.js"></script>
<div id=outer>
  <div id=div></div>
</div>
<script>

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    @keyframes test {
      from { ${name}: 100px; }
      to { ${name}: 200px; }
    }
    #div { animation: test 100s -50s linear; }
  `, () => {
    assert_equals(getComputedStyle(div).getPropertyValue(name), '150px');
  });
}, '@keyframes works with @property');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    @property ${name} {
      syntax: "<color>";
      inherits: false;
      initial-value: black;
    }
    @keyframes test {
      from { ${name}: rgb(100, 100, 100); }
      to { ${name}: rgb(200, 200, 200); }
    }
    #div { animation: test 100s -50s linear; }
  `, () => {
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(150, 150, 150)');
  });
}, '@keyframes picks up the latest @property in the document');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  // These keyframes are initially invalid for the declared custom property.
  let animation = div.animate([
    { [name]: 'rgb(100, 100, 100)'},
    { [name]: 'rgb(200, 200, 200)'},
  ], { duration: 10000, delay: -5000, easing: 'linear' });
  let cs = getComputedStyle(div);
  assert_equals(cs.getPropertyValue(name), '0px');

  // Redeclare the property as a <color>, effectively making the existing
  // keyframes valid.
  with_at_property({
    name: name,
    syntax: '"<color>"',
    inherits: false,
    initialValue: 'black'
  }, (name) => {
    assert_equals(cs.getPropertyValue(name), 'rgb(150, 150, 150)');
  });

  animation.finish();
}, 'Ongoing animation picks up redeclared custom property');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  // These keyframes are initially invalid for the declared custom property.
  let animation = div.animate([
    { [name]: 'rgb(100, 100, 100)'},
    { [name]: 'rgb(200, 200, 200)'},
  ], { duration: 10000, delay: -5000, easing: 'linear' });
  let cs = getComputedStyle(div);
  assert_equals(cs.getPropertyValue(name), '0px');

  // Setting the keyframes to something that matches <length> makes the
  // interpolation valid.
  animation.effect.setKeyframes([
    {[name]: '100px'},
    {[name]: '200px'}
  ]);
  assert_equals(cs.getPropertyValue(name), '150px');

  animation.finish();
}, 'Ongoing animation matches new keyframes against the current registration');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  let animation = div.animate([
    { [name]: 'initial'},
    { [name]: '400px'},
  ], { duration: 10000, delay: -5000, easing: 'linear' });
  let cs = getComputedStyle(div);
  assert_equals(cs.getPropertyValue(name), '200px');

  // Change initial value.
  with_at_property({
    name: name,
    syntax: '"<length>"',
    inherits: false,
    initialValue: '100px'
  }, (name) => {
    assert_equals(cs.getPropertyValue(name), '250px');
  });

  animation.finish();
}, 'Ongoing animation picks up redeclared intial value');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  try {
    document.body.style = `${name}: 100px`;
    // Note that 'inherit' here refers to #outer, which has the initial
    // value. (#outer did not inherit from body, since the property is not
    // yet declared as inherited).
    let animation = div.animate([
      { [name]: 'inherit'},
      { [name]: '400px'},
    ], { duration: 10000, delay: -5000, easing: 'linear' });
    let cs = getComputedStyle(div);
    assert_equals(cs.getPropertyValue(name), '200px');

    // Change inherits to 'true'. The value should now propagate from body
    // to #outer.
    with_at_property({
      name: name,
      syntax: '"<length>"',
      inherits: true,
      initialValue: '0px'
    }, (name) => {
      assert_equals(cs.getPropertyValue(name), '250px');
    });

    animation.finish();
  } finally {
    document.body.style = '';
  }
}, 'Ongoing animation picks up redeclared inherits flag');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  try {
    outer.style = `${name}: 100px`;
    // 'unset' should take the initial value (not the value from #outer), since
    // the property is not declared as inherited.
    let animation = div.animate([
      { [name]: 'unset'},
      { [name]: '400px'},
    ], { duration: 10000, delay: -5000, easing: 'linear' });
    let cs = getComputedStyle(div);
    assert_equals(cs.getPropertyValue(name), '200px');

    // Change inherits to 'true'. 'unset' now refers to #outer's value.
    with_at_property({
      name: name,
      syntax: '"<length>"',
      inherits: true,
      initialValue: '0px'
    }, (name) => {
      assert_equals(cs.getPropertyValue(name), '250px');
    });

    animation.finish();
  } finally {
    outer.style = '';
  }
}, 'Ongoing animation picks up redeclared meaning of \'unset\'');

test_with_at_property({
  syntax: '"<color>"',
  inherits: false,
  initialValue: 'red'
}, (name) => {
  try {
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(255, 0, 0)');
    div.style = `transition: ${name} steps(2, start) 100s; ${name}: blue`;
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(128, 0, 128)');
  } finally {
    div.style = '';
  }
}, 'Transitioning from initial value');

test_with_at_property({
  syntax: '"<color>"',
  inherits: false,
  initialValue: 'red'
}, (name) => {
  try {
    div.style = `${name}: blue;`;
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(0, 0, 255)');
    div.style = `transition: ${name} steps(2, start) 100s; ${name}: green`;
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(0, 64, 128)');
  } finally {
    div.style = '';
  }
}, 'Transitioning from specified value');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '100px'
}, (name) => {
    with_style_node(`div { transition: ${name} steps(2, start) 100s; }`, () => {
      assert_equals(getComputedStyle(div).getPropertyValue(name), '100px');
      // Re-declaring the property with a different initial value effectively
      // means the computed value has changed. This means we should transition
      // from the old initial value to the new initial value.
      with_at_property({
        name: name,
        syntax: '"<length>"',
        inherits: false,
        initialValue: '200px'
      }, () => {
        assert_equals(getComputedStyle(div).getPropertyValue(name), '150px');
      });
    });
}, 'Transition triggered by initial value change');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '100px'
}, (name) => {
    with_style_node(`div { transition: ${name} steps(2, start) 100s; }`, () => {
      assert_equals(getComputedStyle(div).getPropertyValue(name), '100px');
      with_at_property({
        name: name,
        syntax: '"<color>"',
        inherits: false,
        initialValue: 'green'
      }, () => {
        assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(0, 128, 0)');
      });
    });
}, 'No transition when changing types');

test(() => {
  let name = generate_name();
  with_style_node(`div { ${name}: 100px; transition: ${name} steps(2, start) 100s; }`, () => {
    assert_equals(getComputedStyle(div).getPropertyValue(name), '100px');

    let style1 = document.createElement('style');
    style1.textContent = `
      @property ${name} {
        syntax: "<length>";
        inherits: false;
        initial-value: 200px;
      }
    `;

    let style2 = document.createElement('style');
    style2.textContent = `div { ${name}: 400px; }`;

    try {
      // Register the property:
      document.body.append(style1);
      // The token sequence ' 100px' is now interpreted as a length '100px'.
      assert_equals(getComputedStyle(div).getPropertyValue(name), '100px');

      // Change the computed value:
      document.body.append(style2);
      // This should cause an interpolation between 100px and 400px:
      assert_equals(getComputedStyle(div).getPropertyValue(name), '250px');

      // In the middle of the transition above, remove the @property rule
      // (making the computed value a token sequence again). We should snap
      // to the new token sequence.
      style1.remove();
      assert_equals(getComputedStyle(div).getPropertyValue(name), '400px');
    } finally {
      style1.remove();
      style2.remove();
    }
  });
}, 'No transition when removing @property rule');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    @keyframes test {
      from { ${name}: 100px; }
      to { ${name}: 200px; }
    }
    #div {
        animation: test 100s -50s linear;
        --unregistered: var(${name});
    }
  `, () => {
    assert_equals(getComputedStyle(div).getPropertyValue('--unregistered'), '150px');
  });
}, 'Unregistered properties referencing animated properties update correctly.');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    @keyframes test {
      from { ${name}: 100px; }
      to { ${name}: 200px; }
    }
    @property --registered {
        syntax: "<length>";
        inherits: false;
        initialValue: 0px;
    }
    #div {
        animation: test 100s -50s linear;
        --registered: var(${name});
    }
  `, () => {
    assert_equals(getComputedStyle(div).getPropertyValue('--registered'), '150px');
  });
}, 'Registered properties referencing animated properties update correctly.');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    @keyframes test {
      from { ${name}: inherit; }
      to { ${name}: 300px; }
    }
    #outer {
      ${name}: 100px;
    }
    #div {
      animation: test 100s -50s linear paused;
    }
  `, () => {
    assert_equals(getComputedStyle(div).getPropertyValue(name), '200px');

    outer.style.setProperty(name, '200px');
    assert_equals(getComputedStyle(div).getPropertyValue(name), '250px');

    outer.style.setProperty(name, '0px');
    assert_equals(getComputedStyle(div).getPropertyValue(name), '150px');

    outer.style.removeProperty(name);
  });
}, 'CSS animation setting "inherit" for a custom property on a keyframe is responsive to changing that custom property on the parent.');

test_with_at_property({
  syntax: '"<length>"',
  inherits: false,
  initialValue: '0px'
}, (name) => {
  with_style_node(`
    #outer {
      ${name}: 100px;
    }
  `, () => {
    const animation = div.animate({ [name]: ["inherit", "300px"]}, 1000);
    animation.currentTime = 500;
    animation.pause();

    assert_equals(getComputedStyle(div).getPropertyValue(name), '200px');

    outer.style.setProperty(name, '200px');
    assert_equals(getComputedStyle(div).getPropertyValue(name), '250px');

    outer.style.setProperty(name, '0px');
    assert_equals(getComputedStyle(div).getPropertyValue(name), '150px');

    outer.style.removeProperty(name);
  });
}, 'JS-originated animation setting "inherit" for a custom property on a keyframe is responsive to changing that custom property on the parent.');

test_with_at_property({
  syntax: '"<color>"',
  inherits: false,
  initialValue: 'black'
}, (name) => {
  with_style_node(`
    @keyframes test {
      from { ${name}: currentcolor; }
      to { ${name}: rgb(200, 200, 200); }
    }
    #outer {
      color: rgb(100, 100, 100);
    }
    #div {
      animation: test 100s -50s linear paused;
    }
  `, (style) => {
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(150, 150, 150)');

    outer.style.color = 'rgb(50, 50, 50)';
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(125, 125, 125)');

    outer.style.color = 'rgb(150, 150, 150)';
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(175, 175, 175)');

    outer.style.removeProperty("color");
  });
}, 'CSS animation setting "currentColor" for a custom property on a keyframe is responsive to changing "color" on the parent.');

test_with_at_property({
  syntax: '"<color>"',
  inherits: false,
  initialValue: 'black'
}, (name) => {
  with_style_node(`
    #outer {
      color: rgb(100, 100, 100);
    }
  `, () => {
    const animation = div.animate({ [name]: ["currentcolor", "rgb(200, 200, 200)"]}, 1000);
    animation.currentTime = 500;
    animation.pause();

    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(150, 150, 150)');

    outer.style.color = 'rgb(50, 50, 50)';
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(125, 125, 125)');

    outer.style.color = 'rgb(150, 150, 150)';
    assert_equals(getComputedStyle(div).getPropertyValue(name), 'rgb(175, 175, 175)');

    outer.style.removeProperty("color");
  });
}, 'JS-originated animation setting "currentColor" for a custom property on a keyframe is responsive to changing "color" on the parent.');

</script>