blob: be705f6c8a314ebfe2ad6493ab73e32d102ea68c [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function load() {
window.animation = document.body.animate([]);
runTest();
}
function test()
{
let suite = InspectorTest.createAsyncSuite("Animation.targetChanged");
suite.addTestCase({
name: "Animation.targetChanged.NewTarget",
description: "Should return a valid object for the given animation identifier.",
async test() {
let animations = Array.from(WI.animationManager.animationCollection);
InspectorTest.assert(animations.length === 1, "There should only be one animation.");
let animation = animations[0];
if (!animation) {
throw `Missing animation.`;
return;
}
InspectorTest.assert(animation.animationType === WI.Animation.Type.WebAnimation, "Animation should be a web animation.");
let [oldTarget] = await promisify((callback) => { animation.requestEffectTarget(callback); });
InspectorTest.expectThat(oldTarget instanceof WI.DOMNode, "Animation should have a target.");
InspectorTest.log("Changing target...\n");
await Promise.all([
animation.awaitEvent(WI.Animation.Event.TargetChanged),
InspectorTest.evaluateInPage(`window.animation.effect.target = document.createElement("div")`),
]);
let [newTarget] = await promisify((callback) => { animation.requestEffectTarget(callback); });
InspectorTest.expectThat(newTarget instanceof WI.DOMNode, "Animation should have a target.");
InspectorTest.expectNotEqual(newTarget, oldTarget, "Animation effect should have changed.");
},
});
suite.addTestCase({
name: "Animation.targetChanged.NullTarget",
description: "Should return a valid object for the given animation identifier.",
async test() {
let animations = Array.from(WI.animationManager.animationCollection);
InspectorTest.assert(animations.length === 1, "There should only be one animation.");
let animation = animations[0];
if (!animation) {
throw `Missing animation.`;
return;
}
InspectorTest.assert(animation.animationType === WI.Animation.Type.WebAnimation, "Animation should be a web animation.");
let [oldTarget] = await promisify((callback) => { animation.requestEffectTarget(callback); });
InspectorTest.expectThat(oldTarget instanceof WI.DOMNode, "Animation should have a target.");
InspectorTest.log("Changing target...\n");
await Promise.all([
animation.awaitEvent(WI.Animation.Event.TargetChanged),
InspectorTest.evaluateInPage(`window.animation.effect.target = null`),
]);
let [newTarget] = await promisify((callback) => { animation.requestEffectTarget(callback); });
InspectorTest.expectNull(newTarget, "Animation should not have a target.");
InspectorTest.expectNotEqual(newTarget, oldTarget, "Animation effect should have changed.");
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="load()">
<p>Tests for the Animation.targetChanged event.</p>
</body>
</html>