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

Unified Diff: ui/compositor/layer_animator_unittest.cc

Issue 795113002: compositor/layer_animator: handle delegate removal in LayerAnimation::StopAnimating (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixups for test Created 5 years, 11 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
« no previous file with comments | « ui/compositor/layer_animator.cc ('k') | ui/wm/core/window_animations_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer_animator_unittest.cc
diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc
index 99d2426c0299fc6bf3c110c48729aa7ae06aa36e..e641b8a2334af21091d6a5deb36a09a3b4a21ec7 100644
--- a/ui/compositor/layer_animator_unittest.cc
+++ b/ui/compositor/layer_animator_unittest.cc
@@ -2611,4 +2611,67 @@ TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) {
TerminateContextFactoryForTests();
}
+class LayerOwnerAnimationObserver : public LayerAnimationObserver {
+ public:
+ LayerOwnerAnimationObserver(LayerAnimator* animator)
+ : animator_layer_(new Layer(LAYER_TEXTURED)) {
+ animator_layer_->SetAnimator(animator);
+ }
+
+ ~LayerOwnerAnimationObserver() override {}
+
+ void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override {
+ ASSERT_TRUE(sequence);
+ animator_layer_.reset();
+ }
+
+ void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override {
+ ASSERT_TRUE(sequence);
+ animator_layer_.reset();
+ }
+
+ LayerAnimationDelegate* animator_layer() {
+ return animator_layer_.get();
+ }
+
+ void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {}
+
+ private:
+ scoped_ptr<Layer> animator_layer_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver);
+};
+
+TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) {
+ scoped_refptr<LayerAnimator> animator(
+ LayerAnimator::CreateImplicitAnimator());
+ animator->set_disable_timer_for_test(true);
+ LayerOwnerAnimationObserver observer(animator.get());
+ LayerAnimationDelegate* delegate = observer.animator_layer();
+
+ const gfx::Rect start_bounds(0, 0, 50, 50);
+ const gfx::Rect target_bounds(10, 10, 100, 100);
+ const double target_opacity = 1.0;
+
+ delegate->SetOpacityFromAnimation(0.0f);
+ delegate->SetBoundsFromAnimation(start_bounds);
+
+ base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1);
+ LayerAnimationSequence* opacity = new LayerAnimationSequence(
+ LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta));
+ opacity->AddObserver(&observer);
+ animator->ScheduleAnimation(opacity);
+ time_delta = base::TimeDelta::FromSeconds(2);
+ LayerAnimationSequence* move = new LayerAnimationSequence(
+ LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta));
+ animator->ScheduleAnimation(move);
+ EXPECT_TRUE(animator->is_animating());
+ animator->Step(animator->last_step_time() +
+ base::TimeDelta::FromMilliseconds(500));
+ animator->StopAnimating();
+
+ EXPECT_EQ(nullptr, observer.animator_layer());
+ EXPECT_TRUE(animator->is_animating());
+}
+
} // namespace ui
« no previous file with comments | « ui/compositor/layer_animator.cc ('k') | ui/wm/core/window_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698