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 LayerOwnerAnimationObserver : public LayerAnimationObserver { | |
| 2615 public: | |
| 2616 LayerOwnerAnimationObserver(LayerAnimator* animator) | |
| 2617 : animator_layer_(new Layer(LAYER_TEXTURED)) { | |
| 2618 animator_layer_->SetAnimator(animator); | |
| 2619 } | |
| 2620 | |
| 2621 virtual ~LayerOwnerAnimationObserver() {} | |
|
sky
2015/01/05 17:54:52
no virtual, just override.
| |
| 2622 | |
| 2623 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { | |
| 2624 ASSERT_TRUE(sequence); | |
| 2625 reset_layer(); | |
| 2626 } | |
| 2627 | |
| 2628 void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override { | |
| 2629 ASSERT_TRUE(sequence); | |
| 2630 reset_layer(); | |
| 2631 } | |
| 2632 | |
| 2633 LayerAnimationDelegate* get_animator_delegate() { | |
|
sky
2015/01/05 17:54:52
Style guide says this should be named animator_lay
| |
| 2634 return animator_layer_.get(); | |
| 2635 } | |
| 2636 | |
| 2637 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} | |
| 2638 | |
| 2639 private: | |
| 2640 void reset_layer() { animator_layer_.reset(); } | |
|
sky
2015/01/05 17:54:52
This function is a single liner and doesn't add an
| |
| 2641 | |
| 2642 scoped_ptr<Layer> animator_layer_; | |
| 2643 | |
| 2644 DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver); | |
| 2645 }; | |
| 2646 | |
| 2647 TEST(LayerAnimatorTest, ObserverRemovesLayerInStopAnimating) { | |
|
sky
2015/01/05 17:54:52
Removes->Deletes.
| |
| 2648 scoped_refptr<LayerAnimator> animator( | |
| 2649 LayerAnimator::CreateImplicitAnimator()); | |
| 2650 animator->set_disable_timer_for_test(true); | |
| 2651 LayerOwnerAnimationObserver observer(animator.get()); | |
| 2652 LayerAnimationDelegate* delegate = observer.get_animator_delegate(); | |
| 2653 | |
| 2654 const gfx::Rect start_bounds(0, 0, 50, 50); | |
| 2655 const gfx::Rect target_bounds(10, 10, 100, 100); | |
| 2656 const double target_opacity = 1.0; | |
| 2657 | |
| 2658 delegate->SetOpacityFromAnimation(0.0f); | |
| 2659 delegate->SetBoundsFromAnimation(start_bounds); | |
| 2660 | |
| 2661 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); | |
| 2662 LayerAnimationSequence* opacity = new LayerAnimationSequence( | |
| 2663 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta)); | |
| 2664 opacity->AddObserver(&observer); | |
| 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->Step(animator->last_step_time() + | |
| 2672 base::TimeDelta::FromMilliseconds(500)); | |
| 2673 animator->StopAnimating(); | |
| 2674 | |
| 2675 EXPECT_EQ(observer.get_animator_delegate(), nullptr); | |
|
sky
2015/01/05 17:54:52
assertions have the format expected, actual. nullp
| |
| 2676 EXPECT_TRUE(animator->is_animating()); | |
| 2677 } | |
| 2678 | |
| 2614 } // namespace ui | 2679 } // namespace ui |
| OLD | NEW |