OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "testing/gmock/include/gmock/gmock.h" |
5 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "ui/base/animation/slide_animation.h" | 7 #include "ui/base/animation/slide_animation.h" |
7 #include "ui/base/animation/test_animation_delegate.h" | 8 #include "ui/base/animation/test_animation_delegate.h" |
8 #include "views/animation/bounds_animator.h" | 9 #include "views/animation/bounds_animator.h" |
9 #include "views/view.h" | 10 #include "views/view.h" |
10 | 11 |
11 using views::BoundsAnimator; | 12 using views::BoundsAnimator; |
12 using ui::Animation; | 13 using ui::Animation; |
13 using ui::SlideAnimation; | 14 using ui::SlideAnimation; |
14 using ui::TestAnimationDelegate; | 15 using ui::TestAnimationDelegate; |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
| 19 class MockBoundsAnimatorObserver : public views::BoundsAnimatorObserver { |
| 20 public: |
| 21 MOCK_METHOD1(OnBoundsAnimatorProgressed, void(BoundsAnimator* animator)); |
| 22 MOCK_METHOD1(OnBoundsAnimatorDone, void(BoundsAnimator* animator)); |
| 23 }; |
| 24 |
18 class TestBoundsAnimator : public BoundsAnimator { | 25 class TestBoundsAnimator : public BoundsAnimator { |
19 public: | 26 public: |
20 explicit TestBoundsAnimator(views::View* view) : BoundsAnimator(view) { | 27 explicit TestBoundsAnimator(views::View* view) : BoundsAnimator(view) { |
21 } | 28 } |
22 | 29 |
23 protected: | 30 protected: |
24 SlideAnimation* CreateAnimation() { | 31 SlideAnimation* CreateAnimation() { |
25 SlideAnimation* animation = BoundsAnimator::CreateAnimation(); | 32 SlideAnimation* animation = BoundsAnimator::CreateAnimation(); |
26 animation->SetSlideDuration(10); | 33 animation->SetSlideDuration(10); |
27 return animation; | 34 return animation; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 101 |
95 class BoundsAnimatorTest : public testing::Test { | 102 class BoundsAnimatorTest : public testing::Test { |
96 public: | 103 public: |
97 BoundsAnimatorTest() : child_(new TestView()), animator_(&parent_) { | 104 BoundsAnimatorTest() : child_(new TestView()), animator_(&parent_) { |
98 parent_.AddChildView(child_); | 105 parent_.AddChildView(child_); |
99 } | 106 } |
100 | 107 |
101 TestView* parent() { return &parent_; } | 108 TestView* parent() { return &parent_; } |
102 TestView* child() { return child_; } | 109 TestView* child() { return child_; } |
103 TestBoundsAnimator* animator() { return &animator_; } | 110 TestBoundsAnimator* animator() { return &animator_; } |
| 111 MockBoundsAnimatorObserver* observer() { return &observer_; } |
104 | 112 |
105 private: | 113 private: |
106 MessageLoopForUI message_loop_; | 114 MessageLoopForUI message_loop_; |
107 TestView parent_; | 115 TestView parent_; |
108 TestView* child_; // Owned by |parent_|. | 116 TestView* child_; // Owned by |parent_|. |
109 TestBoundsAnimator animator_; | 117 TestBoundsAnimator animator_; |
| 118 testing::StrictMock<MockBoundsAnimatorObserver> observer_; |
110 | 119 |
111 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorTest); | 120 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorTest); |
112 }; | 121 }; |
113 | 122 |
114 // Checks animate view to. | 123 // Checks animate view to. |
115 TEST_F(BoundsAnimatorTest, AnimateViewTo) { | 124 TEST_F(BoundsAnimatorTest, AnimateViewTo) { |
116 TestAnimationDelegate delegate; | 125 TestAnimationDelegate delegate; |
117 gfx::Rect initial_bounds(0, 0, 10, 10); | 126 gfx::Rect initial_bounds(0, 0, 10, 10); |
118 child()->SetBoundsRect(initial_bounds); | 127 child()->SetBoundsRect(initial_bounds); |
119 gfx::Rect target_bounds(10, 10, 20, 20); | 128 gfx::Rect target_bounds(10, 10, 20, 20); |
120 animator()->AnimateViewTo(child(), target_bounds); | 129 animator()->AnimateViewTo(child(), target_bounds); |
121 animator()->SetAnimationDelegate(child(), &delegate, false); | 130 animator()->SetAnimationDelegate(child(), &delegate, false); |
| 131 animator()->set_observer(observer()); |
| 132 |
| 133 EXPECT_CALL(*observer(), OnBoundsAnimatorProgressed(animator())) |
| 134 .Times(testing::AnyNumber()); |
| 135 EXPECT_CALL(*observer(), OnBoundsAnimatorDone(animator())) |
| 136 .Times(1); |
122 | 137 |
123 // The animator should be animating now. | 138 // The animator should be animating now. |
124 EXPECT_TRUE(animator()->IsAnimating()); | 139 EXPECT_TRUE(animator()->IsAnimating()); |
125 | 140 |
126 // Run the message loop; the delegate exits the loop when the animation is | 141 // Run the message loop; the delegate exits the loop when the animation is |
127 // done. | 142 // done. |
128 MessageLoop::current()->Run(); | 143 MessageLoop::current()->Run(); |
129 | 144 |
130 // Make sure the bounds match of the view that was animated match. | 145 // Make sure the bounds match of the view that was animated match. |
131 EXPECT_EQ(target_bounds, child()->bounds()); | 146 EXPECT_EQ(target_bounds, child()->bounds()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 187 |
173 animator()->StopAnimatingView(child()); | 188 animator()->StopAnimatingView(child()); |
174 | 189 |
175 // Shouldn't be animating now. | 190 // Shouldn't be animating now. |
176 EXPECT_FALSE(animator()->IsAnimating()); | 191 EXPECT_FALSE(animator()->IsAnimating()); |
177 | 192 |
178 // Stopping should both cancel the delegate and delete it. | 193 // Stopping should both cancel the delegate and delete it. |
179 EXPECT_TRUE(OwnedDelegate::get_and_clear_deleted()); | 194 EXPECT_TRUE(OwnedDelegate::get_and_clear_deleted()); |
180 EXPECT_TRUE(OwnedDelegate::get_and_clear_canceled()); | 195 EXPECT_TRUE(OwnedDelegate::get_and_clear_canceled()); |
181 } | 196 } |
OLD | NEW |