summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/animation-worklet/worklet-animation-local-time-null-1.https.html
blob: 52727fa6ea49d9f6e8c09b0cbe21c9040438c183 (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
<!DOCTYPE html>
<title>Setting localTime to null means effect does not apply</title>
<link rel="help" href="https://drafts.css-houdini.org/css-animationworklet/">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="common.js"></script>

<style>
.box {
  width: 100px;
  height: 100px;
  background-color: green;
  display: inline-block;
}
</style>

<div>
<div class="box" id="target1"></div>
<div class="box" id="target2"></div>
<div class="box" id="target3"></div>
<div class="box" id="target4"></div>
</div>


<script>
promise_test(async t => {
  await runInAnimationWorklet(`
    registerAnimator("blank_animator", class {
      animate(currentTime, effect) {
        // Unset effect.localTime is equivalent to 'null'
      }
    });
  `);
  const target = document.getElementById('target1');

  const animation = new WorkletAnimation('blank_animator',
    new KeyframeEffect(target,
      [
        { transform: 'translateY(100px)' },
        { transform: 'translateY(200px)' }
      ], {
        duration: 1000,
      }
    )
  );
  animation.play();
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).transform, "none");
}, "A worklet which never sets localTime has no effect.");

promise_test(async t => {
  await runInAnimationWorklet(`
    registerAnimator("null_animator", class {
      animate(currentTime, effect) {
        effect.localTime = null;
      }
    });
  `);
  const target = document.getElementById('target2');

  const animation = new WorkletAnimation('null_animator',
    new KeyframeEffect(target,
      [
        { transform: 'translateY(100px)' },
        { transform: 'translateY(200px)' }
      ], {
        duration: 1000,
      }
    )
  );
  animation.play();
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).transform, "none");
}, "A worklet which sets localTime to null has no effect.");

promise_test(async t => {
  await runInAnimationWorklet(`
    registerAnimator("drop_animator", class {
      animate(currentTime, effect) {
        if (currentTime < 500)
          effect.localTime = 500;
        else if (currentTime < 1000)
          effect.localTime = 0;
        else
          effect.localTime = null;
      }
    });
  `);
  const target = document.getElementById('target3');

  const animation = new WorkletAnimation('drop_animator',
    new KeyframeEffect(target,
      [
        { transform: 'translateY(100px)' },
        { transform: 'translateY(200px)' }
      ], {
        duration: 1000,
      }
    )
  );
  animation.play();
  await waitForAsyncAnimationFrames(5);
  assert_equals(getComputedStyle(target).transform, "matrix(1, 0, 0, 1, 0, 150)",
      "The animation has an effect at first");

  await waitForAnimationFrameWithCondition(() => animation.currentTime > 500);
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).transform, "matrix(1, 0, 0, 1, 0, 100)",
      "The effect correctly changes");

  await waitForAnimationFrameWithCondition(() => animation.currentTime > 1000);
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).transform, "none",
      "The effect stops on nulling of localTime");

}, "A worklet which changes localTime to from a number to null has no effect on transform.");

promise_test(async t => {
  await runInAnimationWorklet(`
    registerAnimator("drop2_animator", class {
      animate(currentTime, effect) {
        if (currentTime < 500)
          effect.localTime = 500;
        else if (currentTime < 1000)
          effect.localTime = 0;
        else
          effect.localTime = null;
      }
    });
  `);
  const target = document.getElementById('target4');

  const animation = new WorkletAnimation('drop2_animator',
    new KeyframeEffect(target,
      [
        { backgroundColor: 'red' },
        { backgroundColor: 'blue' }
      ], {
        duration: 1000,
      }
    )
  );
  animation.play();
  await waitForAsyncAnimationFrames(5);
  assert_equals(getComputedStyle(target).backgroundColor, "rgb(128, 0, 128)",
      "The animation has an effect at first");

  await waitForAnimationFrameWithCondition(() => animation.currentTime > 500);
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)",
      "The effect correctly changes");

  await waitForAnimationFrameWithCondition(() => animation.currentTime > 1000);
  await waitForAsyncAnimationFrames(1);
  assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 128, 0)",
      "The effect stops on nulling of localTime");

}, "A worklet which changes localTime to from a number to null has no effect on backgroundColor.");


</script>