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

Side by Side Diff: ui/base/animation/animation_unittest.cc

Issue 14061025: ui: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/base/animation/animation_delegate.h" 6 #include "ui/base/animation/animation_delegate.h"
7 #include "ui/base/animation/linear_animation.h" 7 #include "ui/base/animation/linear_animation.h"
8 #include "ui/base/animation/test_animation_delegate.h" 8 #include "ui/base/animation/test_animation_delegate.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
12 #endif 12 #endif
13 13
14 namespace ui { 14 namespace ui {
15 15
16 class AnimationTest: public testing::Test { 16 class AnimationTest: public testing::Test {
17 private: 17 private:
18 MessageLoopForUI message_loop_; 18 base::MessageLoopForUI message_loop_;
19 }; 19 };
20 20
21 namespace { 21 namespace {
22 22
23 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
24 // RunAnimation 24 // RunAnimation
25 25
26 class RunAnimation : public LinearAnimation { 26 class RunAnimation : public LinearAnimation {
27 public: 27 public:
28 RunAnimation(int frame_rate, AnimationDelegate* delegate) 28 RunAnimation(int frame_rate, AnimationDelegate* delegate)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 }; 66 };
67 67
68 /////////////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////////////
69 // DeletingAnimationDelegate 69 // DeletingAnimationDelegate
70 70
71 // AnimationDelegate implementation that deletes the animation in ended. 71 // AnimationDelegate implementation that deletes the animation in ended.
72 class DeletingAnimationDelegate : public AnimationDelegate { 72 class DeletingAnimationDelegate : public AnimationDelegate {
73 public: 73 public:
74 virtual void AnimationEnded(const Animation* animation) OVERRIDE { 74 virtual void AnimationEnded(const Animation* animation) OVERRIDE {
75 delete animation; 75 delete animation;
76 MessageLoop::current()->Quit(); 76 base::MessageLoop::current()->Quit();
77 } 77 }
78 }; 78 };
79 79
80 } // namespace 80 } // namespace
81 81
82 /////////////////////////////////////////////////////////////////////////////// 82 ///////////////////////////////////////////////////////////////////////////////
83 // LinearCase 83 // LinearCase
84 84
85 TEST_F(AnimationTest, RunCase) { 85 TEST_F(AnimationTest, RunCase) {
86 TestAnimationDelegate ad; 86 TestAnimationDelegate ad;
87 RunAnimation a1(150, &ad); 87 RunAnimation a1(150, &ad);
88 a1.SetDuration(2000); 88 a1.SetDuration(2000);
89 a1.Start(); 89 a1.Start();
90 MessageLoop::current()->Run(); 90 base::MessageLoop::current()->Run();
91 91
92 EXPECT_TRUE(ad.finished()); 92 EXPECT_TRUE(ad.finished());
93 EXPECT_FALSE(ad.canceled()); 93 EXPECT_FALSE(ad.canceled());
94 } 94 }
95 95
96 TEST_F(AnimationTest, CancelCase) { 96 TEST_F(AnimationTest, CancelCase) {
97 TestAnimationDelegate ad; 97 TestAnimationDelegate ad;
98 CancelAnimation a2(2000, 150, &ad); 98 CancelAnimation a2(2000, 150, &ad);
99 a2.Start(); 99 a2.Start();
100 MessageLoop::current()->Run(); 100 base::MessageLoop::current()->Run();
101 101
102 EXPECT_TRUE(ad.finished()); 102 EXPECT_TRUE(ad.finished());
103 EXPECT_TRUE(ad.canceled()); 103 EXPECT_TRUE(ad.canceled());
104 } 104 }
105 105
106 // Lets an animation run, invoking End part way through and make sure we get the 106 // Lets an animation run, invoking End part way through and make sure we get the
107 // right delegate methods invoked. 107 // right delegate methods invoked.
108 TEST_F(AnimationTest, EndCase) { 108 TEST_F(AnimationTest, EndCase) {
109 TestAnimationDelegate ad; 109 TestAnimationDelegate ad;
110 EndAnimation a2(2000, 150, &ad); 110 EndAnimation a2(2000, 150, &ad);
111 a2.Start(); 111 a2.Start();
112 MessageLoop::current()->Run(); 112 base::MessageLoop::current()->Run();
113 113
114 EXPECT_TRUE(ad.finished()); 114 EXPECT_TRUE(ad.finished());
115 EXPECT_FALSE(ad.canceled()); 115 EXPECT_FALSE(ad.canceled());
116 } 116 }
117 117
118 // Runs an animation with a delegate that deletes the animation in end. 118 // Runs an animation with a delegate that deletes the animation in end.
119 TEST_F(AnimationTest, DeleteFromEnd) { 119 TEST_F(AnimationTest, DeleteFromEnd) {
120 DeletingAnimationDelegate delegate; 120 DeletingAnimationDelegate delegate;
121 RunAnimation* animation = new RunAnimation(150, &delegate); 121 RunAnimation* animation = new RunAnimation(150, &delegate);
122 animation->Start(); 122 animation->Start();
123 MessageLoop::current()->Run(); 123 base::MessageLoop::current()->Run();
124 // delegate should have deleted animation. 124 // delegate should have deleted animation.
125 } 125 }
126 126
127 TEST_F(AnimationTest, ShouldRenderRichAnimation) { 127 TEST_F(AnimationTest, ShouldRenderRichAnimation) {
128 #if defined(OS_WIN) 128 #if defined(OS_WIN)
129 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 129 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
130 BOOL result; 130 BOOL result;
131 ASSERT_NE( 131 ASSERT_NE(
132 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)); 132 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0));
133 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION 133 // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION
(...skipping 15 matching lines...) Expand all
149 EXPECT_EQ(0.0, animation.GetCurrentValue()); 149 EXPECT_EQ(0.0, animation.GetCurrentValue());
150 animation.Start(); 150 animation.Start();
151 EXPECT_EQ(0.0, animation.GetCurrentValue()); 151 EXPECT_EQ(0.0, animation.GetCurrentValue());
152 animation.End(); 152 animation.End();
153 EXPECT_EQ(1.0, animation.GetCurrentValue()); 153 EXPECT_EQ(1.0, animation.GetCurrentValue());
154 animation.Start(); 154 animation.Start();
155 EXPECT_EQ(0.0, animation.GetCurrentValue()); 155 EXPECT_EQ(0.0, animation.GetCurrentValue());
156 } 156 }
157 157
158 } // namespace ui 158 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/animation/animation_container_unittest.cc ('k') | ui/base/animation/slide_animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698