Chromium Code Reviews| 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 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); | 2604 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2605 | 2605 |
| 2606 root_2.Add(&layer); | 2606 root_2.Add(&layer); |
| 2607 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); | 2607 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2608 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); | 2608 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2609 host_2.reset(); | 2609 host_2.reset(); |
| 2610 host_1.reset(); | 2610 host_1.reset(); |
| 2611 TerminateContextFactoryForTests(); | 2611 TerminateContextFactoryForTests(); |
| 2612 } | 2612 } |
| 2613 | 2613 |
| 2614 class DelegateOwnerAnimationObserver : public LayerAnimationObserver { | |
| 2615 public: | |
| 2616 DelegateOwnerAnimationObserver(LayerAnimator* animator) | |
| 2617 : animator_delegate_(new TestLayerAnimationDelegate()), | |
| 2618 animator_(animator) { | |
| 2619 animator_->SetDelegate(animator_delegate_.get()); | |
| 2620 } | |
| 2621 | |
| 2622 ~DelegateOwnerAnimationObserver() { animator_->SetDelegate(nullptr); } | |
|
sky
2014/12/18 20:31:40
override
| |
| 2623 | |
| 2624 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { | |
| 2625 ASSERT_TRUE(sequence); | |
| 2626 reset_delegate(); | |
| 2627 } | |
| 2628 | |
| 2629 void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override { | |
| 2630 ASSERT_TRUE(sequence); | |
| 2631 reset_delegate(); | |
| 2632 } | |
| 2633 | |
| 2634 TestLayerAnimationDelegate* get_animator_delegate() { | |
| 2635 return animator_delegate_.get(); | |
| 2636 } | |
| 2637 | |
| 2638 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} | |
| 2639 | |
| 2640 private: | |
| 2641 void reset_delegate() { | |
| 2642 animator_->SetDelegate(nullptr); | |
| 2643 animator_delegate_.reset(); | |
| 2644 } | |
| 2645 | |
| 2646 scoped_ptr<TestLayerAnimationDelegate> animator_delegate_; | |
| 2647 scoped_refptr<LayerAnimator> animator_; | |
| 2648 | |
| 2649 DISALLOW_COPY_AND_ASSIGN(DelegateOwnerAnimationObserver); | |
| 2650 }; | |
| 2651 | |
| 2652 TEST(LayerAnimatorTest, ObserverRemovesDelegateInStopAnimating) { | |
| 2653 scoped_refptr<LayerAnimator> animator( | |
|
sky
2014/12/18 20:31:40
Can you write this test using the layer and deleti
| |
| 2654 LayerAnimator::CreateImplicitAnimator()); | |
| 2655 animator->set_disable_timer_for_test(true); | |
| 2656 DelegateOwnerAnimationObserver observer(animator.get()); | |
| 2657 TestLayerAnimationDelegate* delegate = observer.get_animator_delegate(); | |
| 2658 | |
| 2659 const gfx::Rect start_bounds(0, 0, 50, 50); | |
| 2660 const gfx::Rect target_bounds(10, 10, 100, 100); | |
| 2661 const double target_opacity = 1.0; | |
| 2662 | |
| 2663 delegate->SetOpacityFromAnimation(0.0f); | |
| 2664 delegate->SetBoundsFromAnimation(start_bounds); | |
| 2665 | |
| 2666 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); | |
| 2667 LayerAnimationSequence* opacity = new LayerAnimationSequence( | |
| 2668 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta)); | |
| 2669 opacity->AddObserver(&observer); | |
| 2670 animator->ScheduleAnimation(opacity); | |
| 2671 time_delta = base::TimeDelta::FromSeconds(2); | |
| 2672 LayerAnimationSequence* move = new LayerAnimationSequence( | |
| 2673 LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta)); | |
| 2674 animator->ScheduleAnimation(move); | |
| 2675 EXPECT_TRUE(animator->is_animating()); | |
| 2676 animator->Step(animator->last_step_time() + | |
| 2677 base::TimeDelta::FromMilliseconds(500)); | |
| 2678 animator->StopAnimating(); | |
| 2679 | |
| 2680 EXPECT_EQ(observer.get_animator_delegate(), nullptr); | |
| 2681 EXPECT_TRUE(animator->is_animating()); | |
| 2682 } | |
| 2683 | |
| 2614 } // namespace ui | 2684 } // namespace ui |
| OLD | NEW |