servo/tests/wpt/web-platform-tests/animation-worklet/worklet-animation-with-fill-mode.https.html

107 lines
3.8 KiB
HTML

<!DOCTYPE html>
<title>Test that worklet animation works with different fill modes</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="common.js"></script>
<style>
.target {
width: 100px;
height: 100px;
background-color: green;
}
</style>
<script>
function CreateTest(target, effect, verify, test_name) {
async_test(t => {
runInAnimationWorklet(
document.getElementById('simple_animate').textContent
).then(_ => {
const animation = new WorkletAnimation('test_animator', effect);
animation.play();
waitTwoAnimationFrames(() => {
// waitTwoAnimationFrames guarantees a compositor frame that could update
// the opacity value in the worklet. Meanwhile, getComputedStyle needs an
// extra frame to fetch the updated value.
window.requestAnimationFrame(t.step_func_done(() => {
verify();
animation.cancel();
}));
});
});
}, test_name);
}
</script>
<script id="simple_animate" type="text/worklet">
registerAnimator("test_animator", class {
animate(currentTime, effect) {
effect.localTime = 2000;
}
});
</script>
<div id="target1" class='target'></div>
<div id="target2" class='target'></div>
<div id="target3" class='target'></div>
<div id="target4" class='target'></div>
<div id="target5" class='target'></div>
<div id="target6" class='target'></div>
<script>
const effect_with_fill_forwards = new KeyframeEffect(
target1,
{ opacity: [0.5, 0] },
{ duration: 1000, fill: 'forwards' });
CreateTest(target1,
effect_with_fill_forwards,
function() { assert_equals(getComputedStyle(target1).opacity, '0'); },
"Effect with fill mode forwards in after phase produces output that is equivalent to effect's end value.");
const effect_without_fill_forwards = new KeyframeEffect(
target2,
{ opacity: [0.5, 0] },
{ duration: 1000 });
CreateTest(target2,
effect_without_fill_forwards,
function() { assert_equals(getComputedStyle(target2).opacity, '1'); },
'Effect without fill mode forwards in after phase (local time beyond end) should deactivate the animation.');
const effect_without_fill_forwards_at_end = new KeyframeEffect(
target3,
{ opacity: [0.5, 0] },
{ duration: 2000 });
CreateTest(target3,
effect_without_fill_forwards_at_end,
function() { assert_equals(getComputedStyle(target3).opacity, '1'); },
'Effect without fill mode in after phase (local time at end) should deactivate the animation.');
const effect_with_fill_backwards = new KeyframeEffect(
target4,
{ opacity: [0.5, 0] },
{ duration: 1000, delay: 2001, fill: 'backwards' });
CreateTest(target4,
effect_with_fill_backwards,
function() { assert_equals(getComputedStyle(target4).opacity, '0.5'); },
"Effect with fill mode backwards in before phase produces output that is equivalent to effect's start value.");
const effect_without_fill_backwards = new KeyframeEffect(
target5,
{ opacity: [0.5, 0] },
{ duration: 1000, delay: 2001 });
CreateTest(target5,
effect_without_fill_backwards,
function() { assert_equals(getComputedStyle(target5).opacity, '1'); },
'Effect without fill mode backwards in before phase (local time before start) should deactivate the animation.');
const effect_without_fill_backwards_at_start = new KeyframeEffect(
target6,
{ opacity: [0.5, 0] },
{ duration: 1000, delay: 2000 });
CreateTest(target6,
effect_without_fill_backwards_at_start,
function() { assert_equals(getComputedStyle(target6).opacity, '0.5'); },
'Effect with local time at start point is in active phase.');
</script>