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/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 virtual void OnLayerAnimationScheduled( | 113 virtual void OnLayerAnimationScheduled( |
114 LayerAnimationSequence* sequence) OVERRIDE { | 114 LayerAnimationSequence* sequence) OVERRIDE { |
115 } | 115 } |
116 | 116 |
117 private: | 117 private: |
118 LayerAnimator* animator_; | 118 LayerAnimator* animator_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(DeletingLayerAnimationObserver); | 120 DISALLOW_COPY_AND_ASSIGN(DeletingLayerAnimationObserver); |
121 }; | 121 }; |
122 | 122 |
| 123 class LayerAnimatorDestructionObserver { |
| 124 public: |
| 125 LayerAnimatorDestructionObserver() : animator_deleted_(false) {} |
| 126 virtual ~LayerAnimatorDestructionObserver() {} |
| 127 |
| 128 void NotifyAnimatorDeleted() { |
| 129 animator_deleted_ = true; |
| 130 } |
| 131 |
| 132 bool IsAnimatorDeleted() { |
| 133 return animator_deleted_; |
| 134 } |
| 135 |
| 136 private: |
| 137 bool animator_deleted_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(LayerAnimatorDestructionObserver); |
| 140 }; |
| 141 |
123 class TestLayerAnimator : public LayerAnimator { | 142 class TestLayerAnimator : public LayerAnimator { |
124 public: | 143 public: |
125 TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)) {} | 144 TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)), |
| 145 destruction_observer_(NULL) {} |
| 146 |
| 147 void SetDestructionObserver( |
| 148 LayerAnimatorDestructionObserver* observer) { |
| 149 destruction_observer_ = observer; |
| 150 } |
126 | 151 |
127 protected: | 152 protected: |
128 virtual ~TestLayerAnimator() {} | 153 virtual ~TestLayerAnimator() { |
| 154 if (destruction_observer_) { |
| 155 destruction_observer_->NotifyAnimatorDeleted(); |
| 156 } |
| 157 } |
129 | 158 |
130 virtual void ProgressAnimation(LayerAnimationSequence* sequence, | 159 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
131 base::TimeTicks now) OVERRIDE { | 160 base::TimeTicks now) OVERRIDE { |
132 EXPECT_TRUE(HasAnimation(sequence)); | 161 EXPECT_TRUE(HasAnimation(sequence)); |
133 LayerAnimator::ProgressAnimation(sequence, now); | 162 LayerAnimator::ProgressAnimation(sequence, now); |
134 } | 163 } |
135 | 164 |
136 private: | 165 private: |
| 166 LayerAnimatorDestructionObserver* destruction_observer_; |
| 167 |
137 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); | 168 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); |
138 }; | 169 }; |
139 | 170 |
140 // The test layer animation sequence updates a live instances count when it is | 171 // The test layer animation sequence updates a live instances count when it is |
141 // created and destroyed. | 172 // created and destroyed. |
142 class TestLayerAnimationSequence : public LayerAnimationSequence { | 173 class TestLayerAnimationSequence : public LayerAnimationSequence { |
143 public: | 174 public: |
144 TestLayerAnimationSequence(LayerAnimationElement* element, | 175 TestLayerAnimationSequence(LayerAnimationElement* element, |
145 int* num_live_instances) | 176 int* num_live_instances) |
146 : LayerAnimationSequence(element), | 177 : LayerAnimationSequence(element), |
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 EXPECT_FALSE(observer.animations_completed()); | 1666 EXPECT_FALSE(observer.animations_completed()); |
1636 // This should interrupt the implicit animation causing the observer to be | 1667 // This should interrupt the implicit animation causing the observer to be |
1637 // notified immediately. | 1668 // notified immediately. |
1638 animator->SetBrightness(1.0f); | 1669 animator->SetBrightness(1.0f); |
1639 EXPECT_TRUE(observer.animations_completed()); | 1670 EXPECT_TRUE(observer.animations_completed()); |
1640 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( | 1671 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( |
1641 LayerAnimationElement::BRIGHTNESS)); | 1672 LayerAnimationElement::BRIGHTNESS)); |
1642 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); | 1673 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); |
1643 } | 1674 } |
1644 | 1675 |
| 1676 // Tests that LayerAnimator is not deleted after the animation completes as long |
| 1677 // as there is a live ScopedLayerAnimationSettings object wrapped around it. |
| 1678 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { |
| 1679 // Note we are using a raw pointer unlike in other tests. |
| 1680 TestLayerAnimator* animator = new TestLayerAnimator(); |
| 1681 LayerAnimatorDestructionObserver destruction_observer; |
| 1682 animator->SetDestructionObserver(&destruction_observer); |
| 1683 AnimationContainerElement* element = animator; |
| 1684 animator->set_disable_timer_for_test(true); |
| 1685 TestLayerAnimationDelegate delegate; |
| 1686 animator->SetDelegate(&delegate); |
| 1687 { |
| 1688 // ScopedLayerAnimationSettings should keep the Animator alive as long as |
| 1689 // it is alive, even beyond the end of the animation. |
| 1690 ScopedLayerAnimationSettings settings(animator); |
| 1691 base::TimeTicks now = gfx::FrameTime::Now(); |
| 1692 animator->SetBrightness(0.5); |
| 1693 element->Step(now + base::TimeDelta::FromSeconds(1)); |
| 1694 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); |
| 1695 } |
| 1696 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. |
| 1697 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); |
| 1698 } |
| 1699 |
1645 // Tests that an observer added to a scoped settings object is not notified | 1700 // Tests that an observer added to a scoped settings object is not notified |
1646 // when the animator is destroyed unless explicitly requested. | 1701 // when the animator is destroyed unless explicitly requested. |
1647 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { | 1702 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { |
1648 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1703 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1649 animator->set_disable_timer_for_test(true); | 1704 animator->set_disable_timer_for_test(true); |
1650 TestImplicitAnimationObserver observer_notify(true); | 1705 TestImplicitAnimationObserver observer_notify(true); |
1651 TestImplicitAnimationObserver observer_do_not_notify(false); | 1706 TestImplicitAnimationObserver observer_do_not_notify(false); |
1652 TestLayerAnimationDelegate delegate; | 1707 TestLayerAnimationDelegate delegate; |
1653 animator->SetDelegate(&delegate); | 1708 animator->SetDelegate(&delegate); |
1654 | 1709 |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 | 2519 |
2465 parent.SetTransform(parent_end); | 2520 parent.SetTransform(parent_end); |
2466 | 2521 |
2467 EXPECT_TRUE(child.GetAnimator()->is_animating()); | 2522 EXPECT_TRUE(child.GetAnimator()->is_animating()); |
2468 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) | 2523 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) |
2469 << child.GetTargetTransform().ToString(); | 2524 << child.GetTargetTransform().ToString(); |
2470 | 2525 |
2471 } | 2526 } |
2472 | 2527 |
2473 } // namespace ui | 2528 } // namespace ui |
OLD | NEW |