summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-animations/interfaces/Animation/onremove.html
blob: 1a41a3d21c1768cff4289e3cb497937ac4a81f43 (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
<!DOCTYPE html>
<meta charset=utf-8>
<title>Animation.onremove</title>
<link rel="help" href="https://drafts.csswg.org/web-animations/#dom-animation-onremove">
<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';

async_test(t => {
  const div = createDiv(t);
  const animA = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });
  const animB = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });

  let finishedTimelineTime = null;
  animB.onfinish = event => {
    finishedTimelineTime = event.timelineTime;
  };

  animA.onremove = t.step_func_done(event => {
    assert_equals(animA.replaceState, 'removed');
    assert_equals(event.currentTime, 1);
    assert_true(finishedTimelineTime != null, 'finished event fired');
    assert_equals(event.timelineTime, finishedTimelineTime,
                'timeline time is set');
  });

}, 'onremove event is fired when replaced animation is removed.');

promise_test(async t => {
  const div = createDiv(t);
  const animA = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });
  const animB = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });
  const animC = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });
  const animD = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });

  const removed = [];

  animA.onremove = () => { removed.push('A'); };
  animB.onremove = () => { removed.push('B'); };
  animC.onremove = () => { removed.push('C'); };

  animD.onremove = event => {
    assert_unreached('onremove event should not be fired');
  };

  await waitForAnimationFrames(2);

  assert_equals(removed.join(''), 'ABC');

}, 'onremove events are fired in the correct order');

</script>
</body>