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

Unified Diff: app/animation_unittest.cc

Issue 1961001: Refactors animation to allow for cleaner subclassing. I'm doing this (Closed)
Patch Set: Incorporated review feedback Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/animation_container_unittest.cc ('k') | app/app_base.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/animation_unittest.cc
diff --git a/app/animation_unittest.cc b/app/animation_unittest.cc
index 30f9b523dcbdf7bf18f59eb25bcc9ab765f7c167..df0b262b28adc421d4f6ef8ea667717a7a5ab0a0 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) {
« no previous file with comments | « app/animation_container_unittest.cc ('k') | app/app_base.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698