summaryrefslogtreecommitdiffstats
path: root/app/animation_container_unittest.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 23:20:52 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 23:20:52 +0000
commit059e7a559572484fb677480ef6b95322cde3b34f (patch)
treed21b6b7393c4d27d1fb2ee172c2a0ac7330138ae /app/animation_container_unittest.cc
parente3f4cc62db9c967b911b00399674e392c71d0a7d (diff)
downloadchromium_src-059e7a559572484fb677480ef6b95322cde3b34f.zip
chromium_src-059e7a559572484fb677480ef6b95322cde3b34f.tar.gz
chromium_src-059e7a559572484fb677480ef6b95322cde3b34f.tar.bz2
Adds AnimationContainer, which can be used to group a set of
animations to have the same timer. By default each animation has one animationcontainer, but I'm going to change the tab renderer to share the animationcontainer so that the pulse effects happen in unison. Also updated the BoundsAnimator so that I can use it by the TabStrip. BUG=none TEST=none Review URL: http://codereview.chromium.org/1575011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/animation_container_unittest.cc')
-rw-r--r--app/animation_container_unittest.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/app/animation_container_unittest.cc b/app/animation_container_unittest.cc
new file mode 100644
index 0000000..4046ae3
--- /dev/null
+++ b/app/animation_container_unittest.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 2010 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 "app/animation.h"
+#include "app/animation_container.h"
+#include "app/test_animation_delegate.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::AtLeast;
+
+namespace {
+
+class MockObserver : public AnimationContainer::Observer {
+ public:
+ MockObserver() {}
+
+ MOCK_METHOD1(AnimationContainerProgressed, void(AnimationContainer*));
+ MOCK_METHOD1(AnimationContainerEmpty, void(AnimationContainer*));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockObserver);
+};
+
+class TestAnimation : public Animation {
+ public:
+ TestAnimation(AnimationDelegate* delegate)
+ : Animation(20, 20, delegate) {
+ }
+
+ virtual void AnimateToState(double state) {
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestAnimation);
+};
+
+} // namespace
+
+class AnimationContainerTest: public testing::Test {
+ private:
+ MessageLoopForUI message_loop_;
+};
+
+// Makes sure the animation ups the ref count of the container and releases it
+// appropriately.
+TEST_F(AnimationContainerTest, Ownership) {
+ TestAnimationDelegate delegate;
+ scoped_refptr<AnimationContainer> container(new AnimationContainer());
+ scoped_ptr<Animation> animation(new TestAnimation(&delegate));
+ animation->SetContainer(container.get());
+ // Setting the container should up the ref count.
+ EXPECT_FALSE(container->HasOneRef());
+
+ animation.reset();
+
+ // Releasing the animation should decrement the ref count.
+ EXPECT_TRUE(container->HasOneRef());
+}
+
+// Makes sure multiple animations are managed correctly.
+TEST_F(AnimationContainerTest, Multi) {
+ TestAnimationDelegate delegate1;
+ TestAnimationDelegate delegate2;
+
+ scoped_refptr<AnimationContainer> container(new AnimationContainer());
+ TestAnimation animation1(&delegate1);
+ TestAnimation animation2(&delegate2);
+ animation1.SetContainer(container.get());
+ animation2.SetContainer(container.get());
+
+ // Start both animations.
+ animation1.Start();
+ EXPECT_TRUE(container->is_running());
+ animation2.Start();
+ EXPECT_TRUE(container->is_running());
+
+ // Run the message loop the delegate quits the message loop when notified.
+ MessageLoop::current()->Run();
+
+ // Both timers should have finished.
+ EXPECT_TRUE(delegate1.finished());
+ EXPECT_TRUE(delegate2.finished());
+
+ // And the container should no longer be runnings.
+ EXPECT_FALSE(container->is_running());
+}
+
+// Makes sure observer is notified appropriately.
+TEST_F(AnimationContainerTest, Observer) {
+ MockObserver observer;
+ TestAnimationDelegate delegate1;
+
+ scoped_refptr<AnimationContainer> container(new AnimationContainer());
+ container->set_observer(&observer);
+ TestAnimation animation1(&delegate1);
+ animation1.SetContainer(container.get());
+
+ // We expect to get these two calls: the animation progressed, and then when
+ // the animation completed the container went empty.
+ EXPECT_CALL(observer, AnimationContainerProgressed(container.get())).Times(
+ AtLeast(1));
+ EXPECT_CALL(observer, AnimationContainerEmpty(container.get())).Times(1);
+
+ // Start the animation.
+ animation1.Start();
+ EXPECT_TRUE(container->is_running());
+
+ // Run the message loop the delegate quits the message loop when notified.
+ MessageLoop::current()->Run();
+
+ // The timer should have finished.
+ EXPECT_TRUE(delegate1.finished());
+
+ // And the container should no longer be runnings.
+ EXPECT_FALSE(container->is_running());
+
+ container->set_observer(NULL);
+}