| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/animation/bounds_animator.h" | 5 #include "ui/views/animation/bounds_animator.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/animation/slide_animation.h" | 9 #include "ui/gfx/animation/slide_animation.h" |
| 10 #include "ui/gfx/animation/test_animation_delegate.h" | 10 #include "ui/gfx/animation/test_animation_delegate.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorTest); | 107 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorTest); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // Checks animate view to. | 110 // Checks animate view to. |
| 111 TEST_F(BoundsAnimatorTest, AnimateViewTo) { | 111 TEST_F(BoundsAnimatorTest, AnimateViewTo) { |
| 112 gfx::Rect initial_bounds(0, 0, 10, 10); | 112 gfx::Rect initial_bounds(0, 0, 10, 10); |
| 113 child()->SetBoundsRect(initial_bounds); | 113 child()->SetBoundsRect(initial_bounds); |
| 114 gfx::Rect target_bounds(10, 10, 20, 20); | 114 gfx::Rect target_bounds(10, 10, 20, 20); |
| 115 animator()->AnimateViewTo(child(), target_bounds); | 115 animator()->AnimateViewTo(child(), target_bounds); |
| 116 animator()->SetAnimationDelegate( | 116 animator()->SetAnimationDelegate( |
| 117 child(), scoped_ptr<gfx::AnimationDelegate>(new TestAnimationDelegate())); | 117 child(), |
| 118 std::unique_ptr<gfx::AnimationDelegate>(new TestAnimationDelegate())); |
| 118 | 119 |
| 119 // The animator should be animating now. | 120 // The animator should be animating now. |
| 120 EXPECT_TRUE(animator()->IsAnimating()); | 121 EXPECT_TRUE(animator()->IsAnimating()); |
| 121 | 122 |
| 122 // Run the message loop; the delegate exits the loop when the animation is | 123 // Run the message loop; the delegate exits the loop when the animation is |
| 123 // done. | 124 // done. |
| 124 base::MessageLoop::current()->Run(); | 125 base::MessageLoop::current()->Run(); |
| 125 | 126 |
| 126 // Make sure the bounds match of the view that was animated match. | 127 // Make sure the bounds match of the view that was animated match. |
| 127 EXPECT_EQ(target_bounds, child()->bounds()); | 128 EXPECT_EQ(target_bounds, child()->bounds()); |
| 128 | 129 |
| 129 // The parent should have been told to repaint as the animation progressed. | 130 // The parent should have been told to repaint as the animation progressed. |
| 130 // The resulting rect is the union of the original and target bounds. | 131 // The resulting rect is the union of the original and target bounds. |
| 131 EXPECT_EQ(gfx::UnionRects(target_bounds, initial_bounds), | 132 EXPECT_EQ(gfx::UnionRects(target_bounds, initial_bounds), |
| 132 parent()->dirty_rect()); | 133 parent()->dirty_rect()); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Make sure an AnimationDelegate is deleted when canceled. | 136 // Make sure an AnimationDelegate is deleted when canceled. |
| 136 TEST_F(BoundsAnimatorTest, DeleteDelegateOnCancel) { | 137 TEST_F(BoundsAnimatorTest, DeleteDelegateOnCancel) { |
| 137 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); | 138 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); |
| 138 animator()->SetAnimationDelegate( | 139 animator()->SetAnimationDelegate( |
| 139 child(), scoped_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); | 140 child(), std::unique_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); |
| 140 | 141 |
| 141 animator()->Cancel(); | 142 animator()->Cancel(); |
| 142 | 143 |
| 143 // The animator should no longer be animating. | 144 // The animator should no longer be animating. |
| 144 EXPECT_FALSE(animator()->IsAnimating()); | 145 EXPECT_FALSE(animator()->IsAnimating()); |
| 145 | 146 |
| 146 // The cancel should both cancel the delegate and delete it. | 147 // The cancel should both cancel the delegate and delete it. |
| 147 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); | 148 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); |
| 148 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); | 149 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Make sure an AnimationDelegate is deleted when another animation is | 152 // Make sure an AnimationDelegate is deleted when another animation is |
| 152 // scheduled. | 153 // scheduled. |
| 153 TEST_F(BoundsAnimatorTest, DeleteDelegateOnNewAnimate) { | 154 TEST_F(BoundsAnimatorTest, DeleteDelegateOnNewAnimate) { |
| 154 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); | 155 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); |
| 155 animator()->SetAnimationDelegate( | 156 animator()->SetAnimationDelegate( |
| 156 child(), scoped_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); | 157 child(), std::unique_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); |
| 157 | 158 |
| 158 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); | 159 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); |
| 159 | 160 |
| 160 // Starting a new animation should both cancel the delegate and delete it. | 161 // Starting a new animation should both cancel the delegate and delete it. |
| 161 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); | 162 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); |
| 162 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); | 163 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); |
| 163 } | 164 } |
| 164 | 165 |
| 165 // Makes sure StopAnimating works. | 166 // Makes sure StopAnimating works. |
| 166 TEST_F(BoundsAnimatorTest, StopAnimating) { | 167 TEST_F(BoundsAnimatorTest, StopAnimating) { |
| 167 scoped_ptr<OwnedDelegate> delegate(new OwnedDelegate()); | 168 std::unique_ptr<OwnedDelegate> delegate(new OwnedDelegate()); |
| 168 | 169 |
| 169 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); | 170 animator()->AnimateViewTo(child(), gfx::Rect(0, 0, 10, 10)); |
| 170 animator()->SetAnimationDelegate( | 171 animator()->SetAnimationDelegate( |
| 171 child(), scoped_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); | 172 child(), std::unique_ptr<gfx::AnimationDelegate>(new OwnedDelegate())); |
| 172 | 173 |
| 173 animator()->StopAnimatingView(child()); | 174 animator()->StopAnimatingView(child()); |
| 174 | 175 |
| 175 // Shouldn't be animating now. | 176 // Shouldn't be animating now. |
| 176 EXPECT_FALSE(animator()->IsAnimating()); | 177 EXPECT_FALSE(animator()->IsAnimating()); |
| 177 | 178 |
| 178 // Stopping should both cancel the delegate and delete it. | 179 // Stopping should both cancel the delegate and delete it. |
| 179 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); | 180 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); |
| 180 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); | 181 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); |
| 181 } | 182 } |
| 182 | 183 |
| 183 } // namespace views | 184 } // namespace views |
| OLD | NEW |