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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Updating the finished state</title>
<link rel="help" href="https://drafts.csswg.org/web-animations/#updating-the-finished-state">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="testcommon.js"></script>
<style>
.scroller {
overflow: auto;
height: 100px;
width: 100px;
will-change: transform;
}
.contents {
height: 1000px;
width: 100%;
}
</style>
<body>
<script>
'use strict';
// --------------------------------------------------------------------
//
// TESTS FOR UPDATING THE HOLD TIME
//
// --------------------------------------------------------------------
// CASE 1: playback rate > 0 and current time >= target effect end
// (Also the start time is resolved and there is pending task)
// Did seek = true
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
await anim.ready;
anim.currentTime = CSS.percent(200);
scroller.scrollTop = 0.7 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 200,
'Hold time is set so current time should NOT change');
}, 'Updating the finished state when seeking past end');
// Did seek = false
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
await anim.ready;
scroller.scrollTop = maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 100,
'Hold time is set to target end clamping current time');
}, 'Updating the finished state when playing exactly to end');
// Did seek = true
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
await anim.ready;
anim.currentTime = CSS.percent(100);
scroller.scrollTop = 0.7 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 100,
'Hold time is set so current time should NOT change');
}, 'Updating the finished state when seeking exactly to end');
// CASE 2: playback rate < 0 and current time <= 0
// (Also the start time is resolved and there is pending task)
// Did seek = false
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.playbackRate = -1;
anim.play(); // Make sure animation is not initially finished
await anim.ready;
// Seek to 1ms before 0 and then wait 1ms
anim.currentTime = CSS.percent(1);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 0,
'Hold time is set to zero clamping current time');
}, 'Updating the finished state when playing in reverse past zero');
// Did seek = true
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.playbackRate = -1;
anim.play();
await anim.ready;
anim.currentTime = CSS.percent(-100);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, -100,
'Hold time is set so current time should NOT change');
}, 'Updating the finished state when seeking a reversed animation past zero');
// Did seek = false
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.playbackRate = -1;
anim.play();
await anim.ready;
scroller.scrollTop = maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 0,
'Hold time is set to target end clamping current time');
}, 'Updating the finished state when playing a reversed animation exactly ' +
'to zero');
// Did seek = true
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.playbackRate = -1;
anim.play();
await anim.ready;
anim.currentTime = CSS.percent(0);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 0,
'Hold time is set so current time should NOT change');
}, 'Updating the finished state when seeking a reversed animation exactly ' +
'to zero');
// CASE 3: playback rate > 0 and current time < target end OR
// playback rate < 0 and current time > 0
// (Also the start time is resolved and there is pending task)
// Did seek = true; playback rate > 0
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.finish();
await anim.ready;
assert_percents_equal(anim.startTime, -100);
anim.currentTime = CSS.percent(50);
// When did seek = true, updating the finished state: (i) updates
// the animation's start time and (ii) clears the hold time.
// We can test both by checking that the currentTime is initially
// updated and then increases.
assert_percents_equal(anim.currentTime, 50, 'Start time is updated');
assert_percents_equal(anim.startTime, -50);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 70,
'Hold time is not set so current time should increase');
}, 'Updating the finished state when seeking before end');
// Did seek = false; playback rate < 0
//
// Unfortunately it is not possible to test this case. We need to have
// a hold time set, a resolved start time, and then perform some
// operation that updates the finished state with did seek set to true.
//
// However, the only situation where this could arrive is when we
// replace the timeline and that procedure is likely to change. For all
// other cases we either have an unresolved start time (e.g. when
// paused), we don't have a set hold time (e.g. regular playback), or
// the current time is zero (and anything that gets us out of that state
// will set did seek = true).
// Did seek = true; playback rate < 0
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.playbackRate = -1;
await anim.ready;
anim.currentTime = CSS.percent(50);
assert_percents_equal(anim.startTime, 50, 'Start time is updated');
assert_percents_equal(anim.currentTime, 50, 'Current time is updated');
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 30,
'Hold time is not set so current time should decrease');
}, 'Updating the finished state when seeking a reversed animation before end');
// CASE 4: playback rate == 0
// current time < 0
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.playbackRate = 0;
await anim.ready;
anim.currentTime = CSS.percent(-100);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, -100,
'Hold time should not be cleared so current time should NOT change');
}, 'Updating the finished state when playback rate is zero and the current ' +
'time is less than zero');
// current time < target end
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.playbackRate = 0;
await anim.ready;
anim.currentTime = CSS.percent(50);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 50,
'Hold time should not be cleared so current time should NOT change');
}, 'Updating the finished state when playback rate is zero and the current ' +
'time is less than end');
// current time > target end
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.playbackRate = 0;
await anim.ready;
anim.currentTime = CSS.percent(200);
scroller.scrollTop = 0.2 * maxScroll;
await waitForNextFrame();
assert_percents_equal(anim.currentTime, 200,
'Hold time should not be cleared so current time should NOT change');
}, 'Updating the finished state when playback rate is zero and the current' +
'time is greater than end');
// CASE 5: current time unresolved
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.play();
anim.cancel();
// Trigger a change that will cause the "update the finished state"
// procedure to run.
anim.effect.updateTiming({ duration: 2000 });
assert_equals(anim.currentTime, null,
'The animation hold time / start time should not be updated');
// The "update the finished state" procedure is supposed to run after any
// change to timing, but just in case an implementation defers that, let's
// wait a frame and check that the hold time / start time has still not been
// updated.
await waitForAnimationFrames(1);
assert_equals(anim.currentTime, null,
'The animation hold time / start time should not be updated');
}, 'Updating the finished state when current time is unresolved');
// CASE 7: start time unresolved
// Did seek = true
promise_test(async t => {
const anim = createScrollLinkedAnimation(t);
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
anim.cancel();
anim.currentTime = CSS.percent(150);
// Trigger a change that will cause the "update the finished state"
// procedure to run.
anim.currentTime = CSS.percent(50);
assert_percents_equal(anim.currentTime, 50,
'The animation hold time should not be updated');
assert_equals(anim.startTime, null,
'The animation start time should not be updated');
}, 'Updating the finished state when start time is unresolved and did seek = ' +
'true');
// --------------------------------------------------------------------
//
// TESTS FOR RUNNING FINISH NOTIFICATION STEPS
//
// --------------------------------------------------------------------
function waitForFinishEventAndPromise(animation) {
const eventPromise = new Promise(resolve => {
animation.onfinish = resolve;
});
return Promise.all([eventPromise, animation.finished]);
}
promise_test(t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
animation.onfinish =
t.unreached_func('Seeking to finish should not fire finish event');
animation.finished.then(
t.unreached_func(
'Seeking to finish should not resolve finished promise'));
animation.currentTime = CSS.percent(100);
animation.currentTime = CSS.percent(0);
animation.pause();
scroller.scrollTop = 0.2 * maxScroll;
return waitForAnimationFrames(3);
}, 'Finish notification steps don\'t run when the animation seeks to finish ' +
'and then seeks back again');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
await animation.ready;
scroller.scrollTop = maxScroll;
return waitForFinishEventAndPromise(animation);
}, 'Finish notification steps run when the animation completes normally');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.effect.target = null;
animation.play();
await animation.ready;
scroller.scrollTop = maxScroll;
return waitForFinishEventAndPromise(animation);
}, 'Finish notification steps run when an animation without a target effect ' +
'completes normally');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
animation.play();
await animation.ready;
animation.currentTime = CSS.percent(101);
return waitForFinishEventAndPromise(animation);
}, 'Finish notification steps run when the animation seeks past finish');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
animation.play();
await animation.ready;
// Register for notifications now since once we seek away from being
// finished the 'finished' promise will be replaced.
const finishNotificationSteps = waitForFinishEventAndPromise(animation);
animation.finish();
animation.currentTime = CSS.percent(0);
animation.pause();
return finishNotificationSteps;
}, 'Finish notification steps run when the animation completes with ' +
'.finish(), even if we then seek away');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
scroller.scrollTop = maxScroll;
const initialFinishedPromise = animation.finished;
await animation.finished;
animation.currentTime = CSS.percent(0);
assert_not_equals(initialFinishedPromise, animation.finished);
}, 'Animation finished promise is replaced after seeking back to start');
promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
const initialFinishedPromise = animation.finished;
scroller.scrollTop = maxScroll;
await animation.finished;
scroller.scrollTop = 0;
await waitForNextFrame();
animation.play();
assert_not_equals(initialFinishedPromise, animation.finished);
}, 'Animation finished promise is replaced after replaying from start');
async_test(t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
animation.onfinish = event => {
scroller.scrollTop = 0;
window.requestAnimationFrame(function() {
window.requestAnimationFrame(function() {
scroller.scrollTop = maxScroll;
});
});
animation.onfinish = event => {
t.done();
};
};
scroller.scrollTop = maxScroll;
}, 'Animation finish event is fired again after seeking back to start');
async_test(t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
animation.play();
animation.onfinish = event => {
scroller.scrollTop = 0;
window.requestAnimationFrame(function() {
animation.play();
scroller.scrollTop = maxScroll;
animation.onfinish = event => {
t.done();
};
});
};
scroller.scrollTop = maxScroll;
}, 'Animation finish event is fired again after replaying from start');
async_test(t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
anim.effect.updateTiming({ duration: 800, endDelay: 200});
anim.onfinish = t.step_func(event => {
assert_unreached('finish event should not be fired');
});
anim.play();
anim.ready.then(() => {
scroller.scrollTop = 0.9 * maxScroll;
return waitForAnimationFrames(3);
}).then(t.step_func(() => {
t.done();
}));
}, 'finish event is not fired at the end of the active interval when the ' +
'endDelay has not expired');
async_test(t => {
const anim = createScrollLinkedAnimation(t);
const scroller = anim.timeline.source;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
anim.effect.updateTiming({ duration: 800, endDelay: 100});
anim.play();
anim.ready.then(() => {
scroller.scrollTop = 0.95 * maxScroll; // during endDelay
anim.onfinish = t.step_func(event => {
assert_unreached('onfinish event should not be fired during endDelay');
});
return waitForAnimationFrames(2);
}).then(t.step_func(() => {
anim.onfinish = t.step_func(event => {
t.done();
});
scroller.scrollTop = maxScroll;
return waitForAnimationFrames(2);
}));
}, 'finish event is fired after the endDelay has expired');
</script>
</body>
|