gecko-dev/testing/web-platform/tests/animation-worklet/current-time.https.html
Yi Gu f1d01111a8 Bug 1527487 [wpt PR 15344] - [Animation Worklet] Clean up animator registration logic for wpt test, a=testonly
Automatic update from web-platform-tests
[Animation Worklet] Clean up animator registration logic for wpt test

Similar to [1], we should register the animator only once in the setup
for test current-time.https.html.

Given that DocumentTimeline does not always move forward, this test
also replaces waitForNextFrame with waitForDocumentTimelineAdvance.

[1] https://cs.chromium.org/chromium/src/third_party/blink/web_tests/external/wpt/animation-worklet/scroll-timeline-writing-modes.https.html

Bug: 923881
Change-Id: Iabc6c7c1cea520e3dd81ed8a781cc072e2d8e20b
Reviewed-on: https://chromium-review.googlesource.com/c/1466145
Commit-Queue: Yi Gu <yigu@chromium.org>
Reviewed-by: Majid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631287}

--

wpt-commits: 109654d2560bf74830e483fdf15cbbc67208a877
wpt-pr: 15344
2019-03-16 12:12:29 +00:00

64 lines
2 KiB
HTML

<!DOCTYPE html>
<meta charset=utf-8>
<title>The current time of a worklet animation</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>
<div id="box"></div>
<script>
'use strict';
function CreateAnimation() {
const box = document.getElementById('box');
const effect = new KeyframeEffect(
box,
{ height: ['100px', '50px'] },
10000);
return new WorkletAnimation('passthrough', effect);
}
setup(setupAndRegisterTests, {explicit_done: true});
function setupAndRegisterTests() {
registerPassthroughAnimator().then(() => {
promise_test(async t => {
const animation = CreateAnimation();
animation.play();
assert_equals(animation.currentTime, 0,
'Current time returns the hold time set when entering the play-pending' +
'state');
animation.cancel();
}, 'The current time returns the hold time when set');
promise_test(async t => {
const animation = CreateAnimation();
animation.play();
// Allow one async animation frame to pass so that animation is running.
await waitForAsyncAnimationFrames(1);
assert_equals(animation.playState, "running");
// Allow time to advance so that we have a non-zero current time.
await waitForDocumentTimelineAdvance();
const timelineTime = document.timeline.currentTime;
assert_greater_than(animation.currentTime, 0);
assert_times_equal(animation.currentTime, (timelineTime - animation.startTime));
animation.cancel();
}, 'The current time is calculated from the timeline time and start time');
done();
});
}
// TODO(majidvp): Add tests for playbackRate and animations that are not
// associated with a timeline once these are supported in WorkletAnimation.
// http://crbug.com/833846
</script>