OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <meta charset=utf-8> | |
3 <title>Test play state changes for animations with a negative playback rate</tit
le> | |
4 <link rel="help" href="http://w3c.github.io/web-animations/#play-state"> | |
5 <script src="../external/wpt/web-animations/testcommon.js"></script> | |
6 <script src="../resources/testharness.js"></script> | |
7 <script src="../resources/testharnessreport.js"></script> | |
8 | |
9 <script> | |
10 var duration = 100000; | |
11 | |
12 function assert_unresolved(value) { | |
13 assert_equals(value, null); | |
14 } | |
15 | |
16 function idleAnimation() { | |
17 var animation = document.documentElement.animate([], duration); | |
18 animation.reverse(); | |
19 animation.cancel(); | |
20 return animation; | |
21 } | |
22 | |
23 function runningAnimation() { | |
24 var animation = idleAnimation(); | |
25 animation.play(); | |
26 animation.startTime = document.timeline.currentTime + duration / 2; | |
27 return animation; | |
28 } | |
29 | |
30 function pendingAnimation() { | |
31 var animation = idleAnimation(); | |
32 animation.play(); | |
33 return animation; | |
34 } | |
35 | |
36 function pausedAnimation() { | |
37 var animation = idleAnimation(); | |
38 animation.pause(); | |
39 animation.currentTime = duration; | |
40 return animation; | |
41 } | |
42 | |
43 function finishedAnimation() { | |
44 var animation = idleAnimation(); | |
45 animation.play(); | |
46 animation.finish(); | |
47 return animation; | |
48 } | |
49 | |
50 test(function() { | |
51 var animation = idleAnimation(); | |
52 assert_unresolved(animation.startTime); | |
53 assert_unresolved(animation.currentTime); | |
54 assert_equals(animation.playState, 'idle'); | |
55 }, "Play state is idle after cancelling a reversed animation"); | |
56 | |
57 test(function() { | |
58 var animation = pendingAnimation(); | |
59 assert_unresolved(animation.startTime); | |
60 assert_equals(animation.currentTime, duration); | |
61 assert_equals(animation.playState, 'pending'); | |
62 }, "Play state is pending after playing a cancelled reversed animation"); | |
63 | |
64 test(function() { | |
65 var animation = runningAnimation(); | |
66 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
67 assert_times_equal(animation.currentTime, duration / 2); | |
68 assert_equals(animation.playState, 'running'); | |
69 }, "Play state is running after playing and setting start time of a cancelled re
versed animation"); | |
70 | |
71 test(function() { | |
72 var animation = pausedAnimation(); | |
73 assert_unresolved(animation.startTime); | |
74 assert_equals(animation.currentTime, duration); | |
75 assert_equals(animation.playState, 'paused'); | |
76 }, "Play state is paused after pausing and setting current time of a cancelled r
eversed animation"); | |
77 | |
78 test(function() { | |
79 var animation = finishedAnimation(); | |
80 assert_equals(animation.startTime, document.timeline.currentTime - (animation.
playbackRate * animation.currentTime)); | |
81 assert_equals(animation.currentTime, 0); | |
82 assert_equals(animation.playState, 'finished'); | |
83 }, "Play state is finished after playing and finishing a cancelled reversed anim
ation"); | |
84 | |
85 test(function() { | |
86 var animation = idleAnimation(); | |
87 animation.play(); | |
88 assert_unresolved(animation.startTime); | |
89 assert_equals(animation.currentTime, duration); | |
90 assert_equals(animation.playState, 'pending'); | |
91 }, "Calling play() on an idle animation"); | |
92 | |
93 test(function() { | |
94 var animation = idleAnimation(); | |
95 animation.pause(); | |
96 assert_unresolved(animation.startTime); | |
97 assert_equals(animation.currentTime, duration); | |
98 assert_equals(animation.playState, 'pending'); | |
99 }, "Calling pause() on an idle animation"); | |
100 | |
101 test(function() { | |
102 var animation = idleAnimation(); | |
103 animation.cancel(); | |
104 assert_unresolved(animation.startTime); | |
105 assert_unresolved(animation.currentTime); | |
106 assert_equals(animation.playState, 'idle'); | |
107 }, "Calling cancel() on an idle animation"); | |
108 | |
109 test(function() { | |
110 var animation = idleAnimation(); | |
111 animation.finish(); | |
112 assert_equals(animation.startTime, document.timeline.currentTime - (animation.
playbackRate * animation.currentTime)); | |
113 assert_equals(animation.currentTime, 0); | |
114 assert_equals(animation.playState, 'finished'); | |
115 }, "Calling finish() on an idle animation"); | |
116 | |
117 test(function() { | |
118 var animation = idleAnimation(); | |
119 animation.reverse(); | |
120 assert_unresolved(animation.startTime); | |
121 assert_equals(animation.currentTime, 0); | |
122 assert_equals(animation.playState, 'pending'); | |
123 }, "Calling reverse() on an idle animation"); | |
124 | |
125 test(function() { | |
126 var animation = idleAnimation(); | |
127 animation.currentTime = 1000; | |
128 assert_unresolved(animation.startTime); | |
129 assert_equals(animation.currentTime, 1000); | |
130 assert_equals(animation.playState, 'paused'); | |
131 }, "Setting currentTime on an idle animation"); | |
132 | |
133 test(function() { | |
134 var animation = idleAnimation(); | |
135 animation.startTime = document.timeline.currentTime + 1000; | |
136 assert_times_equal(animation.startTime, document.timeline.currentTime + 1000); | |
137 assert_times_equal(animation.currentTime, 1000); | |
138 assert_equals(animation.playState, 'running'); | |
139 }, "Setting startTime on an idle animation"); | |
140 | |
141 test(function() { | |
142 var animation = pendingAnimation(); | |
143 animation.play(); | |
144 assert_unresolved(animation.startTime); | |
145 assert_equals(animation.currentTime, duration); | |
146 assert_equals(animation.playState, 'pending'); | |
147 }, "Calling play() on a pending animation"); | |
148 | |
149 test(function() { | |
150 var animation = pendingAnimation(); | |
151 animation.pause(); | |
152 assert_unresolved(animation.startTime); | |
153 assert_equals(animation.currentTime, duration); | |
154 assert_equals(animation.playState, 'pending'); | |
155 }, "Calling pause() on a pending animation"); | |
156 | |
157 test(function() { | |
158 var animation = pendingAnimation(); | |
159 animation.cancel(); | |
160 assert_unresolved(animation.startTime); | |
161 assert_unresolved(animation.currentTime); | |
162 assert_equals(animation.playState, 'idle'); | |
163 }, "Calling cancel() on a pending animation"); | |
164 | |
165 test(function() { | |
166 var animation = pendingAnimation(); | |
167 animation.finish(); | |
168 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
169 assert_equals(animation.currentTime, 0); | |
170 assert_equals(animation.playState, 'finished'); | |
171 }, "Calling finish() on a pending animation"); | |
172 | |
173 test(function() { | |
174 var animation = pendingAnimation(); | |
175 animation.reverse(); | |
176 assert_unresolved(animation.startTime); | |
177 assert_equals(animation.currentTime, 0); | |
178 assert_equals(animation.playState, 'pending'); | |
179 }, "Calling reverse() on a pending animation"); | |
180 | |
181 test(function() { | |
182 var animation = pendingAnimation(); | |
183 animation.currentTime = 1000; | |
184 assert_unresolved(animation.startTime); | |
185 assert_equals(animation.currentTime, 1000); | |
186 assert_equals(animation.playState, 'pending'); | |
187 }, "Setting currentTime on a pending animation"); | |
188 | |
189 test(function() { | |
190 var animation = pendingAnimation(); | |
191 animation.startTime = document.timeline.currentTime + 1000; | |
192 assert_times_equal(animation.startTime, document.timeline.currentTime + 1000); | |
193 assert_times_equal(animation.currentTime, 1000); | |
194 assert_equals(animation.playState, 'running'); | |
195 }, "Setting startTime on a pending animation"); | |
196 | |
197 test(function() { | |
198 var animation = runningAnimation(); | |
199 var startTime = animation.startTime; | |
200 var currentTime = animation.currentTime; | |
201 animation.play(); | |
202 assert_equals(animation.startTime, startTime); | |
203 assert_equals(animation.currentTime, currentTime); | |
204 assert_equals(animation.playState, 'running'); | |
205 }, "Calling play() on a running animation"); | |
206 | |
207 test(function() { | |
208 var animation = runningAnimation(); | |
209 animation.pause(); | |
210 assert_unresolved(animation.startTime); | |
211 assert_times_equal(animation.currentTime, duration / 2); | |
212 assert_equals(animation.playState, 'pending'); | |
213 }, "Calling pause() on a running animation"); | |
214 | |
215 test(function() { | |
216 var animation = runningAnimation(); | |
217 animation.cancel(); | |
218 assert_unresolved(animation.startTime); | |
219 assert_unresolved(animation.currentTime); | |
220 assert_equals(animation.playState, 'idle'); | |
221 }, "Calling cancel() on a running animation"); | |
222 | |
223 test(function() { | |
224 var animation = runningAnimation(); | |
225 animation.finish(); | |
226 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
227 assert_equals(animation.currentTime, 0); | |
228 assert_equals(animation.playState, 'finished'); | |
229 }, "Calling finish() on a running animation"); | |
230 | |
231 test(function() { | |
232 var animation = runningAnimation(); | |
233 animation.reverse(); | |
234 assert_unresolved(animation.startTime); | |
235 assert_times_equal(animation.currentTime, duration / 2); | |
236 assert_equals(animation.playState, 'pending'); | |
237 }, "Calling reverse() on a running animation"); | |
238 | |
239 test(function() { | |
240 var animation = runningAnimation(); | |
241 animation.currentTime = 1000; | |
242 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
243 assert_equals(animation.currentTime, 1000); | |
244 assert_equals(animation.playState, 'running'); | |
245 }, "Setting currentTime on a running animation"); | |
246 | |
247 test(function() { | |
248 var animation = runningAnimation(); | |
249 animation.startTime = document.timeline.currentTime + 1000; | |
250 assert_times_equal(animation.startTime, document.timeline.currentTime + 1000); | |
251 assert_times_equal(animation.currentTime, 1000); | |
252 assert_equals(animation.playState, 'running'); | |
253 }, "Setting startTime on a running animation"); | |
254 | |
255 test(function() { | |
256 var animation = pausedAnimation(); | |
257 animation.play(); | |
258 assert_unresolved(animation.startTime); | |
259 assert_equals(animation.currentTime, duration); | |
260 assert_equals(animation.playState, 'pending'); | |
261 }, "Calling play() on a paused animation"); | |
262 | |
263 test(function() { | |
264 var animation = pausedAnimation(); | |
265 animation.pause(); | |
266 assert_unresolved(animation.startTime); | |
267 assert_equals(animation.currentTime, duration); | |
268 assert_equals(animation.playState, 'paused'); | |
269 }, "Calling pause() on a paused animation"); | |
270 | |
271 test(function() { | |
272 var animation = pausedAnimation(); | |
273 animation.cancel(); | |
274 assert_unresolved(animation.startTime); | |
275 assert_unresolved(animation.currentTime); | |
276 assert_equals(animation.playState, 'idle'); | |
277 }, "Calling cancel() on a paused animation"); | |
278 | |
279 test(function() { | |
280 var animation = pausedAnimation(); | |
281 animation.finish(); | |
282 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
283 assert_equals(animation.currentTime, 0); | |
284 assert_equals(animation.playState, 'finished'); | |
285 }, "Calling finish() on a paused animation"); | |
286 | |
287 test(function() { | |
288 var animation = pausedAnimation(); | |
289 animation.reverse(); | |
290 assert_unresolved(animation.startTime); | |
291 assert_equals(animation.currentTime, 0); | |
292 assert_equals(animation.playState, 'pending'); | |
293 }, "Calling reverse() on a paused animation"); | |
294 | |
295 test(function() { | |
296 var animation = pausedAnimation(); | |
297 animation.currentTime = 1000; | |
298 assert_unresolved(animation.startTime); | |
299 assert_equals(animation.currentTime, 1000); | |
300 assert_equals(animation.playState, 'paused'); | |
301 }, "Setting currentTime on a paused animation"); | |
302 | |
303 test(function() { | |
304 var animation = pausedAnimation(); | |
305 animation.startTime = document.timeline.currentTime + 1000; | |
306 assert_times_equal(animation.startTime, document.timeline.currentTime + 1000); | |
307 assert_times_equal(animation.currentTime, 1000); | |
308 assert_equals(animation.playState, 'running'); | |
309 }, "Setting startTime on a paused animation"); | |
310 | |
311 test(function() { | |
312 var animation = finishedAnimation(); | |
313 animation.play(); | |
314 assert_unresolved(animation.startTime); | |
315 assert_equals(animation.currentTime, duration); | |
316 assert_equals(animation.playState, 'pending'); | |
317 }, "Calling play() on a finished animation"); | |
318 | |
319 test(function() { | |
320 var animation = finishedAnimation(); | |
321 animation.pause(); | |
322 assert_unresolved(animation.startTime); | |
323 assert_equals(animation.currentTime, 0); | |
324 assert_equals(animation.playState, 'pending'); | |
325 }, "Calling pause() on a finished animation"); | |
326 | |
327 test(function() { | |
328 var animation = finishedAnimation(); | |
329 animation.cancel(); | |
330 assert_unresolved(animation.startTime); | |
331 assert_unresolved(animation.currentTime); | |
332 assert_equals(animation.playState, 'idle'); | |
333 }, "Calling cancel() on a finished animation"); | |
334 | |
335 test(function() { | |
336 var animation = finishedAnimation(); | |
337 animation.finish(); | |
338 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
339 assert_equals(animation.currentTime, 0); | |
340 assert_equals(animation.playState, 'finished'); | |
341 }, "Calling finish() on a finished animation"); | |
342 | |
343 test(function() { | |
344 var animation = finishedAnimation(); | |
345 animation.reverse(); | |
346 assert_unresolved(animation.startTime); | |
347 assert_equals(animation.currentTime, 0); | |
348 assert_equals(animation.playState, 'pending'); | |
349 }, "Calling reverse() on a finished animation"); | |
350 | |
351 test(function() { | |
352 var animation = finishedAnimation(); | |
353 animation.currentTime = 1000; | |
354 assert_times_equal(animation.startTime, document.timeline.currentTime - (anima
tion.playbackRate * animation.currentTime)); | |
355 assert_equals(animation.currentTime, 1000); | |
356 assert_equals(animation.playState, 'running'); | |
357 }, "Setting currentTime on a finished animation"); | |
358 </script> | |
OLD | NEW |