Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: app/animation_unittest.cc

Issue 6154001: Move animation code to new ui/base/animation directory.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/animation_delegate.h ('k') | app/app.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "app/animation_delegate.h"
6 #include "app/linear_animation.h"
7 #include "app/test_animation_delegate.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 #if defined(OS_WIN)
11 #include "base/win/windows_version.h"
12 #endif
13
14 class AnimationTest: public testing::Test {
15 private:
16 MessageLoopForUI message_loop_;
17 };
18
19 namespace {
20
21 ///////////////////////////////////////////////////////////////////////////////
22 // RunAnimation
23
24 class RunAnimation : public LinearAnimation {
25 public:
26 RunAnimation(int frame_rate, AnimationDelegate* delegate)
27 : LinearAnimation(frame_rate, delegate) {
28 }
29
30 virtual void AnimateToState(double state) {
31 EXPECT_LE(0.0, state);
32 EXPECT_GE(1.0, state);
33 }
34 };
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // CancelAnimation
38
39 class CancelAnimation : public LinearAnimation {
40 public:
41 CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
42 : LinearAnimation(duration, frame_rate, delegate) {
43 }
44
45 virtual void AnimateToState(double state) {
46 if (state >= 0.5)
47 Stop();
48 }
49 };
50
51 ///////////////////////////////////////////////////////////////////////////////
52 // EndAnimation
53
54 class EndAnimation : public LinearAnimation {
55 public:
56 EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
57 : LinearAnimation(duration, frame_rate, delegate) {
58 }
59
60 virtual void AnimateToState(double state) {
61 if (state >= 0.5)
62 End();
63 }
64 };
65
66 ///////////////////////////////////////////////////////////////////////////////
67 // DeletingAnimationDelegate
68
69 // AnimationDelegate implementation that deletes the animation in ended.
70 class DeletingAnimationDelegate : public AnimationDelegate {
71 public:
72 virtual void AnimationEnded(const Animation* animation) {
73 delete animation;
74 MessageLoop::current()->Quit();
75 }
76 };
77
78 } // namespace
79
80 ///////////////////////////////////////////////////////////////////////////////
81 // LinearCase
82
83 TEST_F(AnimationTest, RunCase) {
84 TestAnimationDelegate ad;
85 RunAnimation a1(150, &ad);
86 a1.SetDuration(2000);
87 a1.Start();
88 MessageLoop::current()->Run();
89
90 EXPECT_TRUE(ad.finished());
91 EXPECT_FALSE(ad.canceled());
92 }
93
94 TEST_F(AnimationTest, CancelCase) {
95 TestAnimationDelegate ad;
96 CancelAnimation a2(2000, 150, &ad);
97 a2.Start();
98 MessageLoop::current()->Run();
99
100 EXPECT_TRUE(ad.finished());
101 EXPECT_TRUE(ad.canceled());
102 }
103
104 // Lets an animation run, invoking End part way through and make sure we get the
105 // right delegate methods invoked.
106 TEST_F(AnimationTest, EndCase) {
107 TestAnimationDelegate ad;
108 EndAnimation a2(2000, 150, &ad);
109 a2.Start();
110 MessageLoop::current()->Run();
111
112 EXPECT_TRUE(ad.finished());
113 EXPECT_FALSE(ad.canceled());
114 }
115
116 // Runs an animation with a delegate that deletes the animation in end.
117 TEST_F(AnimationTest, DeleteFromEnd) {
118 DeletingAnimationDelegate delegate;
119 RunAnimation* animation = new RunAnimation(150, &delegate);
120 animation->Start();
121 MessageLoop::current()->Run();
122 // delegate should have deleted animation.
123 }
124
125 TEST_F(AnimationTest, ShouldRenderRichAnimation) {
126 #if defined(OS_WIN)
127 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
128 BOOL result;
129 ASSERT_NE(
130 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0));
131 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION
132 // value on Vista.
133 EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation());
134 } else {
135 // On XP, the function should check the SM_REMOTESESSION value.
136 EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION),
137 Animation::ShouldRenderRichAnimation());
138 }
139 #else
140 EXPECT_TRUE(Animation::ShouldRenderRichAnimation());
141 #endif
142 }
OLDNEW
« no previous file with comments | « app/animation_delegate.h ('k') | app/app.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698