diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 17:33:39 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 17:33:39 +0000 |
commit | f676780687464428e340d008a0d1ca13d9944628 (patch) | |
tree | 489e8bd8188e31a7f6c53f15e8d1d9c6ba36d023 /ui/base/animation/animation_unittest.cc | |
parent | 3b65bfd55c56cf8a6db025087d937494f49dc15f (diff) | |
download | chromium_src-f676780687464428e340d008a0d1ca13d9944628.zip chromium_src-f676780687464428e340d008a0d1ca13d9944628.tar.gz chromium_src-f676780687464428e340d008a0d1ca13d9944628.tar.bz2 |
Move animation code to new ui/base/animation directory.
BUG=none
TEST=none
TBR=brettw
Review URL: http://codereview.chromium.org/6154001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/animation/animation_unittest.cc')
-rw-r--r-- | ui/base/animation/animation_unittest.cc | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/ui/base/animation/animation_unittest.cc b/ui/base/animation/animation_unittest.cc new file mode 100644 index 0000000..7d87600 --- /dev/null +++ b/ui/base/animation/animation_unittest.cc @@ -0,0 +1,146 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/animation/animation_delegate.h" +#include "ui/base/animation/linear_animation.h" +#include "ui/base/animation/test_animation_delegate.h" + +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + +namespace ui { + +class AnimationTest: public testing::Test { + private: + MessageLoopForUI message_loop_; +}; + +namespace { + +/////////////////////////////////////////////////////////////////////////////// +// RunAnimation + +class RunAnimation : public LinearAnimation { + public: + RunAnimation(int frame_rate, AnimationDelegate* delegate) + : LinearAnimation(frame_rate, delegate) { + } + + virtual void AnimateToState(double state) { + EXPECT_LE(0.0, state); + EXPECT_GE(1.0, state); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// CancelAnimation + +class CancelAnimation : public LinearAnimation { + public: + CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate) + : LinearAnimation(duration, frame_rate, delegate) { + } + + virtual void AnimateToState(double state) { + if (state >= 0.5) + Stop(); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// 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) { + TestAnimationDelegate ad; + RunAnimation a1(150, &ad); + a1.SetDuration(2000); + a1.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(ad.finished()); + EXPECT_FALSE(ad.canceled()); +} + +TEST_F(AnimationTest, CancelCase) { + TestAnimationDelegate ad; + CancelAnimation a2(2000, 150, &ad); + a2.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(ad.finished()); + 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 (base::win::GetVersion() >= base::win::VERSION_VISTA) { + BOOL result; + ASSERT_NE( + 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)); + // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION + // value on Vista. + EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation()); + } else { + // On XP, the function should check the SM_REMOTESESSION value. + EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION), + Animation::ShouldRenderRichAnimation()); + } +#else + EXPECT_TRUE(Animation::ShouldRenderRichAnimation()); +#endif +} + +} // namespace ui |