OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/animation.h" | 5 #include "app/linear_animation.h" |
6 #include "app/test_animation_delegate.h" | 6 #include "app/test_animation_delegate.h" |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include "base/win_util.h" | 8 #include "base/win_util.h" |
9 #endif | 9 #endif |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 class AnimationTest: public testing::Test { | 12 class AnimationTest: public testing::Test { |
13 private: | 13 private: |
14 MessageLoopForUI message_loop_; | 14 MessageLoopForUI message_loop_; |
15 }; | 15 }; |
16 | 16 |
| 17 namespace { |
| 18 |
17 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
18 // RunAnimation | 20 // RunAnimation |
19 | 21 |
20 class RunAnimation : public Animation { | 22 class RunAnimation : public LinearAnimation { |
21 public: | 23 public: |
22 RunAnimation(int frame_rate, AnimationDelegate* delegate) | 24 RunAnimation(int frame_rate, AnimationDelegate* delegate) |
23 : Animation(frame_rate, delegate) { | 25 : LinearAnimation(frame_rate, delegate) { |
24 } | 26 } |
25 | 27 |
26 virtual void AnimateToState(double state) { | 28 virtual void AnimateToState(double state) { |
27 EXPECT_LE(0.0, state); | 29 EXPECT_LE(0.0, state); |
28 EXPECT_GE(1.0, state); | 30 EXPECT_GE(1.0, state); |
29 } | 31 } |
30 }; | 32 }; |
31 | 33 |
32 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
33 // CancelAnimation | 35 // CancelAnimation |
34 | 36 |
35 class CancelAnimation : public Animation { | 37 class CancelAnimation : public LinearAnimation { |
36 public: | 38 public: |
37 CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate) | 39 CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate) |
38 : Animation(duration, frame_rate, delegate) { | 40 : LinearAnimation(duration, frame_rate, delegate) { |
39 } | 41 } |
40 | 42 |
41 virtual void AnimateToState(double state) { | 43 virtual void AnimateToState(double state) { |
42 if (state >= 0.5) | 44 if (state >= 0.5) |
43 Stop(); | 45 Stop(); |
44 } | 46 } |
45 }; | 47 }; |
46 | 48 |
47 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
| 50 // EndAnimation |
| 51 |
| 52 class EndAnimation : public LinearAnimation { |
| 53 public: |
| 54 EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate) |
| 55 : LinearAnimation(duration, frame_rate, delegate) { |
| 56 } |
| 57 |
| 58 virtual void AnimateToState(double state) { |
| 59 if (state >= 0.5) |
| 60 End(); |
| 61 } |
| 62 }; |
| 63 |
| 64 /////////////////////////////////////////////////////////////////////////////// |
| 65 // DeletingAnimationDelegate |
| 66 |
| 67 // AnimationDelegate implementation that deletes the animation in ended. |
| 68 class DeletingAnimationDelegate : public AnimationDelegate { |
| 69 public: |
| 70 virtual void AnimationEnded(const Animation* animation) { |
| 71 delete animation; |
| 72 MessageLoop::current()->Quit(); |
| 73 } |
| 74 }; |
| 75 |
| 76 } // namespace |
| 77 |
| 78 /////////////////////////////////////////////////////////////////////////////// |
48 // LinearCase | 79 // LinearCase |
49 | 80 |
50 TEST_F(AnimationTest, RunCase) { | 81 TEST_F(AnimationTest, RunCase) { |
51 TestAnimationDelegate ad; | 82 TestAnimationDelegate ad; |
52 RunAnimation a1(150, &ad); | 83 RunAnimation a1(150, &ad); |
53 a1.SetDuration(2000); | 84 a1.SetDuration(2000); |
54 a1.Start(); | 85 a1.Start(); |
55 MessageLoop::current()->Run(); | 86 MessageLoop::current()->Run(); |
56 | 87 |
57 EXPECT_TRUE(ad.finished()); | 88 EXPECT_TRUE(ad.finished()); |
58 EXPECT_FALSE(ad.canceled()); | 89 EXPECT_FALSE(ad.canceled()); |
59 } | 90 } |
60 | 91 |
61 TEST_F(AnimationTest, CancelCase) { | 92 TEST_F(AnimationTest, CancelCase) { |
62 TestAnimationDelegate ad; | 93 TestAnimationDelegate ad; |
63 CancelAnimation a2(2000, 150, &ad); | 94 CancelAnimation a2(2000, 150, &ad); |
64 a2.Start(); | 95 a2.Start(); |
65 MessageLoop::current()->Run(); | 96 MessageLoop::current()->Run(); |
66 | 97 |
67 EXPECT_TRUE(ad.finished()); | 98 EXPECT_TRUE(ad.finished()); |
68 EXPECT_TRUE(ad.canceled()); | 99 EXPECT_TRUE(ad.canceled()); |
69 } | 100 } |
70 | 101 |
| 102 // Lets an animation run, invoking End part way through and make sure we get the |
| 103 // right delegate methods invoked. |
| 104 TEST_F(AnimationTest, EndCase) { |
| 105 TestAnimationDelegate ad; |
| 106 EndAnimation a2(2000, 150, &ad); |
| 107 a2.Start(); |
| 108 MessageLoop::current()->Run(); |
| 109 |
| 110 EXPECT_TRUE(ad.finished()); |
| 111 EXPECT_FALSE(ad.canceled()); |
| 112 } |
| 113 |
| 114 // Runs an animation with a delegate that deletes the animation in end. |
| 115 TEST_F(AnimationTest, DeleteFromEnd) { |
| 116 DeletingAnimationDelegate delegate; |
| 117 RunAnimation* animation = new RunAnimation(150, &delegate); |
| 118 animation->Start(); |
| 119 MessageLoop::current()->Run(); |
| 120 // delegate should have deleted animation. |
| 121 } |
| 122 |
71 TEST_F(AnimationTest, ShouldRenderRichAnimation) { | 123 TEST_F(AnimationTest, ShouldRenderRichAnimation) { |
72 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
73 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { | 125 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { |
74 BOOL result; | 126 BOOL result; |
75 ASSERT_NE( | 127 ASSERT_NE( |
76 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)); | 128 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)); |
77 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION | 129 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION |
78 // value on Vista. | 130 // value on Vista. |
79 EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation()); | 131 EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation()); |
80 } else { | 132 } else { |
81 // On XP, the function should check the SM_REMOTESESSION value. | 133 // On XP, the function should check the SM_REMOTESESSION value. |
82 EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION), | 134 EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION), |
83 Animation::ShouldRenderRichAnimation()); | 135 Animation::ShouldRenderRichAnimation()); |
84 } | 136 } |
85 #else | 137 #else |
86 EXPECT_TRUE(Animation::ShouldRenderRichAnimation()); | 138 EXPECT_TRUE(Animation::ShouldRenderRichAnimation()); |
87 #endif | 139 #endif |
88 } | 140 } |
OLD | NEW |