summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_animation_name.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/server/tests/xpcshell/test_animation_name.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/xpcshell/test_animation_name.js')
-rw-r--r--devtools/server/tests/xpcshell/test_animation_name.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/devtools/server/tests/xpcshell/test_animation_name.js b/devtools/server/tests/xpcshell/test_animation_name.js
new file mode 100644
index 0000000000..e88911334c
--- /dev/null
+++ b/devtools/server/tests/xpcshell/test_animation_name.js
@@ -0,0 +1,93 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test that AnimationPlayerActor.getName returns the right name depending on
+// the type of an animation and the various properties available on it.
+
+const {
+ AnimationPlayerActor,
+} = require("resource://devtools/server/actors/animation.js");
+
+function run_test() {
+ // Mock a window with just the properties the AnimationPlayerActor uses.
+ const window = {};
+ window.MutationObserver = class {
+ constructor() {
+ this.observe = () => {};
+ }
+ };
+ window.Animation = class {
+ constructor() {
+ this.effect = { target: getMockNode() };
+ }
+ };
+
+ window.CSSAnimation = class extends window.Animation {};
+ window.CSSTransition = class extends window.Animation {};
+
+ // Helper to get a mock DOM node.
+ function getMockNode() {
+ return {
+ ownerDocument: {
+ defaultView: window,
+ },
+ };
+ }
+
+ // Objects in this array should contain the following properties:
+ // - desc {String} For logging
+ // - animation {Object} An animation object instantiated from one of the mock
+ // window animation constructors.
+ // - props {Objet} Properties of this object will be added to the animation
+ // object.
+ // - expectedName {String} The expected name returned by
+ // AnimationPlayerActor.getName.
+ const TEST_DATA = [
+ {
+ desc: "Animation with an id",
+ animation: new window.Animation(),
+ props: { id: "animation-id" },
+ expectedName: "animation-id",
+ },
+ {
+ desc: "Animation without an id",
+ animation: new window.Animation(),
+ props: {},
+ expectedName: "",
+ },
+ {
+ desc: "CSSTransition with an id",
+ animation: new window.CSSTransition(),
+ props: { id: "transition-with-id", transitionProperty: "width" },
+ expectedName: "transition-with-id",
+ },
+ {
+ desc: "CSSAnimation with an id",
+ animation: new window.CSSAnimation(),
+ props: { id: "animation-with-id", animationName: "move" },
+ expectedName: "animation-with-id",
+ },
+ {
+ desc: "CSSTransition without an id",
+ animation: new window.CSSTransition(),
+ props: { transitionProperty: "width" },
+ expectedName: "width",
+ },
+ {
+ desc: "CSSAnimation without an id",
+ animation: new window.CSSAnimation(),
+ props: { animationName: "move" },
+ expectedName: "move",
+ },
+ ];
+
+ for (const { desc, animation, props, expectedName } of TEST_DATA) {
+ info(desc);
+ for (const key in props) {
+ animation[key] = props[key];
+ }
+ const actor = new AnimationPlayerActor({}, animation);
+ Assert.equal(actor.getName(), expectedName);
+ }
+}