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

Unified 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: Remove valgrind suppression 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/compositor/layer_animator.cc ('K') | « ui/gfx/compositor/layer_animator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer_animator_unittest.cc
diff --git a/ui/gfx/compositor/layer_animator_unittest.cc b/ui/gfx/compositor/layer_animator_unittest.cc
index 09d1c661c73dc08508086788ebb508ed68d85877..711403ee908dc5559c3e755c39ae7d25fd1b0294 100644
--- a/ui/gfx/compositor/layer_animator_unittest.cc
+++ b/ui/gfx/compositor/layer_animator_unittest.cc
@@ -43,6 +43,23 @@ class TestImplicitAnimationObserver : public ImplicitAnimationObserver {
DISALLOW_COPY_AND_ASSIGN(TestImplicitAnimationObserver);
};
+class TestLayerAnimationSequence : public LayerAnimationSequence {
+ public:
+ TestLayerAnimationSequence(LayerAnimationElement* element,
+ int* num_live_instances)
+ : LayerAnimationSequence(element),
+ num_live_instances_(num_live_instances) {
+ *num_live_instances_ += 1;
oshima 2012/02/09 07:46:02 ++
+ }
+
+ virtual ~TestLayerAnimationSequence() {
+ *num_live_instances_ -= 1;
oshima 2012/02/09 07:46:02 --
+ }
+
+ private:
+ int* num_live_instances_;
sky 2012/02/09 03:48:56 DISALLOW_COPY_AND_ASSIGN. And add a description of
+};
+
} // namespace
// Checks that setting a property on an implicit animator causes an animation to
@@ -910,4 +927,48 @@ TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
EXPECT_EQ(0.5, animator->GetTargetOpacity());
}
+// Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That
+// is, ensure that all animations targetting a particular property are run in
+// order.
+TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
+ scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
+ animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
+ animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ animator->SetDelegate(&delegate);
+
+ 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
+ start_bounds = gfx::Rect(0, 0, 50, 50);
+ middle_bounds = gfx::Rect(10, 10, 100, 100);
+ target_bounds = gfx::Rect(5, 5, 5, 5);
+
+ delegate.SetBoundsFromAnimation(start_bounds);
+
+ {
+ // start an implicit bounds animation.
+ ScopedLayerAnimationSettings settings(animator.get());
+ animator->SetBounds(middle_bounds);
+ }
+
+ EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
+
+ int num_live_instances = 0;
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+ scoped_ptr<TestLayerAnimationSequence> sequence(
+ new TestLayerAnimationSequence(
+ LayerAnimationElement::CreateBoundsElement(target_bounds, delta),
+ &num_live_instances));
+
+ EXPECT_EQ(1, num_live_instances);
+
+ // This should interrupt the running sequence causing us to immediately set
+ // the target value. The sequence should alse be destructed.
+ animator->StartAnimation(sequence.release());
+
+ EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
+ EXPECT_EQ(0, num_live_instances);
+ CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
+}
+
+
oshima 2012/02/09 07:46:02 remove extra line
} // namespace ui
oshima 2012/02/09 07:46:02 two spaces before //
« ui/gfx/compositor/layer_animator.cc ('K') | « ui/gfx/compositor/layer_animator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698