Index: ui/compositor/layer_animator_unittest.cc |
diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc |
index 99d2426c0299fc6bf3c110c48729aa7ae06aa36e..04f94362396e2e9aee4daf664abc25428900fb60 100644 |
--- a/ui/compositor/layer_animator_unittest.cc |
+++ b/ui/compositor/layer_animator_unittest.cc |
@@ -2611,4 +2611,74 @@ TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) { |
TerminateContextFactoryForTests(); |
} |
+class DelegateOwnerAnimationObserver : public LayerAnimationObserver { |
+ public: |
+ DelegateOwnerAnimationObserver(LayerAnimator* animator) |
+ : animator_delegate_(new TestLayerAnimationDelegate()), |
+ animator_(animator) { |
+ animator_->SetDelegate(animator_delegate_.get()); |
+ } |
+ |
+ ~DelegateOwnerAnimationObserver() { animator_->SetDelegate(nullptr); } |
sky
2014/12/18 20:31:40
override
|
+ |
+ void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { |
+ ASSERT_TRUE(sequence); |
+ reset_delegate(); |
+ } |
+ |
+ void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override { |
+ ASSERT_TRUE(sequence); |
+ reset_delegate(); |
+ } |
+ |
+ TestLayerAnimationDelegate* get_animator_delegate() { |
+ return animator_delegate_.get(); |
+ } |
+ |
+ void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} |
+ |
+ private: |
+ void reset_delegate() { |
+ animator_->SetDelegate(nullptr); |
+ animator_delegate_.reset(); |
+ } |
+ |
+ scoped_ptr<TestLayerAnimationDelegate> animator_delegate_; |
+ scoped_refptr<LayerAnimator> animator_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DelegateOwnerAnimationObserver); |
+}; |
+ |
+TEST(LayerAnimatorTest, ObserverRemovesDelegateInStopAnimating) { |
+ scoped_refptr<LayerAnimator> animator( |
sky
2014/12/18 20:31:40
Can you write this test using the layer and deleti
|
+ LayerAnimator::CreateImplicitAnimator()); |
+ animator->set_disable_timer_for_test(true); |
+ DelegateOwnerAnimationObserver observer(animator.get()); |
+ TestLayerAnimationDelegate* delegate = observer.get_animator_delegate(); |
+ |
+ const gfx::Rect start_bounds(0, 0, 50, 50); |
+ const gfx::Rect target_bounds(10, 10, 100, 100); |
+ const double target_opacity = 1.0; |
+ |
+ delegate->SetOpacityFromAnimation(0.0f); |
+ delegate->SetBoundsFromAnimation(start_bounds); |
+ |
+ base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
+ LayerAnimationSequence* opacity = new LayerAnimationSequence( |
+ LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta)); |
+ opacity->AddObserver(&observer); |
+ animator->ScheduleAnimation(opacity); |
+ time_delta = base::TimeDelta::FromSeconds(2); |
+ LayerAnimationSequence* move = new LayerAnimationSequence( |
+ LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta)); |
+ animator->ScheduleAnimation(move); |
+ EXPECT_TRUE(animator->is_animating()); |
+ animator->Step(animator->last_step_time() + |
+ base::TimeDelta::FromMilliseconds(500)); |
+ animator->StopAnimating(); |
+ |
+ EXPECT_EQ(observer.get_animator_delegate(), nullptr); |
+ EXPECT_TRUE(animator->is_animating()); |
+} |
+ |
} // namespace ui |