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

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: Worked everything around. Created 6 years 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..04f94362396e2e9aee4daf664abc25428900fb60 100644
--- a/ui/compositor/layer_animator_unittest.cc
+++ b/ui/compositor/layer_animator_unittest.cc
@@ -2611,4 +2611,74 @@ TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) {
TerminateContextFactoryForTests();
}
+class DelegateOwnerAnimationObserver : public LayerAnimationObserver {
+ public:
+ DelegateOwnerAnimationObserver(LayerAnimator* animator)
+ : animator_delegate_(new TestLayerAnimationDelegate()),
+ animator_(animator) {
+ animator_->SetDelegate(animator_delegate_.get());
+ }
+
+ ~DelegateOwnerAnimationObserver() { animator_->SetDelegate(nullptr); }
sky 2014/12/18 20:31:40 override
+
+ void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override {
+ ASSERT_TRUE(sequence);
+ reset_delegate();
+ }
+
+ void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override {
+ ASSERT_TRUE(sequence);
+ reset_delegate();
+ }
+
+ TestLayerAnimationDelegate* get_animator_delegate() {
+ return animator_delegate_.get();
+ }
+
+ void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {}
+
+ private:
+ void reset_delegate() {
+ animator_->SetDelegate(nullptr);
+ animator_delegate_.reset();
+ }
+
+ scoped_ptr<TestLayerAnimationDelegate> animator_delegate_;
+ scoped_refptr<LayerAnimator> animator_;
+
+ DISALLOW_COPY_AND_ASSIGN(DelegateOwnerAnimationObserver);
+};
+
+TEST(LayerAnimatorTest, ObserverRemovesDelegateInStopAnimating) {
+ scoped_refptr<LayerAnimator> animator(
sky 2014/12/18 20:31:40 Can you write this test using the layer and deleti
+ LayerAnimator::CreateImplicitAnimator());
+ animator->set_disable_timer_for_test(true);
+ DelegateOwnerAnimationObserver observer(animator.get());
+ TestLayerAnimationDelegate* delegate = observer.get_animator_delegate();
+
+ 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(observer.get_animator_delegate(), nullptr);
+ 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