Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: ui/gfx/compositor/layer_animator_unittest.cc

Issue 9371007: Fix a memory leak in the layer animator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a comment. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer_animator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // The test layer animation sequence updates a live instances count when it is
47 // created and destroyed.
48 class TestLayerAnimationSequence : public LayerAnimationSequence {
49 public:
50 TestLayerAnimationSequence(LayerAnimationElement* element,
51 int* num_live_instances)
52 : LayerAnimationSequence(element),
53 num_live_instances_(num_live_instances) {
54 (*num_live_instances_)++;
55 }
56
57 virtual ~TestLayerAnimationSequence() {
58 (*num_live_instances_)--;
59 }
60
61 private:
62 int* num_live_instances_;
63
64 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence);
65 };
66
46 } // namespace 67 } // namespace
47 68
48 // Checks that setting a property on an implicit animator causes an animation to 69 // Checks that setting a property on an implicit animator causes an animation to
49 // happen. 70 // happen.
50 TEST(LayerAnimatorTest, ImplicitAnimation) { 71 TEST(LayerAnimatorTest, ImplicitAnimation) {
51 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); 72 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator());
52 AnimationContainerElement* element = animator.get(); 73 AnimationContainerElement* element = animator.get();
53 animator->set_disable_timer_for_test(true); 74 animator->set_disable_timer_for_test(true);
54 TestLayerAnimationDelegate delegate; 75 TestLayerAnimationDelegate delegate;
55 animator->SetDelegate(&delegate); 76 animator->SetDelegate(&delegate);
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 924 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
904 925
905 animator->StartAnimation(sequence.release()); 926 animator->StartAnimation(sequence.release());
906 927
907 animator->SetOpacity(0.5); 928 animator->SetOpacity(0.5);
908 929
909 EXPECT_FALSE(animator->is_animating()); 930 EXPECT_FALSE(animator->is_animating());
910 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 931 EXPECT_EQ(0.5, animator->GetTargetOpacity());
911 } 932 }
912 933
913 } // namespace ui 934 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the
935 // second sequence to be leaked.
936 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
937 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
938 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
939 animator->set_disable_timer_for_test(true);
940 TestLayerAnimationDelegate delegate;
941 animator->SetDelegate(&delegate);
942
943 gfx::Rect start_bounds(0, 0, 50, 50);
944 gfx::Rect middle_bounds(10, 10, 100, 100);
945 gfx::Rect target_bounds(5, 5, 5, 5);
946
947 delegate.SetBoundsFromAnimation(start_bounds);
948
949 {
950 // start an implicit bounds animation.
951 ScopedLayerAnimationSettings settings(animator.get());
952 animator->SetBounds(middle_bounds);
953 }
954
955 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
956
957 int num_live_instances = 0;
958 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
959 scoped_ptr<TestLayerAnimationSequence> sequence(
960 new TestLayerAnimationSequence(
961 LayerAnimationElement::CreateBoundsElement(target_bounds, delta),
962 &num_live_instances));
963
964 EXPECT_EQ(1, num_live_instances);
965
966 // This should interrupt the running sequence causing us to immediately set
967 // the target value. The sequence should alse be destructed.
968 animator->StartAnimation(sequence.release());
969
970 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
971 EXPECT_EQ(0, num_live_instances);
972 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
973 }
974
975 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698