mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
96 lines
3.6 KiB
HTML
96 lines
3.6 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="/web-animations/testcommon.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) {
|
|
promise_test(async function() {
|
|
await registerConstantLocalTimeAnimator(2000);
|
|
const animation = new WorkletAnimation('constant_time', effect);
|
|
animation.play();
|
|
|
|
await waitForAsyncAnimationFrames(1);
|
|
// 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.
|
|
await waitForNextFrame();
|
|
verify();
|
|
animation.cancel();
|
|
}, test_name);
|
|
}
|
|
</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>
|