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 CompletionOrderAnimationObserver : public LayerAnimationObserver { | |
2615 public: | |
2616 | |
sky
2014/12/12 18:05:15
nit: no newline here.
| |
2617 CompletionOrderAnimationObserver() {}; | |
sky
2014/12/12 18:05:15
no ;
| |
2618 | |
2619 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { | |
2620 ASSERT_TRUE(sequence); | |
2621 completion_order_.push_back(sequence); | |
2622 } | |
2623 | |
2624 void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override { | |
2625 ASSERT_TRUE(sequence); | |
2626 completion_order_.push_back(sequence); | |
2627 } | |
2628 | |
2629 const std::vector<LayerAnimationSequence *>& GetCompletionOrder() { | |
sky
2014/12/12 18:05:15
Make this function const too and name completion_o
| |
2630 return completion_order_; | |
2631 } | |
2632 | |
2633 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} | |
sky
2014/12/12 18:05:15
Keep the LayerAnimationObserver methods together.
| |
2634 | |
2635 private: | |
2636 std::vector<LayerAnimationSequence *> completion_order_; | |
2637 | |
2638 DISALLOW_COPY_AND_ASSIGN(CompletionOrderAnimationObserver); | |
2639 }; | |
2640 | |
2641 // This test illustrates completion order of animations interrupted by | |
2642 // LayerAnimator::StopAnimating(). | |
2643 TEST(LayerAnimatorTest, StopAnimatingCompletionOrder) { | |
sky
2014/12/12 18:05:15
This is an interesting test, but what you want is
| |
2644 scoped_refptr<LayerAnimator> animator( | |
2645 LayerAnimator::CreateImplicitAnimator()); | |
2646 animator->set_disable_timer_for_test(true); | |
2647 TestLayerAnimationDelegate delegate; | |
2648 animator->SetDelegate(&delegate); | |
2649 CompletionOrderAnimationObserver observer; | |
2650 animator->AddObserver(&observer); | |
2651 | |
2652 const gfx::Rect start_bounds(0, 0, 50, 50); | |
2653 const gfx::Rect target_bounds(10, 10, 100, 100); | |
2654 const double target_opacity = 1.0; | |
2655 | |
2656 delegate.SetOpacityFromAnimation(0.0f); | |
2657 delegate.SetBoundsFromAnimation(start_bounds); | |
2658 | |
2659 animator->SchedulePauseForProperties(base::TimeDelta::FromMilliseconds(100), | |
2660 LayerAnimationElement::OPACITY); | |
2661 | |
2662 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); | |
2663 LayerAnimationSequence* opacity = new LayerAnimationSequence( | |
2664 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta)); | |
2665 animator->ScheduleAnimation(opacity); | |
2666 time_delta = base::TimeDelta::FromSeconds(2); | |
2667 LayerAnimationSequence* move = new LayerAnimationSequence( | |
2668 LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta)); | |
2669 animator->ScheduleAnimation(move); | |
2670 EXPECT_TRUE(animator->is_animating()); | |
2671 animator->StopAnimating(); | |
2672 | |
2673 auto completion_order = observer.GetCompletionOrder(); | |
2674 EXPECT_NE( | |
2675 std::find(completion_order.begin(), completion_order.end(), opacity), | |
2676 completion_order.end()); | |
2677 EXPECT_NE(std::find(completion_order.begin(), completion_order.end(), move), | |
2678 completion_order.end()); | |
2679 EXPECT_GT( | |
2680 std::find(completion_order.begin(), completion_order.end(), opacity), | |
2681 std::find(completion_order.begin(), completion_order.end(), move)); | |
2682 | |
2683 animator->RemoveObserver(&observer); | |
2684 } | |
2685 | |
2614 } // namespace ui | 2686 } // namespace ui |
OLD | NEW |