Skip to content

Commit

Permalink
Bug 1631850 [wpt PR 23145] - Initialize start time of scroll animatio…
Browse files Browse the repository at this point in the history
…ns to zero., a=testonly

Automatic update from web-platform-tests
Initialize start time of scroll animations to zero.

Implemented web-animations-1 spec changes introduces in [1].

- Update play and pause procedures to initialize start time of scroll
  animations to zero.
- Updated calculate play state procedure to return "running" state for
  animations that has start time resolved.
- Added/modified tests reflecting spec changes.

[1] w3c/csswg-drafts#4842

Bug: 1070637
Change-Id: Ic83995899b2f3f8d8f985f84b8a2b438bbad7c35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150687
Commit-Queue: Olga Gerchikov <gerchiko@microsoft.com>
Reviewed-by: Majid Valipour <majidvp@chromium.org>
Reviewed-by: Kevin Ellis <kevers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761974}

--

wpt-commits: 46978682c5d3e2ff08468be05564307a9a75e06b
wpt-pr: 23145
  • Loading branch information
ogerchikov committed Apr 28, 2020
1 parent 7df46f4 commit e71485f
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 42 deletions.
Expand Up @@ -89,6 +89,10 @@
endScrollOffset: {target: end, ...config.end }
});

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();

const animation = createScrollLinkedAnimation(t, timeline);
const scrollRange = end.offsetTop - start.offsetTop;
const timeRange = animation.timeline.timeRange;
Expand All @@ -100,11 +104,12 @@
"The start time is null in Idle state.");

animation.play();
assert_true(animation.pending, "Animation is in pending state.");
// Verify initial start and current times in Pending state.
assert_times_equal(animation.currentTime, 0,
"The current time is a hold time in Pending state.");
assert_equals(animation.startTime, null,
"The start time is null in Pending state.");
"The current time is zero in Pending state.");
assert_equals(animation.startTime, 0,
"The start time is zero in Pending state.");

await animation.ready;
// Verify initial start and current times in Playing state.
Expand Down
@@ -0,0 +1,144 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test basic functionality of scroll linked animation.</title>
<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;
}
.contents {
height: 1000px;
width: 100%;
}
</style>
<div id="log"></div>
<script>
'use strict';

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
// Make the scroll timeline inactive.
scroller.style.overflow = 'visible';
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
// Play the animation when the timeline is inactive.
animation.play();
assert_equals(animation.currentTime, null,
'The current time is null when the timeline is inactive.');
assert_equals(animation.startTime, 0,
'The start time is zero in Pending state.');
await waitForNextFrame();
assert_true(animation.pending,
'Animation has play pending task while the timeline is inactive.');
assert_equals(animation.playState, 'running',
'State is \'running\' in Pending state.');
}, 'Play pending task doesn\'t run when the timeline is inactive.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
// Make the scroll timeline inactive.
scroller.style.overflow = 'visible';
// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
// Play the animation when the timeline is inactive.
animation.play();

// Make the scroll timeline active.
scroller.style.overflow = 'auto';
await animation.ready;
// Ready promise is resolved as a result of the timeline becoming active.
assert_equals(animation.currentTime, 0,
'Animation current time is resolved when the animation is ready.');
assert_equals(animation.startTime, 0,
'Animation start time is resolved when the animation is ready.');
}, 'Animation start and current times are correct if scroll timeline is ' +
'activated after animation.play call.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
const target = animation.effect.target;
// Advance the scroller.
scroller.scrollTop = 0.2 * maxScroll;

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
// Play the animation when the timeline is active.
animation.play();
await animation.ready;

// Make the scroll timeline inactive.
scroller.style.overflow = 'visible';
scroller.scrollTop;
await waitForNextFrame();
assert_equals(animation.playState, 'running',
'State is \'running\' when the timeline is inactive.');
assert_equals(animation.currentTime, null,
'Current time is unresolved when the timeline is inactive.');
assert_equals(animation.startTime, 0,
'Start time is zero when the timeline is inactive.');
assert_equals(
animation.effect.getComputedTiming().localTime,
null,
'Effect local time is null when the timeline is inactive.');
assert_equals(Number(getComputedStyle(target).opacity), 1,
'Animation does not have an effect when the timeline is inactive.');

// Make the scroll timeline active.
scroller.style.overflow = 'auto';
await waitForNextFrame();

assert_equals(animation.playState, 'running',
'State is \'running\' when the timeline is active.');
assert_equals(animation.currentTime, 200,
'Current time is resolved when the timeline is active.');
assert_equals(animation.startTime, 0,
'Start time is zero when the timeline is active.');
assert_times_equal(
animation.effect.getComputedTiming().localTime,
200,
'Effect local time is resolved when the timeline is active.');
assert_equals(Number(getComputedStyle(target).opacity), 0.2,
'Animation has an effect when the timeline is active.');
}, 'Animation current time is correct when the timeline becomes newly ' +
'inactive and then active again.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
scroller.scrollTop;

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
animation.play();
await animation.ready;

// Make the scroll timeline inactive.
scroller.style.overflow = 'visible';
scroller.scrollTop;
await waitForNextFrame();

const eventWatcher = new EventWatcher(t, animation, 'cancel');
animation.cancel();
const cancelEvent = await eventWatcher.wait_for('cancel');

assert_equals(cancelEvent.currentTime, null,
'event.currentTime should be unresolved when the timeline is inactive.');
assert_equals(cancelEvent.timelineTime, null,
'event.timelineTime should be unresolved when the timeline is inactive');
}, 'oncancel event is fired when the timeline is inactive.');


</script>
52 changes: 16 additions & 36 deletions testing/web-platform/tests/scroll-animations/scroll-animation.html
Expand Up @@ -23,19 +23,23 @@
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
const timeRange = animation.timeline.timeRange;

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();

// Verify initial start and current times in Idle state.
assert_equals(animation.currentTime, null,
"The current time is null in Idle state.");
assert_equals(animation.startTime, null,
"The start time is null in Idle state.");
animation.play();
assert_true(animation.pending, "Animation is in pending state.");
// Verify initial start and current times in Pending state.
assert_equals(animation.currentTime, 0,
"The current time is a hold time in Pending state.");
assert_equals(animation.startTime, null,
"The start time is null in Pending state.");
"The current time is zero in Pending state.");
assert_equals(animation.startTime, 0,
"The start time is zero in Pending state.");

await animation.ready;
// Verify initial start and current times in Playing state.
Expand All @@ -62,7 +66,7 @@
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
const timeRange = animation.timeline.timeRange;

// Advance the scroller.
scroller.scrollTop = 0.2 * maxScroll;
// Wait for new animation frame which allows the timeline to compute new
Expand All @@ -78,8 +82,8 @@
// Verify initial start and current times in Pending state.
assert_equals(animation.currentTime, animation.timeline.currentTime,
"The current time is a hold time in Pending state.");
assert_equals(animation.startTime, null,
"The start time is null in Pending state.");
assert_equals(animation.startTime, 0,
"The start time is zero in Pending state.");

await animation.ready;
// Verify initial start and current times in Playing state.
Expand All @@ -96,7 +100,7 @@
const animation2 = createScrollLinkedAnimation(t, timeline);
const scroller = timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
const timeRange = timeline.timeRange;

// Advance the scroller.
scroller.scrollTop = 0.2 * maxScroll;
// Wait for new animation frame which allows the timeline to compute new
Expand All @@ -118,13 +122,13 @@
assert_equals(animation1.currentTime, timeline.currentTime,
"The current time corresponds to the scroll position of the scroller" +
" in Pending state.");
assert_equals(animation1.startTime, null,
"The start time is null in Pending state.");
assert_equals(animation1.startTime, 0,
"The start time is zero in Pending state.");
assert_equals(animation2.currentTime, timeline.currentTime,
"The current time corresponds to the scroll position of the scroller" +
" in Pending state.");
assert_equals(animation2.startTime, null,
"The start time is null in Pending state.");
assert_equals(animation2.startTime, 0,
"The start time is zero in Pending state.");

await animation1.ready;
await animation2.ready;
Expand All @@ -140,30 +144,6 @@
}, 'Animation start and current times are correct when multiple animations' +
' are attached to the same timeline.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
// Make the scroll timeline inactive.
scroller.style.overflow = "visible";
// Trigger layout;
scroller.scrollTop;
assert_equals(animation.timeline.currentTime, null,
"Timeline current time is null in inactive state.");
// Play the animation when the timeline is inactive.
animation.play();
// Make the scroll timeline active.
scroller.style.overflow = "auto";
await animation.ready;
// Ready promise is resolved as a result of the timeline becoming active.
assert_equals(animation.timeline.currentTime, 0,
"Timeline current time is resolved in active state.");
assert_equals(animation.currentTime, 0,
"Animation current time is resolved when the animation is ready.");
assert_equals(animation.startTime, 0,
"Animation start time is resolved when the animation is ready.");
}, 'Animation start and current times are correct if scroll timeline is ' +
'activated after animation.play call.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;
Expand Down
Expand Up @@ -223,5 +223,71 @@
" source has been scrolled."
);
}, 'Set Animation current time then scroll.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
animation.play();
await animation.ready;

// Make the timeline inactive.
scroller.style.overflow = 'visible';
scroller.scrollTop;
await waitForNextFrame();

assert_equals(animation.currentTime, null,
'Current time is unresolved when the timeline is inactive.');

animation.currentTime = 300;
assert_equals(animation.currentTime, 300,
'Animation current time should be equal to the set value.');
assert_equals(animation.playState, 'paused',
'Animation play state is \'paused\' when current time is set and ' +
'timeline is inactive.');
}, 'Animation current time and play state are correct when current time is ' +
'set while the timeline is inactive.');

promise_test(async t => {
const animation = createScrollLinkedAnimation(t);
const scroller = animation.timeline.scrollSource;

// Wait for new animation frame which allows the timeline to compute new
// current time.
await waitForNextFrame();
animation.play();
await animation.ready;

// Make the timeline inactive.
scroller.style.overflow = 'visible';
scroller.scrollTop;
await waitForNextFrame();

assert_equals(animation.timeline.currentTime, null,
'Current time is unresolved when the timeline is inactive.');

animation.currentTime = 300;
assert_equals(animation.currentTime, 300,
'Animation current time should be equal to the set value.');
assert_equals(animation.playState, 'paused',
'Animation play state is \'paused\' when current time is set and ' +
'timeline is inactive.');

// Make the timeline active.
scroller.style.overflow = 'auto';
scroller.scrollTop;
await waitForNextFrame();

assert_equals(animation.timeline.currentTime, 0,
'Current time is resolved when the timeline is active.');
assert_equals(animation.currentTime, 300,
'Animation current time holds the set value.');
assert_equals(animation.playState, 'paused',
'Animation holds \'paused\' state.');
}, 'Animation current time set while the timeline is inactive holds when the ' +
'timeline becomes active again.');
</script>
</body>
2 changes: 1 addition & 1 deletion testing/web-platform/tests/scroll-animations/testcommon.js
Expand Up @@ -27,7 +27,7 @@ function createScrollLinkedAnimation(test, timeline) {
if (timeline === undefined)
timeline = createScrollTimeline(test);
const DURATION = 1000; // ms
const KEYFRAMES = { opacity: [1, 0] };
const KEYFRAMES = { opacity: [0, 1] };
return new Animation(
new KeyframeEffect(createDiv(test), KEYFRAMES, DURATION), timeline);
}
Expand Up @@ -31,5 +31,25 @@
});
}, 'reports true -> false when paused');

promise_test(async t => {
const animation =
new Animation(new KeyframeEffect(createDiv(t), null, 100 * MS_PER_SEC),
null);
animation.play();
assert_true(animation.pending);
await waitForAnimationFrames(2);
assert_true(animation.pending);
}, 'reports true -> true when played without a timeline');

promise_test(async t => {
const animation =
new Animation(new KeyframeEffect(createDiv(t), null, 100 * MS_PER_SEC),
null);
animation.pause();
assert_true(animation.pending);
await waitForAnimationFrames(2);
assert_true(animation.pending);
}, 'reports true -> true when paused without a timeline');

</script>
</body>

0 comments on commit e71485f

Please sign in to comment.