summaryrefslogtreecommitdiffstats
path: root/app/animation_unittest.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:43:55 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:43:55 +0000
commit4ce7e15da651c6221720e33dc8c500830d4b6b8a (patch)
tree376ef1d7e7951dae3376e65f4edee9e7367adc89 /app/animation_unittest.cc
parent5ee3ca64cdf2d00f82a1bc36f36e8ab5e520b4de (diff)
downloadchromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.zip
chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.gz
chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.bz2
Refactors animation to allow for cleaner subclassing. I'm doing this
for creating a different animation subclass (which you'll see shortly). BUG=none TEST=none Review URL: http://codereview.chromium.org/1961001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/animation_unittest.cc')
-rw-r--r--app/animation_unittest.cc62
1 files changed, 57 insertions, 5 deletions
diff --git a/app/animation_unittest.cc b/app/animation_unittest.cc
index 30f9b52..df0b262b 100644
--- a/app/animation_unittest.cc
+++ b/app/animation_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "app/animation.h"
+#include "app/linear_animation.h"
#include "app/test_animation_delegate.h"
#if defined(OS_WIN)
#include "base/win_util.h"
@@ -14,13 +14,15 @@ class AnimationTest: public testing::Test {
MessageLoopForUI message_loop_;
};
+namespace {
+
///////////////////////////////////////////////////////////////////////////////
// RunAnimation
-class RunAnimation : public Animation {
+class RunAnimation : public LinearAnimation {
public:
RunAnimation(int frame_rate, AnimationDelegate* delegate)
- : Animation(frame_rate, delegate) {
+ : LinearAnimation(frame_rate, delegate) {
}
virtual void AnimateToState(double state) {
@@ -32,10 +34,10 @@ class RunAnimation : public Animation {
///////////////////////////////////////////////////////////////////////////////
// CancelAnimation
-class CancelAnimation : public Animation {
+class CancelAnimation : public LinearAnimation {
public:
CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
- : Animation(duration, frame_rate, delegate) {
+ : LinearAnimation(duration, frame_rate, delegate) {
}
virtual void AnimateToState(double state) {
@@ -45,6 +47,35 @@ class CancelAnimation : public Animation {
};
///////////////////////////////////////////////////////////////////////////////
+// EndAnimation
+
+class EndAnimation : public LinearAnimation {
+ public:
+ EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
+ : LinearAnimation(duration, frame_rate, delegate) {
+ }
+
+ virtual void AnimateToState(double state) {
+ if (state >= 0.5)
+ End();
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// DeletingAnimationDelegate
+
+// AnimationDelegate implementation that deletes the animation in ended.
+class DeletingAnimationDelegate : public AnimationDelegate {
+ public:
+ virtual void AnimationEnded(const Animation* animation) {
+ delete animation;
+ MessageLoop::current()->Quit();
+ }
+};
+
+} // namespace
+
+///////////////////////////////////////////////////////////////////////////////
// LinearCase
TEST_F(AnimationTest, RunCase) {
@@ -68,6 +99,27 @@ TEST_F(AnimationTest, CancelCase) {
EXPECT_TRUE(ad.canceled());
}
+// Lets an animation run, invoking End part way through and make sure we get the
+// right delegate methods invoked.
+TEST_F(AnimationTest, EndCase) {
+ TestAnimationDelegate ad;
+ EndAnimation a2(2000, 150, &ad);
+ a2.Start();
+ MessageLoop::current()->Run();
+
+ EXPECT_TRUE(ad.finished());
+ EXPECT_FALSE(ad.canceled());
+}
+
+// Runs an animation with a delegate that deletes the animation in end.
+TEST_F(AnimationTest, DeleteFromEnd) {
+ DeletingAnimationDelegate delegate;
+ RunAnimation* animation = new RunAnimation(150, &delegate);
+ animation->Start();
+ MessageLoop::current()->Run();
+ // delegate should have deleted animation.
+}
+
TEST_F(AnimationTest, ShouldRenderRichAnimation) {
#if defined(OS_WIN)
if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) {