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

Side by Side Diff: app/animation_container_unittest.cc

Issue 1575011: Adds AnimationContainer, which can be used to group a set of (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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "app/animation.h"
6 #include "app/animation_container.h"
7 #include "app/test_animation_delegate.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using testing::AtLeast;
12
13 namespace {
14
15 class MockObserver : public AnimationContainer::Observer {
16 public:
17 MockObserver() {}
18
19 MOCK_METHOD1(AnimationContainerProgressed, void(AnimationContainer*));
20 MOCK_METHOD1(AnimationContainerEmpty, void(AnimationContainer*));
21
22 private:
23 DISALLOW_COPY_AND_ASSIGN(MockObserver);
24 };
25
26 class TestAnimation : public Animation {
27 public:
28 TestAnimation(AnimationDelegate* delegate)
29 : Animation(20, 20, delegate) {
30 }
31
32 virtual void AnimateToState(double state) {
33 }
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(TestAnimation);
37 };
38
39 } // namespace
40
41 class AnimationContainerTest: public testing::Test {
42 private:
43 MessageLoopForUI message_loop_;
44 };
45
46 // Makes sure the animation ups the ref count of the container and releases it
47 // appropriately.
48 TEST_F(AnimationContainerTest, Ownership) {
49 TestAnimationDelegate delegate;
50 scoped_refptr<AnimationContainer> container(new AnimationContainer());
51 scoped_ptr<Animation> animation(new TestAnimation(&delegate));
52 animation->SetContainer(container.get());
53 // Setting the container should up the ref count.
54 EXPECT_FALSE(container->HasOneRef());
55
56 animation.reset();
57
58 // Releasing the animation should decrement the ref count.
59 EXPECT_TRUE(container->HasOneRef());
60 }
61
62 // Makes sure multiple animations are managed correctly.
63 TEST_F(AnimationContainerTest, Multi) {
64 TestAnimationDelegate delegate1;
65 TestAnimationDelegate delegate2;
66
67 scoped_refptr<AnimationContainer> container(new AnimationContainer());
68 TestAnimation animation1(&delegate1);
69 TestAnimation animation2(&delegate2);
70 animation1.SetContainer(container.get());
71 animation2.SetContainer(container.get());
72
73 // Start both animations.
74 animation1.Start();
75 EXPECT_TRUE(container->is_running());
76 animation2.Start();
77 EXPECT_TRUE(container->is_running());
78
79 // Run the message loop the delegate quits the message loop when notified.
80 MessageLoop::current()->Run();
81
82 // Both timers should have finished.
83 EXPECT_TRUE(delegate1.finished());
84 EXPECT_TRUE(delegate2.finished());
85
86 // And the container should no longer be runnings.
87 EXPECT_FALSE(container->is_running());
88 }
89
90 // Makes sure observer is notified appropriately.
91 TEST_F(AnimationContainerTest, Observer) {
92 MockObserver observer;
93 TestAnimationDelegate delegate1;
94
95 scoped_refptr<AnimationContainer> container(new AnimationContainer());
96 container->set_observer(&observer);
97 TestAnimation animation1(&delegate1);
98 animation1.SetContainer(container.get());
99
100 // We expect to get these two calls: the animation progressed, and then when
101 // the animation completed the container went empty.
102 EXPECT_CALL(observer, AnimationContainerProgressed(container.get())).Times(
103 AtLeast(1));
104 EXPECT_CALL(observer, AnimationContainerEmpty(container.get())).Times(1);
105
106 // Start the animation.
107 animation1.Start();
108 EXPECT_TRUE(container->is_running());
109
110 // Run the message loop the delegate quits the message loop when notified.
111 MessageLoop::current()->Run();
112
113 // The timer should have finished.
114 EXPECT_TRUE(delegate1.finished());
115
116 // And the container should no longer be runnings.
117 EXPECT_FALSE(container->is_running());
118
119 container->set_observer(NULL);
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698