| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 | |
| 5 <script> | |
| 6 var duration = 100000; | |
| 7 | |
| 8 function assert_unresolved(value) { | |
| 9 assert_equals(value, null); | |
| 10 } | |
| 11 | |
| 12 function idleAnimation() { | |
| 13 var animation = document.documentElement.animate([], duration); | |
| 14 animation.cancel(); | |
| 15 return animation; | |
| 16 } | |
| 17 | |
| 18 function runningAnimation() { | |
| 19 var animation = idleAnimation(); | |
| 20 animation.play(); | |
| 21 animation.startTime = document.timeline.currentTime; | |
| 22 return animation; | |
| 23 } | |
| 24 | |
| 25 function pendingStartTimeAnimation() { | |
| 26 var animation = idleAnimation(); | |
| 27 animation.play(); | |
| 28 return animation; | |
| 29 } | |
| 30 | |
| 31 function pendingStartTimeAndCurrentTimeAnimation() { | |
| 32 var animation = idleAnimation(); | |
| 33 animation.play(); | |
| 34 animation.pause(); | |
| 35 animation.play(); | |
| 36 return animation; | |
| 37 } | |
| 38 | |
| 39 function pausedAnimation() { | |
| 40 var animation = idleAnimation(); | |
| 41 animation.pause(); | |
| 42 animation.currentTime = 0; | |
| 43 return animation; | |
| 44 } | |
| 45 | |
| 46 function finishedAnimation() { | |
| 47 var animation = idleAnimation(); | |
| 48 animation.play(); | |
| 49 animation.finish(); | |
| 50 return animation; | |
| 51 } | |
| 52 | |
| 53 test(function() { | |
| 54 var animation = idleAnimation(); | |
| 55 assert_unresolved(animation.startTime); | |
| 56 assert_unresolved(animation.currentTime); | |
| 57 assert_equals(animation.playState, 'idle'); | |
| 58 }, "idle"); | |
| 59 | |
| 60 test(function() { | |
| 61 var animation = pendingStartTimeAnimation(); | |
| 62 assert_unresolved(animation.startTime); | |
| 63 assert_equals(animation.currentTime, 0); | |
| 64 assert_equals(animation.playState, 'pending'); | |
| 65 }, "pending startTime"); | |
| 66 | |
| 67 test(function() { | |
| 68 var animation = runningAnimation(); | |
| 69 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 70 assert_equals(animation.currentTime, 0); | |
| 71 assert_equals(animation.playState, 'running'); | |
| 72 }, "running"); | |
| 73 | |
| 74 test(function() { | |
| 75 var animation = pausedAnimation(); | |
| 76 assert_unresolved(animation.startTime); | |
| 77 assert_equals(animation.currentTime, 0); | |
| 78 assert_equals(animation.playState, 'paused'); | |
| 79 }, "paused"); | |
| 80 | |
| 81 test(function() { | |
| 82 var animation = finishedAnimation(); | |
| 83 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 84 assert_equals(animation.currentTime, duration); | |
| 85 assert_equals(animation.playState, 'finished'); | |
| 86 }, "finished"); | |
| 87 | |
| 88 test(function() { | |
| 89 var animation = idleAnimation(); | |
| 90 animation.play(); | |
| 91 assert_unresolved(animation.startTime); | |
| 92 assert_equals(animation.currentTime, 0); | |
| 93 assert_equals(animation.playState, 'pending'); | |
| 94 }, "idle -> play()"); | |
| 95 | |
| 96 test(function() { | |
| 97 var animation = idleAnimation(); | |
| 98 animation.pause(); | |
| 99 assert_unresolved(animation.startTime); | |
| 100 assert_equals(animation.currentTime, 0); | |
| 101 assert_equals(animation.playState, 'pending'); | |
| 102 }, "idle -> pause()"); | |
| 103 | |
| 104 test(function() { | |
| 105 var animation = idleAnimation(); | |
| 106 animation.cancel(); | |
| 107 assert_unresolved(animation.startTime); | |
| 108 assert_unresolved(animation.currentTime); | |
| 109 assert_equals(animation.playState, 'idle'); | |
| 110 }, "idle -> cancel()"); | |
| 111 | |
| 112 test(function() { | |
| 113 var animation = idleAnimation(); | |
| 114 animation.finish(); | |
| 115 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 116 assert_equals(animation.currentTime, duration); | |
| 117 assert_equals(animation.playState, 'finished'); | |
| 118 }, "idle -> finish()"); | |
| 119 | |
| 120 test(function() { | |
| 121 var animation = idleAnimation(); | |
| 122 animation.reverse(); | |
| 123 assert_unresolved(animation.startTime); | |
| 124 assert_equals(animation.currentTime, duration); | |
| 125 assert_equals(animation.playState, 'pending'); | |
| 126 }, "idle -> reverse()"); | |
| 127 | |
| 128 test(function() { | |
| 129 var animation = idleAnimation(); | |
| 130 animation.currentTime = 1000; | |
| 131 assert_unresolved(animation.startTime); | |
| 132 assert_equals(animation.currentTime, 1000); | |
| 133 assert_equals(animation.playState, 'paused'); | |
| 134 }, "idle -> set currentTime"); | |
| 135 | |
| 136 test(function() { | |
| 137 var animation = idleAnimation(); | |
| 138 animation.startTime = document.timeline.currentTime - 1000; | |
| 139 assert_equals(animation.startTime, document.timeline.currentTime - 1000); | |
| 140 assert_equals(animation.currentTime, 1000); | |
| 141 assert_equals(animation.playState, 'running'); | |
| 142 }, "idle -> set startTime"); | |
| 143 | |
| 144 test(function() { | |
| 145 var animation = pendingStartTimeAnimation(); | |
| 146 animation.play(); | |
| 147 assert_unresolved(animation.startTime); | |
| 148 assert_equals(animation.currentTime, 0); | |
| 149 assert_equals(animation.playState, 'pending'); | |
| 150 }, "pending startTime -> play()"); | |
| 151 | |
| 152 test(function() { | |
| 153 var animation = pendingStartTimeAnimation(); | |
| 154 animation.pause(); | |
| 155 assert_unresolved(animation.startTime); | |
| 156 assert_equals(animation.currentTime, 0); | |
| 157 assert_equals(animation.playState, 'pending'); | |
| 158 }, "pending startTime -> pause()"); | |
| 159 | |
| 160 test(function() { | |
| 161 var animation = pendingStartTimeAnimation(); | |
| 162 animation.cancel(); | |
| 163 assert_unresolved(animation.startTime); | |
| 164 assert_unresolved(animation.currentTime); | |
| 165 assert_equals(animation.playState, 'idle'); | |
| 166 }, "pending startTime -> cancel()"); | |
| 167 | |
| 168 test(function() { | |
| 169 var animation = pendingStartTimeAnimation(); | |
| 170 animation.finish(); | |
| 171 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 172 assert_equals(animation.currentTime, duration); | |
| 173 assert_equals(animation.playState, 'finished'); | |
| 174 }, "pending startTime -> finish()"); | |
| 175 | |
| 176 test(function() { | |
| 177 var animation = pendingStartTimeAnimation(); | |
| 178 animation.reverse(); | |
| 179 assert_unresolved(animation.startTime); | |
| 180 assert_equals(animation.currentTime, duration); | |
| 181 assert_equals(animation.playState, 'pending'); | |
| 182 }, "pending startTime -> reverse()"); | |
| 183 | |
| 184 test(function() { | |
| 185 var animation = pendingStartTimeAnimation(); | |
| 186 animation.currentTime = 1000; | |
| 187 assert_unresolved(animation.startTime); | |
| 188 assert_equals(animation.currentTime, 1000); | |
| 189 assert_equals(animation.playState, 'pending'); | |
| 190 }, "pending startTime -> set currentTime"); | |
| 191 | |
| 192 test(function() { | |
| 193 var animation = pendingStartTimeAnimation(); | |
| 194 animation.startTime = document.timeline.currentTime - 1000; | |
| 195 assert_equals(animation.startTime, document.timeline.currentTime - 1000); | |
| 196 assert_equals(animation.currentTime, 1000); | |
| 197 assert_equals(animation.playState, 'running'); | |
| 198 }, "pending startTime -> set startTime"); | |
| 199 | |
| 200 test(function() { | |
| 201 var animation = runningAnimation(); | |
| 202 var startTime = animation.startTime; | |
| 203 var currentTime = animation.currentTime; | |
| 204 animation.play(); | |
| 205 assert_equals(animation.startTime, startTime); | |
| 206 assert_equals(animation.currentTime, currentTime); | |
| 207 assert_equals(animation.playState, 'running'); | |
| 208 }, "running -> play()"); | |
| 209 | |
| 210 test(function() { | |
| 211 var animation = runningAnimation(); | |
| 212 animation.pause(); | |
| 213 assert_unresolved(animation.startTime); | |
| 214 assert_equals(animation.currentTime, 0); | |
| 215 assert_equals(animation.playState, 'pending'); | |
| 216 }, "running -> pause()"); | |
| 217 | |
| 218 test(function() { | |
| 219 var animation = runningAnimation(); | |
| 220 animation.cancel(); | |
| 221 assert_unresolved(animation.startTime); | |
| 222 assert_unresolved(animation.currentTime); | |
| 223 assert_equals(animation.playState, 'idle'); | |
| 224 }, "running -> cancel()"); | |
| 225 | |
| 226 test(function() { | |
| 227 var animation = runningAnimation(); | |
| 228 animation.finish(); | |
| 229 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 230 assert_equals(animation.currentTime, duration); | |
| 231 assert_equals(animation.playState, 'finished'); | |
| 232 }, "running -> finish()"); | |
| 233 | |
| 234 test(function() { | |
| 235 var animation = runningAnimation(); | |
| 236 animation.reverse(); | |
| 237 assert_unresolved(animation.startTime); | |
| 238 assert_equals(animation.currentTime, duration); | |
| 239 assert_equals(animation.playState, 'pending'); | |
| 240 }, "running -> reverse()"); | |
| 241 | |
| 242 test(function() { | |
| 243 var animation = runningAnimation(); | |
| 244 animation.currentTime = 1000; | |
| 245 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 246 assert_equals(animation.currentTime, 1000); | |
| 247 assert_equals(animation.playState, 'running'); | |
| 248 }, "running -> set currentTime"); | |
| 249 | |
| 250 test(function() { | |
| 251 var animation = runningAnimation(); | |
| 252 animation.startTime = document.timeline.currentTime - 1000; | |
| 253 assert_equals(animation.startTime, document.timeline.currentTime - 1000); | |
| 254 assert_equals(animation.currentTime, 1000); | |
| 255 assert_equals(animation.playState, 'running'); | |
| 256 }, "running -> set startTime"); | |
| 257 | |
| 258 test(function() { | |
| 259 var animation = pausedAnimation(); | |
| 260 animation.play(); | |
| 261 assert_unresolved(animation.startTime); | |
| 262 assert_equals(animation.currentTime, 0); | |
| 263 assert_equals(animation.playState, 'pending'); | |
| 264 }, "paused -> play()"); | |
| 265 | |
| 266 test(function() { | |
| 267 var animation = pausedAnimation(); | |
| 268 animation.pause(); | |
| 269 assert_unresolved(animation.startTime); | |
| 270 assert_equals(animation.currentTime, 0); | |
| 271 assert_equals(animation.playState, 'paused'); | |
| 272 }, "paused -> pause()"); | |
| 273 | |
| 274 test(function() { | |
| 275 var animation = pausedAnimation(); | |
| 276 animation.cancel(); | |
| 277 assert_unresolved(animation.startTime); | |
| 278 assert_unresolved(animation.currentTime); | |
| 279 assert_equals(animation.playState, 'idle'); | |
| 280 }, "paused -> cancel()"); | |
| 281 | |
| 282 test(function() { | |
| 283 var animation = pausedAnimation(); | |
| 284 animation.finish(); | |
| 285 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 286 assert_equals(animation.currentTime, duration); | |
| 287 assert_equals(animation.playState, 'finished'); | |
| 288 }, "paused -> finish()"); | |
| 289 | |
| 290 test(function() { | |
| 291 var animation = pausedAnimation(); | |
| 292 animation.reverse(); | |
| 293 assert_unresolved(animation.startTime); | |
| 294 assert_equals(animation.currentTime, duration); | |
| 295 assert_equals(animation.playState, 'pending'); | |
| 296 }, "paused -> reverse()"); | |
| 297 | |
| 298 test(function() { | |
| 299 var animation = pausedAnimation(); | |
| 300 animation.currentTime = 1000; | |
| 301 assert_unresolved(animation.startTime); | |
| 302 assert_equals(animation.currentTime, 1000); | |
| 303 assert_equals(animation.playState, 'paused'); | |
| 304 }, "paused -> set currentTime"); | |
| 305 | |
| 306 test(function() { | |
| 307 var animation = pausedAnimation(); | |
| 308 animation.startTime = document.timeline.currentTime - 1000; | |
| 309 assert_equals(animation.startTime, document.timeline.currentTime - 1000); | |
| 310 assert_equals(animation.currentTime, 1000); | |
| 311 assert_equals(animation.playState, 'running'); | |
| 312 }, "paused -> set startTime"); | |
| 313 | |
| 314 test(function() { | |
| 315 var animation = finishedAnimation(); | |
| 316 animation.play(); | |
| 317 assert_unresolved(animation.startTime); | |
| 318 assert_equals(animation.currentTime, 0); | |
| 319 assert_equals(animation.playState, 'pending'); | |
| 320 }, "finished -> play()"); | |
| 321 | |
| 322 test(function() { | |
| 323 var animation = finishedAnimation(); | |
| 324 animation.pause(); | |
| 325 assert_unresolved(animation.startTime); | |
| 326 assert_equals(animation.currentTime, duration); | |
| 327 assert_equals(animation.playState, 'pending'); | |
| 328 }, "finished -> pause()"); | |
| 329 | |
| 330 test(function() { | |
| 331 var animation = finishedAnimation(); | |
| 332 animation.cancel(); | |
| 333 assert_unresolved(animation.startTime); | |
| 334 assert_unresolved(animation.currentTime); | |
| 335 assert_equals(animation.playState, 'idle'); | |
| 336 }, "finished -> cancel()"); | |
| 337 | |
| 338 test(function() { | |
| 339 var animation = finishedAnimation(); | |
| 340 animation.finish(); | |
| 341 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 342 assert_equals(animation.currentTime, duration); | |
| 343 assert_equals(animation.playState, 'finished'); | |
| 344 }, "finished -> finish()"); | |
| 345 | |
| 346 test(function() { | |
| 347 var animation = finishedAnimation(); | |
| 348 animation.reverse(); | |
| 349 assert_unresolved(animation.startTime); | |
| 350 assert_equals(animation.currentTime, duration); | |
| 351 assert_equals(animation.playState, 'pending'); | |
| 352 }, "finished -> reverse()"); | |
| 353 | |
| 354 test(function() { | |
| 355 var animation = finishedAnimation(); | |
| 356 animation.currentTime = 1000; | |
| 357 assert_equals(animation.startTime, document.timeline.currentTime - animation.c
urrentTime); | |
| 358 assert_equals(animation.currentTime, 1000); | |
| 359 assert_equals(animation.playState, 'running'); | |
| 360 }, "finished -> set currentTime"); | |
| 361 | |
| 362 { | |
| 363 let test = async_test("pending (play) -> ready.then()"); | |
| 364 let animation = idleAnimation(); | |
| 365 animation.play(); | |
| 366 let animationCurrentTime = animation.currentTime; | |
| 367 let timelineCurrentTime = document.timeline.currentTime; | |
| 368 animation.ready.then(() => { | |
| 369 test.step(() => { | |
| 370 assert_equals(animation.playState, 'running'); | |
| 371 assert_greater_than_equal(animation.startTime, timelineCurrentTime); | |
| 372 assert_greater_than_equal(animation.currentTime, animationCurrentTime); | |
| 373 }); | |
| 374 test.done(); | |
| 375 }); | |
| 376 } | |
| 377 | |
| 378 { | |
| 379 let test = async_test("pending (pause) -> ready.then()"); | |
| 380 let animation = runningAnimation(); | |
| 381 animation.pause(); | |
| 382 let animationCurrentTime = animation.currentTime; | |
| 383 animation.ready.then(() => { | |
| 384 test.step(() => { | |
| 385 assert_equals(animation.playState, 'paused'); | |
| 386 assert_unresolved(animation.startTime); | |
| 387 assert_greater_than_equal(animation.currentTime, animationCurrentTime); | |
| 388 }); | |
| 389 test.done(); | |
| 390 }); | |
| 391 } | |
| 392 </script> | |
| OLD | NEW |