1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/gfx/animation/animation_delegate.h"
7 #include "ui/gfx/animation/linear_animation.h"
8 #include "ui/gfx/animation/test_animation_delegate.h"
11 #include "base/win/windows_version.h"
16 class AnimationTest: public testing::Test {
18 base::MessageLoopForUI message_loop_;
23 ///////////////////////////////////////////////////////////////////////////////
26 class RunAnimation : public LinearAnimation {
28 RunAnimation(int frame_rate, AnimationDelegate* delegate)
29 : LinearAnimation(frame_rate, delegate) {
32 virtual void AnimateToState(double state) OVERRIDE {
33 EXPECT_LE(0.0, state);
34 EXPECT_GE(1.0, state);
38 ///////////////////////////////////////////////////////////////////////////////
41 class CancelAnimation : public LinearAnimation {
43 CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
44 : LinearAnimation(duration, frame_rate, delegate) {
47 virtual void AnimateToState(double state) OVERRIDE {
53 ///////////////////////////////////////////////////////////////////////////////
56 class EndAnimation : public LinearAnimation {
58 EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
59 : LinearAnimation(duration, frame_rate, delegate) {
62 virtual void AnimateToState(double state) OVERRIDE {
68 ///////////////////////////////////////////////////////////////////////////////
69 // DeletingAnimationDelegate
71 // AnimationDelegate implementation that deletes the animation in ended.
72 class DeletingAnimationDelegate : public AnimationDelegate {
74 virtual void AnimationEnded(const Animation* animation) OVERRIDE {
76 base::MessageLoop::current()->Quit();
82 ///////////////////////////////////////////////////////////////////////////////
85 TEST_F(AnimationTest, RunCase) {
86 TestAnimationDelegate ad;
87 RunAnimation a1(150, &ad);
90 base::MessageLoop::current()->Run();
92 EXPECT_TRUE(ad.finished());
93 EXPECT_FALSE(ad.canceled());
96 TEST_F(AnimationTest, CancelCase) {
97 TestAnimationDelegate ad;
98 CancelAnimation a2(2000, 150, &ad);
100 base::MessageLoop::current()->Run();
102 EXPECT_TRUE(ad.finished());
103 EXPECT_TRUE(ad.canceled());
106 // Lets an animation run, invoking End part way through and make sure we get the
107 // right delegate methods invoked.
108 TEST_F(AnimationTest, EndCase) {
109 TestAnimationDelegate ad;
110 EndAnimation a2(2000, 150, &ad);
112 base::MessageLoop::current()->Run();
114 EXPECT_TRUE(ad.finished());
115 EXPECT_FALSE(ad.canceled());
118 // Runs an animation with a delegate that deletes the animation in end.
119 TEST_F(AnimationTest, DeleteFromEnd) {
120 DeletingAnimationDelegate delegate;
121 RunAnimation* animation = new RunAnimation(150, &delegate);
123 base::MessageLoop::current()->Run();
124 // delegate should have deleted animation.
127 TEST_F(AnimationTest, ShouldRenderRichAnimation) {
129 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
132 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0));
133 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION
135 EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation());
137 // On XP, the function should check the SM_REMOTESESSION value.
138 EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION),
139 Animation::ShouldRenderRichAnimation());
142 EXPECT_TRUE(Animation::ShouldRenderRichAnimation());
146 // Test that current value is always 0 after Start() is called.
147 TEST_F(AnimationTest, StartState) {
148 LinearAnimation animation(100, 60, NULL);
149 EXPECT_EQ(0.0, animation.GetCurrentValue());
151 EXPECT_EQ(0.0, animation.GetCurrentValue());
153 EXPECT_EQ(1.0, animation.GetCurrentValue());
155 EXPECT_EQ(0.0, animation.GetCurrentValue());