| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/base/animation/slide_animation.h" | 8 #include "ui/base/animation/slide_animation.h" |
| 9 #include "ui/base/animation/test_animation_delegate.h" | 9 #include "ui/base/animation/test_animation_delegate.h" |
| 10 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 bool OwnedDelegate::canceled_ = false; | 69 bool OwnedDelegate::canceled_ = false; |
| 70 | 70 |
| 71 class TestView : public View { | 71 class TestView : public View { |
| 72 public: | 72 public: |
| 73 TestView() {} | 73 TestView() {} |
| 74 | 74 |
| 75 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { | 75 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { |
| 76 if (dirty_rect_.IsEmpty()) | 76 if (dirty_rect_.IsEmpty()) |
| 77 dirty_rect_ = r; | 77 dirty_rect_ = r; |
| 78 else | 78 else |
| 79 dirty_rect_ = dirty_rect_.Union(r); | 79 dirty_rect_.Union(r); |
| 80 } | 80 } |
| 81 | 81 |
| 82 const gfx::Rect& dirty_rect() const { return dirty_rect_; } | 82 const gfx::Rect& dirty_rect() const { return dirty_rect_; } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 gfx::Rect dirty_rect_; | 85 gfx::Rect dirty_rect_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(TestView); | 87 DISALLOW_COPY_AND_ASSIGN(TestView); |
| 88 }; | 88 }; |
| 89 | 89 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 // 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 |
| 124 // done. | 124 // done. |
| 125 MessageLoop::current()->Run(); | 125 MessageLoop::current()->Run(); |
| 126 | 126 |
| 127 // 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. |
| 128 EXPECT_EQ(target_bounds, child()->bounds()); | 128 EXPECT_EQ(target_bounds, child()->bounds()); |
| 129 | 129 |
| 130 // 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. |
| 131 // 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. |
| 132 EXPECT_EQ(target_bounds.Union(initial_bounds), parent()->dirty_rect()); | 132 target_bounds.Union(initial_bounds); |
| 133 EXPECT_EQ(target_bounds, 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(child(), new OwnedDelegate(), true); | 139 animator()->SetAnimationDelegate(child(), new OwnedDelegate(), true); |
| 139 | 140 |
| 140 animator()->Cancel(); | 141 animator()->Cancel(); |
| 141 | 142 |
| 142 // The animator should no longer be animating. | 143 // The animator should no longer be animating. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 171 | 172 |
| 172 // Shouldn't be animating now. | 173 // Shouldn't be animating now. |
| 173 EXPECT_FALSE(animator()->IsAnimating()); | 174 EXPECT_FALSE(animator()->IsAnimating()); |
| 174 | 175 |
| 175 // Stopping should both cancel the delegate and delete it. | 176 // Stopping should both cancel the delegate and delete it. |
| 176 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); | 177 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); |
| 177 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); | 178 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); |
| 178 } | 179 } |
| 179 | 180 |
| 180 } // namespace views | 181 } // namespace views |
| OLD | NEW |