Chromium Code Reviews| 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..5f2823cdd1358a75fd9b31368e1fcb5ee9781cd3 100644 |
| --- a/ui/compositor/layer_animator_unittest.cc |
| +++ b/ui/compositor/layer_animator_unittest.cc |
| @@ -2611,4 +2611,69 @@ TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) { |
| TerminateContextFactoryForTests(); |
| } |
| +class LayerOwnerAnimationObserver : public LayerAnimationObserver { |
| + public: |
| + LayerOwnerAnimationObserver(LayerAnimator* animator) |
| + : animator_layer_(new Layer(LAYER_TEXTURED)) { |
| + animator_layer_->SetAnimator(animator); |
| + } |
| + |
| + virtual ~LayerOwnerAnimationObserver() {} |
|
sky
2015/01/05 17:54:52
no virtual, just override.
|
| + |
| + void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { |
| + ASSERT_TRUE(sequence); |
| + reset_layer(); |
| + } |
| + |
| + void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override { |
| + ASSERT_TRUE(sequence); |
| + reset_layer(); |
| + } |
| + |
| + LayerAnimationDelegate* get_animator_delegate() { |
|
sky
2015/01/05 17:54:52
Style guide says this should be named animator_lay
|
| + return animator_layer_.get(); |
| + } |
| + |
| + void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} |
| + |
| + private: |
| + void reset_layer() { animator_layer_.reset(); } |
|
sky
2015/01/05 17:54:52
This function is a single liner and doesn't add an
|
| + |
| + scoped_ptr<Layer> animator_layer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver); |
| +}; |
| + |
| +TEST(LayerAnimatorTest, ObserverRemovesLayerInStopAnimating) { |
|
sky
2015/01/05 17:54:52
Removes->Deletes.
|
| + scoped_refptr<LayerAnimator> animator( |
| + LayerAnimator::CreateImplicitAnimator()); |
| + animator->set_disable_timer_for_test(true); |
| + LayerOwnerAnimationObserver observer(animator.get()); |
| + LayerAnimationDelegate* 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); |
|
sky
2015/01/05 17:54:52
assertions have the format expected, actual. nullp
|
| + EXPECT_TRUE(animator->is_animating()); |
| +} |
| + |
| } // namespace ui |