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

Unified Diff: ui/compositor/layer_animator_unittest.cc

Issue 185793005: Replacing raw pointer to LayerAnimator with scoped_refptr in ScopedLayerAnimationSettings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a unit test. Created 6 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
Index: ui/compositor/layer_animator_unittest.cc
diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc
index ed739656e56be3bee3d82a7a38f072e330678f91..03800fdc2745ad074052c1321b04fa8b097545c2 100644
--- a/ui/compositor/layer_animator_unittest.cc
+++ b/ui/compositor/layer_animator_unittest.cc
@@ -120,12 +120,41 @@ class DeletingLayerAnimationObserver : public LayerAnimationObserver {
DISALLOW_COPY_AND_ASSIGN(DeletingLayerAnimationObserver);
};
+class LayerAnimatorDestructionObserver {
+ public:
+ LayerAnimatorDestructionObserver() : animator_deleted_(false) {}
+ virtual ~LayerAnimatorDestructionObserver() {}
+
+ void NotifyAnimatorDeleted() {
+ animator_deleted_ = true;
+ }
+
+ bool IsAnimatorDeleted() {
+ return animator_deleted_;
+ }
+
+ private:
+ bool animator_deleted_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerAnimatorDestructionObserver);
+};
+
class TestLayerAnimator : public LayerAnimator {
public:
- TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)) {}
+ TestLayerAnimator() : LayerAnimator(base::TimeDelta::FromSeconds(0)),
+ destruction_observer_(NULL) {}
+
+ void SetDestructionObserver(
+ LayerAnimatorDestructionObserver* observer) {
+ destruction_observer_ = observer;
+ }
protected:
- virtual ~TestLayerAnimator() {}
+ virtual ~TestLayerAnimator() {
+ if (destruction_observer_) {
+ destruction_observer_->NotifyAnimatorDeleted();
+ }
+ }
virtual void ProgressAnimation(LayerAnimationSequence* sequence,
base::TimeTicks now) OVERRIDE {
@@ -134,6 +163,8 @@ class TestLayerAnimator : public LayerAnimator {
}
private:
+ LayerAnimatorDestructionObserver* destruction_observer_;
+
DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator);
};
@@ -1642,6 +1673,30 @@ TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation());
}
+// Tests that LayerAnimator is not deleted after the animation completes as long
+// as there is a live ScopedLayerAnimationSettings object wrapped around it.
+TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) {
+ // Note we are using a raw pointer unlike in other tests.
+ TestLayerAnimator* animator = new TestLayerAnimator();
+ LayerAnimatorDestructionObserver destruction_observer;
+ animator->SetDestructionObserver(&destruction_observer);
+ AnimationContainerElement* element = animator;
+ animator->set_disable_timer_for_test(true);
+ TestLayerAnimationDelegate delegate;
+ animator->SetDelegate(&delegate);
+ {
+ // ScopedLayerAnimationSettings should keep the Animator alive as long as
+ // it is alive, even beyond the end of the animation.
+ ScopedLayerAnimationSettings settings(animator);
+ base::TimeTicks now = gfx::FrameTime::Now();
+ animator->SetBrightness(0.5);
+ element->Step(now + base::TimeDelta::FromSeconds(1));
+ EXPECT_FALSE(destruction_observer.IsAnimatorDeleted());
+ }
+ // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted.
+ EXPECT_TRUE(destruction_observer.IsAnimatorDeleted());
+}
+
// Tests that an observer added to a scoped settings object is not notified
// when the animator is destroyed unless explicitly requested.
TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
« no previous file with comments | « content/browser/web_contents/aura/overscroll_navigation_overlay.cc ('k') | ui/compositor/scoped_layer_animation_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698