<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<title>Test simple animation with fill modes</title>
<style type="text/css" media="screen">
.box {
position: relative;
left: 100px;
top: 10px;
height: 100px;
width: 100px;
animation-delay: 0.1s;
animation-duration: 0.1s;
animation-timing-function: linear;
animation-play-state: paused;
animation-name: anim;
}
@keyframes anim {
from { left: 200px; }
to { left: 300px; }
}
#a {
background-color: blue;
animation-fill-mode: none;
}
#b {
background-color: red;
animation-fill-mode: backwards;
}
#c {
background-color: green;
animation-fill-mode: forwards;
}
#d {
background-color: yellow;
animation-fill-mode: both;
}
#e {
background-color: #999;
animation-fill-mode: both;
animation-iteration-count: 2;
animation-direction: alternate;
}
</style>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="text/javascript" charset="utf-8">
"use strict";
const expectedValues = [
{id: "a", start: 100, end: 100},
{id: "b", start: 200, end: 100},
{id: "c", start: 100, end: 300},
{id: "d", start: 200, end: 300},
{id: "e", start: 200, end: 200}
];
async_test(t => {
function endTest() {
for (var i=0; i < expectedValues.length; i++) {
var el = document.getElementById(expectedValues[i].id);
var expectedValue = expectedValues[i].end;
var realValue = parseFloat(window.getComputedStyle(el).left);
assert_equals(realValue, expectedValue,
`end of animation - id: ${expectedValues[i].id} expected: ` +
`${expectedValue} actual: ${realValue}`);
}
t.done();
}
window.addEventListener("load", t.step_func(() => {
for (var i=0; i < expectedValues.length; i++) {
var el = document.getElementById(expectedValues[i].id);
var expectedValue = expectedValues[i].start;
var realValue = parseFloat(window.getComputedStyle(el).left);
assert_equals(realValue, expectedValue,
`start of animation - id: ${expectedValues[i].id} expected: ` +
`${expectedValue} actual: ${realValue}`);
}
// We start each animation in a paused state and play only after the initial
// snapshot to prevent a test flake.
let promises = [];
document.getAnimations().forEach(anim => {
anim.play();
promises.push(anim.finished);
});
Promise.all(promises).then(endTest);
}));
}, 'This test performs an animation of the left property with four different fill modes. It animates over 0.1 second with a 0.1 second delay. It takes snapshots at document load and the end of the animation');
</script>
<div id="a" class="box">
None
</div>
<div id="b" class="box">
Backwards
</div>
<div id="c" class="box">
Forwards
</div>
<div id="d" class="box">
Both
</div>
<div id="e" class="box">
Both iterating
</div>