Skip to content

Truly independent web browser

Tests/LibWeb: Add a test for replacing animations of other targets

Andreas Kling1be2efa43675
diff --git a/Tests/LibWeb/Text/expected/WebAnimations/remove-replaced-animations-of-other-targets.txt b/Tests/LibWeb/Text/expected/WebAnimations/remove-replaced-animations-of-other-targets.txt
new file mode 100644
index 00000000000..2e184a62540
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/WebAnimations/remove-replaced-animations-of-other-targets.txt
@@ -0,0 +1,4 @@
+first: removed, remove event: true, opacity: 0.5
+second: removed, remove event: true, opacity: 0.25
+earlier of both: removed, remove event: true, opacity: 0.25
+later of both: active, remove event: false, opacity: 0.25
diff --git a/Tests/LibWeb/Text/input/WebAnimations/remove-replaced-animations-of-other-targets.html b/Tests/LibWeb/Text/input/WebAnimations/remove-replaced-animations-of-other-targets.html
new file mode 100644
index 00000000000..52edfb6abca
--- /dev/null
+++ b/Tests/LibWeb/Text/input/WebAnimations/remove-replaced-animations-of-other-targets.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<div id="first"></div>
+<div id="second"></div>
+<div id="both"></div>
+<script>
+ function animationFrame() {
+ return new Promise(resolve => requestAnimationFrame(resolve));
+ }
+
+ function finishedOpacityAnimation(target, opacity) {
+ const animation = target.animate({ opacity: [0, opacity] }, { duration: 1000, fill: "forwards" });
+ animation.finish();
+ animation.removed = false;
+ animation.onremove = () => { animation.removed = true; };
+ return animation;
+ }
+
+ asyncTest(async done => {
+ // An animation is replaced only by animations of the same target that animate the same properties.
+ const ofFirst = finishedOpacityAnimation(first, 0.5);
+ const ofSecond = finishedOpacityAnimation(second, 0.25);
+ const earlierOfBoth = finishedOpacityAnimation(both, 0.5);
+ const laterOfBoth = finishedOpacityAnimation(both, 0.25);
+ await animationFrame();
+ await animationFrame();
+ for (const [name, animation, target] of [
+ ["first", ofFirst, first],
+ ["second", ofSecond, second],
+ ["earlier of both", earlierOfBoth, both],
+ ["later of both", laterOfBoth, both],
+ ]) {
+ println(`${name}: ${animation.replaceState}, remove event: ${animation.removed}, opacity: ${getComputedStyle(target).opacity}`);
+ }
+ done();
+ });
+</script>