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

Side by Side 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 unified diff | 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 »
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/compositor/layer_animator.h" 5 #include "ui/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/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); 2604 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators());
2605 2605
2606 root_2.Add(&layer); 2606 root_2.Add(&layer);
2607 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); 2607 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators());
2608 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); 2608 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators());
2609 host_2.reset(); 2609 host_2.reset();
2610 host_1.reset(); 2610 host_1.reset();
2611 TerminateContextFactoryForTests(); 2611 TerminateContextFactoryForTests();
2612 } 2612 }
2613 2613
2614 class LayerOwnerAnimationObserver : public LayerAnimationObserver {
2615 public:
2616 LayerOwnerAnimationObserver(LayerAnimator* animator)
2617 : animator_layer_(new Layer(LAYER_TEXTURED)) {
2618 animator_layer_->SetAnimator(animator);
2619 }
2620
2621 ~LayerOwnerAnimationObserver() override {}
2622
2623 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override {
2624 ASSERT_TRUE(sequence);
2625 animator_layer_.reset();
2626 }
2627
2628 void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override {
2629 ASSERT_TRUE(sequence);
2630 animator_layer_.reset();
2631 }
2632
2633 LayerAnimationDelegate* animator_layer() {
2634 return animator_layer_.get();
2635 }
2636
2637 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {}
2638
2639 private:
2640 scoped_ptr<Layer> animator_layer_;
2641
2642 DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver);
2643 };
2644
2645 TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) {
2646 scoped_refptr<LayerAnimator> animator(
2647 LayerAnimator::CreateImplicitAnimator());
2648 animator->set_disable_timer_for_test(true);
2649 LayerOwnerAnimationObserver observer(animator.get());
2650 LayerAnimationDelegate* delegate = observer.animator_layer();
2651
2652 const gfx::Rect start_bounds(0, 0, 50, 50);
2653 const gfx::Rect target_bounds(10, 10, 100, 100);
2654 const double target_opacity = 1.0;
2655
2656 delegate->SetOpacityFromAnimation(0.0f);
2657 delegate->SetBoundsFromAnimation(start_bounds);
2658
2659 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1);
2660 LayerAnimationSequence* opacity = new LayerAnimationSequence(
2661 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta));
2662 opacity->AddObserver(&observer);
2663 animator->ScheduleAnimation(opacity);
2664 time_delta = base::TimeDelta::FromSeconds(2);
2665 LayerAnimationSequence* move = new LayerAnimationSequence(
2666 LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta));
2667 animator->ScheduleAnimation(move);
2668 EXPECT_TRUE(animator->is_animating());
2669 animator->Step(animator->last_step_time() +
2670 base::TimeDelta::FromMilliseconds(500));
2671 animator->StopAnimating();
2672
2673 EXPECT_EQ(nullptr, observer.animator_layer());
2674 EXPECT_TRUE(animator->is_animating());
2675 }
2676
2614 } // namespace ui 2677 } // namespace ui
OLDNEW
« 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