From ce8bd98e0577ebbe8b9e9d3b41cba809f10e6727 Mon Sep 17 00:00:00 2001 From: Patrick Brosset Date: Tue, 2 Feb 2016 11:49:22 +0100 Subject: [PATCH] Bug 1231945 - Display animation.id when it exists; r=tromey --- devtools/server/actors/animation.js | 10 ++-- devtools/server/tests/browser/animation.html | 28 ++++++++++ devtools/server/tests/browser/browser.ini | 1 + .../tests/browser/browser_animation_name.js | 51 +++++++++++++++++++ 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 devtools/server/tests/browser/browser_animation_name.js diff --git a/devtools/server/actors/animation.js b/devtools/server/actors/animation.js index 3fe5ab4efa4..ea4928e5d03 100644 --- a/devtools/server/actors/animation.js +++ b/devtools/server/actors/animation.js @@ -138,13 +138,15 @@ var AnimationPlayerActor = ActorClass({ }, /** - * Get the name associated with the player. This is used to match - * up the player with values in the computed animation-name or - * transition-property property. + * Get the name of this animation. This can be either the animation.id + * property if it was set, or the keyframe rule name or the transition + * property. * @return {String} */ getName: function() { - if (this.isAnimation()) { + if (this.player.id) { + return this.player.id; + } else if (this.isAnimation()) { return this.player.animationName; } else if (this.isTransition()) { return this.player.transitionProperty; diff --git a/devtools/server/tests/browser/animation.html b/devtools/server/tests/browser/animation.html index f310bb13b61..90cec7bf7b4 100644 --- a/devtools/server/tests/browser/animation.html +++ b/devtools/server/tests/browser/animation.html @@ -145,6 +145,19 @@ width: 100px; } } + + .script-generated { + display: inline-block; + + width: 50px; + height: 50px; + border-radius: 50%; + background-color: black; + background-image: + repeating-linear-gradient(45deg, transparent 0, transparent 5px, #f06 5px, #f06 10px); + border: 5px solid #f06; + box-sizing: border-box; + }
@@ -157,11 +170,26 @@
+
diff --git a/devtools/server/tests/browser/browser.ini b/devtools/server/tests/browser/browser.ini index eedbb99131a..35d46842e2d 100644 --- a/devtools/server/tests/browser/browser.ini +++ b/devtools/server/tests/browser/browser.ini @@ -28,6 +28,7 @@ support-files = [browser_animation_getStateAfterFinished.js] [browser_animation_getSubTreeAnimations.js] [browser_animation_keepFinished.js] +[browser_animation_name.js] [browser_animation_playerState.js] [browser_animation_playPauseIframe.js] [browser_animation_playPauseSeveral.js] diff --git a/devtools/server/tests/browser/browser_animation_name.js b/devtools/server/tests/browser/browser_animation_name.js new file mode 100644 index 00000000000..d598f48cc12 --- /dev/null +++ b/devtools/server/tests/browser/browser_animation_name.js @@ -0,0 +1,51 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that the AnimationPlayerActor provides the correct name for an +// animation. Whether this animation is a CSSAnimation, CSSTransition or a +// script-based animation that has been given an id, or even a CSSAnimation that +// has been given an id. + +const TEST_DATA = [{ + selector: ".simple-animation", + animationIndex: 0, + expectedName: "move" +}, { + selector: ".transition", + animationIndex: 0, + expectedName: "width" +}, { + selector: ".script-generated", + animationIndex: 0, + expectedName: "custom-animation-name" +}, { + selector: ".delayed-animation", + animationIndex: 0, + expectedName: "cssanimation-custom-name" +}]; + +add_task(function*() { + let {client, walker, animations} = + yield initAnimationsFrontForUrl(MAIN_DOMAIN + "animation.html"); + + for (let {selector, animationIndex, expectedName} of TEST_DATA) { + let {name} = yield getAnimationStateForNode(walker, animations, selector, + animationIndex); + is(name, expectedName, "The animation has the expected name"); + } + + yield closeDebuggerClient(client); + gBrowser.removeCurrentTab(); +}); + +function* getAnimationStateForNode(walker, animations, nodeSelector, index) { + let node = yield walker.querySelector(walker.rootNode, nodeSelector); + let players = yield animations.getAnimationPlayersForNode(node); + let player = players[index]; + yield player.ready(); + let state = yield player.getCurrentState(); + return state; +}