OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 6 #include "testing/gmock/include/gmock/gmock.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/animation/animation_container.h" | 8 #include "ui/base/animation/animation_container.h" |
9 #include "ui/base/animation/animation_container_observer.h" | 9 #include "ui/base/animation/animation_container_observer.h" |
10 #include "ui/base/animation/linear_animation.h" | 10 #include "ui/base/animation/linear_animation.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 private: | 39 private: |
40 DISALLOW_COPY_AND_ASSIGN(TestAnimation); | 40 DISALLOW_COPY_AND_ASSIGN(TestAnimation); |
41 }; | 41 }; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class AnimationContainerTest: public testing::Test { | 45 class AnimationContainerTest: public testing::Test { |
46 private: | 46 private: |
47 MessageLoopForUI message_loop_; | 47 base::MessageLoopForUI message_loop_; |
48 }; | 48 }; |
49 | 49 |
50 // Makes sure the animation ups the ref count of the container and releases it | 50 // Makes sure the animation ups the ref count of the container and releases it |
51 // appropriately. | 51 // appropriately. |
52 TEST_F(AnimationContainerTest, Ownership) { | 52 TEST_F(AnimationContainerTest, Ownership) { |
53 TestAnimationDelegate delegate; | 53 TestAnimationDelegate delegate; |
54 scoped_refptr<AnimationContainer> container(new AnimationContainer()); | 54 scoped_refptr<AnimationContainer> container(new AnimationContainer()); |
55 scoped_ptr<Animation> animation(new TestAnimation(&delegate)); | 55 scoped_ptr<Animation> animation(new TestAnimation(&delegate)); |
56 animation->SetContainer(container.get()); | 56 animation->SetContainer(container.get()); |
57 // Setting the container should up the ref count. | 57 // Setting the container should up the ref count. |
(...skipping 16 matching lines...) Expand all Loading... |
74 animation1.SetContainer(container.get()); | 74 animation1.SetContainer(container.get()); |
75 animation2.SetContainer(container.get()); | 75 animation2.SetContainer(container.get()); |
76 | 76 |
77 // Start both animations. | 77 // Start both animations. |
78 animation1.Start(); | 78 animation1.Start(); |
79 EXPECT_TRUE(container->is_running()); | 79 EXPECT_TRUE(container->is_running()); |
80 animation2.Start(); | 80 animation2.Start(); |
81 EXPECT_TRUE(container->is_running()); | 81 EXPECT_TRUE(container->is_running()); |
82 | 82 |
83 // Run the message loop the delegate quits the message loop when notified. | 83 // Run the message loop the delegate quits the message loop when notified. |
84 MessageLoop::current()->Run(); | 84 base::MessageLoop::current()->Run(); |
85 | 85 |
86 // Both timers should have finished. | 86 // Both timers should have finished. |
87 EXPECT_TRUE(delegate1.finished()); | 87 EXPECT_TRUE(delegate1.finished()); |
88 EXPECT_TRUE(delegate2.finished()); | 88 EXPECT_TRUE(delegate2.finished()); |
89 | 89 |
90 // And the container should no longer be runnings. | 90 // And the container should no longer be runnings. |
91 EXPECT_FALSE(container->is_running()); | 91 EXPECT_FALSE(container->is_running()); |
92 } | 92 } |
93 | 93 |
94 // Makes sure observer is notified appropriately. | 94 // Makes sure observer is notified appropriately. |
(...skipping 10 matching lines...) Expand all Loading... |
105 // the animation completed the container went empty. | 105 // the animation completed the container went empty. |
106 EXPECT_CALL(observer, AnimationContainerProgressed(container.get())).Times( | 106 EXPECT_CALL(observer, AnimationContainerProgressed(container.get())).Times( |
107 AtLeast(1)); | 107 AtLeast(1)); |
108 EXPECT_CALL(observer, AnimationContainerEmpty(container.get())).Times(1); | 108 EXPECT_CALL(observer, AnimationContainerEmpty(container.get())).Times(1); |
109 | 109 |
110 // Start the animation. | 110 // Start the animation. |
111 animation1.Start(); | 111 animation1.Start(); |
112 EXPECT_TRUE(container->is_running()); | 112 EXPECT_TRUE(container->is_running()); |
113 | 113 |
114 // Run the message loop. The delegate quits the message loop when notified. | 114 // Run the message loop. The delegate quits the message loop when notified. |
115 MessageLoop::current()->Run(); | 115 base::MessageLoop::current()->Run(); |
116 | 116 |
117 // The timer should have finished. | 117 // The timer should have finished. |
118 EXPECT_TRUE(delegate1.finished()); | 118 EXPECT_TRUE(delegate1.finished()); |
119 | 119 |
120 // And the container should no longer be running. | 120 // And the container should no longer be running. |
121 EXPECT_FALSE(container->is_running()); | 121 EXPECT_FALSE(container->is_running()); |
122 | 122 |
123 container->set_observer(NULL); | 123 container->set_observer(NULL); |
124 } | 124 } |
125 | 125 |
126 } // namespace ui | 126 } // namespace ui |
OLD | NEW |