summaryrefslogtreecommitdiffstats
path: root/ui/compositor/layer_animator_unittest.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 23:06:45 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 23:06:45 +0000
commite81480f1fd21a75545b1c5dda31a1e7c8abf847f (patch)
tree8d641760c07be0b750e8ab019e7849b097769774 /ui/compositor/layer_animator_unittest.cc
parentf3b63bc8ea7b4ef0aa474fde036a526c7ef68d59 (diff)
downloadchromium_src-e81480f1fd21a75545b1c5dda31a1e7c8abf847f.zip
chromium_src-e81480f1fd21a75545b1c5dda31a1e7c8abf847f.tar.gz
chromium_src-e81480f1fd21a75545b1c5dda31a1e7c8abf847f.tar.bz2
Adds ability to animate the color of a layer.
BUG=155179 TEST=none R=vollick@chromium.org Review URL: https://codereview.chromium.org/11103037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/compositor/layer_animator_unittest.cc')
-rw-r--r--ui/compositor/layer_animator_unittest.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc
index d60fc319..d1219a15 100644
--- a/ui/compositor/layer_animator_unittest.cc
+++ b/ui/compositor/layer_animator_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/stringprintf.h"
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/layer_animation_delegate.h"
@@ -23,6 +24,14 @@ namespace ui {
namespace {
+// Converts |color| to a string. Each component of the color is separated by a
+// space and the order if A R G B.
+std::string ColorToString(SkColor color) {
+ return base::StringPrintf("%d %d %d %d", SkColorGetA(color),
+ SkColorGetR(color), SkColorGetG(color),
+ SkColorGetB(color));
+}
+
class TestImplicitAnimationObserver : public ImplicitAnimationObserver {
public:
explicit TestImplicitAnimationObserver(bool notify_when_animator_destructed)
@@ -1164,6 +1173,45 @@ TEST(LayerAnimatorTest, GetTargetGrayscale) {
}
}
+// Verifies color property is modified appropriately.
+TEST(LayerAnimatorTest, Color) {
+ scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
+ AnimationContainerElement* element = animator.get();
+ animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ animator->SetDelegate(&delegate);
+
+ SkColor start_color = SkColorSetARGB( 0, 20, 40, 60);
+ SkColor middle_color = SkColorSetARGB(127, 30, 60, 100);
+ SkColor target_color = SkColorSetARGB(254, 40, 80, 140);
+
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+
+ delegate.SetColorFromAnimation(start_color);
+
+ animator->ScheduleAnimation(
+ new LayerAnimationSequence(
+ LayerAnimationElement::CreateColorElement(target_color, delta)));
+
+ EXPECT_TRUE(animator->is_animating());
+ EXPECT_EQ(ColorToString(start_color),
+ ColorToString(delegate.GetColorForAnimation()));
+
+ base::TimeTicks start_time = animator->last_step_time();
+
+ element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
+
+ EXPECT_TRUE(animator->is_animating());
+ EXPECT_EQ(ColorToString(middle_color),
+ ColorToString(delegate.GetColorForAnimation()));
+
+ element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
+
+ EXPECT_FALSE(animator->is_animating());
+ EXPECT_EQ(ColorToString(target_color),
+ ColorToString(delegate.GetColorForAnimation()));
+}
+
// Verifies SchedulePauseForProperties().
TEST(LayerAnimatorTest, SchedulePauseForProperties) {
scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());