Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gfx / animation / animation_unittest.cc
blob779e3ecd78cb0e155a3886a42b21b3e241c517a3
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"
10 #if defined(OS_WIN)
11 #include "base/win/windows_version.h"
12 #endif
14 namespace gfx {
16 class AnimationTest: public testing::Test {
17 private:
18 base::MessageLoopForUI message_loop_;
21 namespace {
23 ///////////////////////////////////////////////////////////////////////////////
24 // RunAnimation
26 class RunAnimation : public LinearAnimation {
27 public:
28 RunAnimation(int frame_rate, AnimationDelegate* delegate)
29 : LinearAnimation(frame_rate, delegate) {
32 void AnimateToState(double state) override {
33 EXPECT_LE(0.0, state);
34 EXPECT_GE(1.0, state);
38 ///////////////////////////////////////////////////////////////////////////////
39 // CancelAnimation
41 class CancelAnimation : public LinearAnimation {
42 public:
43 CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
44 : LinearAnimation(duration, frame_rate, delegate) {
47 void AnimateToState(double state) override {
48 if (state >= 0.5)
49 Stop();
53 ///////////////////////////////////////////////////////////////////////////////
54 // EndAnimation
56 class EndAnimation : public LinearAnimation {
57 public:
58 EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
59 : LinearAnimation(duration, frame_rate, delegate) {
62 void AnimateToState(double state) override {
63 if (state >= 0.5)
64 End();
68 ///////////////////////////////////////////////////////////////////////////////
69 // DeletingAnimationDelegate
71 // AnimationDelegate implementation that deletes the animation in ended.
72 class DeletingAnimationDelegate : public AnimationDelegate {
73 public:
74 void AnimationEnded(const Animation* animation) override {
75 delete animation;
76 base::MessageLoop::current()->Quit();
80 } // namespace
82 ///////////////////////////////////////////////////////////////////////////////
83 // LinearCase
85 TEST_F(AnimationTest, RunCase) {
86 TestAnimationDelegate ad;
87 RunAnimation a1(150, &ad);
88 a1.SetDuration(2000);
89 a1.Start();
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);
99 a2.Start();
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);
111 a2.Start();
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);
122 animation->Start();
123 base::MessageLoop::current()->Run();
124 // delegate should have deleted animation.
127 TEST_F(AnimationTest, ShouldRenderRichAnimation) {
128 #if defined(OS_WIN)
129 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
130 BOOL result;
131 ASSERT_NE(
132 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0));
133 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION
134 // value on Vista.
135 EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation());
136 } else {
137 // On XP, the function should check the SM_REMOTESESSION value.
138 EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION),
139 Animation::ShouldRenderRichAnimation());
141 #else
142 EXPECT_TRUE(Animation::ShouldRenderRichAnimation());
143 #endif
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());
150 animation.Start();
151 EXPECT_EQ(0.0, animation.GetCurrentValue());
152 animation.End();
153 EXPECT_EQ(1.0, animation.GetCurrentValue());
154 animation.Start();
155 EXPECT_EQ(0.0, animation.GetCurrentValue());
158 } // namespace gfx