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/gfx/compositor/layer_animator.h" | 5 #include "ui/gfx/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/time.h" | 10 #include "base/time.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 // ImplicitAnimationObserver implementation | 36 // ImplicitAnimationObserver implementation |
| 37 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 37 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 38 animations_completed_ = true; | 38 animations_completed_ = true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool animations_completed_; | 41 bool animations_completed_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(TestImplicitAnimationObserver); | 43 DISALLOW_COPY_AND_ASSIGN(TestImplicitAnimationObserver); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class TestLayerAnimationSequence : public LayerAnimationSequence { | |
| 47 public: | |
| 48 TestLayerAnimationSequence(LayerAnimationElement* element, | |
| 49 int* num_live_instances) | |
| 50 : LayerAnimationSequence(element), | |
| 51 num_live_instances_(num_live_instances) { | |
| 52 *num_live_instances_ += 1; | |
|
oshima
2012/02/09 07:46:02
++
| |
| 53 } | |
| 54 | |
| 55 virtual ~TestLayerAnimationSequence() { | |
| 56 *num_live_instances_ -= 1; | |
|
oshima
2012/02/09 07:46:02
--
| |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 int* num_live_instances_; | |
|
sky
2012/02/09 03:48:56
DISALLOW_COPY_AND_ASSIGN.
And add a description of
| |
| 61 }; | |
| 62 | |
| 46 } // namespace | 63 } // namespace |
| 47 | 64 |
| 48 // Checks that setting a property on an implicit animator causes an animation to | 65 // Checks that setting a property on an implicit animator causes an animation to |
| 49 // happen. | 66 // happen. |
| 50 TEST(LayerAnimatorTest, ImplicitAnimation) { | 67 TEST(LayerAnimatorTest, ImplicitAnimation) { |
| 51 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 68 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
| 52 AnimationContainerElement* element = animator.get(); | 69 AnimationContainerElement* element = animator.get(); |
| 53 animator->set_disable_timer_for_test(true); | 70 animator->set_disable_timer_for_test(true); |
| 54 TestLayerAnimationDelegate delegate; | 71 TestLayerAnimationDelegate delegate; |
| 55 animator->SetDelegate(&delegate); | 72 animator->SetDelegate(&delegate); |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 920 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
| 904 | 921 |
| 905 animator->StartAnimation(sequence.release()); | 922 animator->StartAnimation(sequence.release()); |
| 906 | 923 |
| 907 animator->SetOpacity(0.5); | 924 animator->SetOpacity(0.5); |
| 908 | 925 |
| 909 EXPECT_FALSE(animator->is_animating()); | 926 EXPECT_FALSE(animator->is_animating()); |
| 910 EXPECT_EQ(0.5, animator->GetTargetOpacity()); | 927 EXPECT_EQ(0.5, animator->GetTargetOpacity()); |
| 911 } | 928 } |
| 912 | 929 |
| 930 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That | |
| 931 // is, ensure that all animations targetting a particular property are run in | |
| 932 // order. | |
| 933 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) { | |
| 934 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | |
| 935 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | |
| 936 animator->set_disable_timer_for_test(true); | |
| 937 TestLayerAnimationDelegate delegate; | |
| 938 animator->SetDelegate(&delegate); | |
| 939 | |
| 940 gfx::Rect start_bounds, target_bounds, middle_bounds; | |
|
oshima
2012/02/09 07:46:02
any good reason not doing start_bounds(0, 0, 50, 5
| |
| 941 start_bounds = gfx::Rect(0, 0, 50, 50); | |
| 942 middle_bounds = gfx::Rect(10, 10, 100, 100); | |
| 943 target_bounds = gfx::Rect(5, 5, 5, 5); | |
| 944 | |
| 945 delegate.SetBoundsFromAnimation(start_bounds); | |
| 946 | |
| 947 { | |
| 948 // start an implicit bounds animation. | |
| 949 ScopedLayerAnimationSettings settings(animator.get()); | |
| 950 animator->SetBounds(middle_bounds); | |
| 951 } | |
| 952 | |
| 953 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | |
| 954 | |
| 955 int num_live_instances = 0; | |
| 956 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | |
| 957 scoped_ptr<TestLayerAnimationSequence> sequence( | |
| 958 new TestLayerAnimationSequence( | |
| 959 LayerAnimationElement::CreateBoundsElement(target_bounds, delta), | |
| 960 &num_live_instances)); | |
| 961 | |
| 962 EXPECT_EQ(1, num_live_instances); | |
| 963 | |
| 964 // This should interrupt the running sequence causing us to immediately set | |
| 965 // the target value. The sequence should alse be destructed. | |
| 966 animator->StartAnimation(sequence.release()); | |
| 967 | |
| 968 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | |
| 969 EXPECT_EQ(0, num_live_instances); | |
| 970 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | |
| 971 } | |
| 972 | |
| 973 | |
|
oshima
2012/02/09 07:46:02
remove extra line
| |
| 913 } // namespace ui | 974 } // namespace ui |
|
oshima
2012/02/09 07:46:02
two spaces before //
| |
| OLD | NEW |