summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-animations/CSSAnimation-pausing.tentative.html
blob: 156a1afa964de12e4a983c032f9b526b5cdf625d (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
<!doctype html>
<meta charset=utf-8>
<title>Pausing a CSSAnimation</title>
<link rel="help"
      href="https://drafts.csswg.org/css-animations-2/#animation-play-state">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/testcommon.js"></script>
<style>
@keyframes anim {
  0% { margin-left: 0px }
  100% { margin-left: 10000px }
}
</style>
<div id="log"></div>
<script>
'use strict';

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 1000s paused';

  const animation = div.getAnimations()[0];
  animation.play();

  await animation.ready;
  await waitForNextFrame();

  assert_equals(
    animation.playState,
    'running',
    'Play state is running after calling play()'
  );

  // Flip the animation-play-state back and forth to check it has no effect

  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;
  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'running',
    'Should still be running even after flipping the animation-play-state'
  );
}, 'play() overrides animation-play-state');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s infinite paused';

  const animation = div.getAnimations()[0];
  animation.playbackRate = -1;
  animation.currentTime = -1;

  assert_throws_dom('InvalidStateError', () => {
    animation.play();
  }, 'Trying to play a reversed infinite animation should throw');

  assert_equals(
    animation.playState,
    'paused',
    'Animation should still be paused'
  );

  animation.playbackRate = 1;
  div.style.animationPlayState = 'running';

  assert_equals(
    animation.playState,
    'running',
    'Changing the animation-play-state should play the animation'
  );
}, 'play() does NOT override the animation-play-state if there was an error');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 1000s paused';

  const animation = div.getAnimations()[0];
  animation.pause();

  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;

  await animation.ready;
  await waitForNextFrame();

  assert_equals(animation.playState, 'paused', 'playState is paused ');

  // Flip the animation-play-state back and forth to check it has no effect

  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;
  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'paused',
    'Should still be paused even after flipping the animation-play-state'
  );
}, 'pause() overrides animation-play-state');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s paused';

  const animation = div.getAnimations()[0];
  animation.reverse();

  assert_equals(
    animation.playState,
    'running',
    'Play state is running after calling reverse()'
  );

  // Flip the animation-play-state back and forth to check it has no effect

  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;
  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'running',
    'Should still be running even after flipping the animation-play-state'
  );
}, 'reverse() overrides animation-play-state when it starts playing the'
   + ' animation');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s';

  const animation = div.getAnimations()[0];
  animation.reverse();

  assert_equals(
    animation.playState,
    'running',
    'Play state is running after calling reverse()'
  );

  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'paused',
    'Should be paused after changing the animation-play-state'
  );
}, 'reverse() does NOT override animation-play-state if the animation is'
   + ' already running');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s';

  const animation = div.getAnimations()[0];
  animation.startTime = null;

  assert_equals(
    animation.playState,
    'paused',
    'Play state is paused after setting the start time to null'
  );

  // Flip the animation-play-state back and forth to check it has no effect

  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;
  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'paused',
    'Should still be paused even after flipping the animation-play-state'
  );
}, 'Setting the startTime to null overrides animation-play-state if the'
   + ' animation is already running');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s paused';

  const animation = div.getAnimations()[0];
  animation.startTime = document.timeline.currentTime;

  assert_equals(
    animation.playState,
    'running',
    'Play state is running after setting the start time to non-null'
  );

  // Flip the animation-play-state back and forth to check it has no effect

  div.style.animationPlayState = 'running';
  getComputedStyle(div).animationPlayState;
  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'running',
    'Should still be running even after flipping the animation-play-state'
  );
}, 'Setting the startTime to non-null overrides animation-play-state if the'
   + ' animation is paused');

promise_test(async t => {
  const div = addDiv(t);
  div.style.animation = 'anim 100s';

  const animation = div.getAnimations()[0];
  animation.startTime = document.timeline.currentTime;

  div.style.animationPlayState = 'paused';
  getComputedStyle(div).animationPlayState;

  assert_equals(
    animation.playState,
    'paused',
    'Should be paused after changing the animation-play-state'
  );
}, 'Setting the startTime to non-null does NOT override the'
   + ' animation-play-state if the animation is already running');

promise_test(async t => {
  const div = addDiv(t, { style: 'animation: anim 1000s' });
  const animation = div.getAnimations()[0];
  let readyPromiseRun = false;

  await animation.ready;

  div.style.animationPlayState = 'paused';
  assert_true(animation.pending && animation.playState === 'paused',
              'Animation is pause-pending');

  // Set current time
  animation.currentTime = 5 * MS_PER_SEC;
  assert_equals(animation.playState, 'paused',
                'Animation is paused immediately after setting currentTime');
  assert_equals(animation.startTime, null,
                'Animation startTime is unresolved immediately after ' +
                'setting currentTime');
  assert_equals(animation.currentTime, 5 * MS_PER_SEC,
                'Animation currentTime does not change when forcing a ' +
                'pause operation to complete');

  // The ready promise should now be resolved. If it's not then test will
  // probably time out before anything else happens that causes it to resolve.
  await animation.ready;
}, 'Setting the current time completes a pending pause');

</script>