diff options
author | vollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-07 15:24:54 +0000 |
---|---|---|
committer | vollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-07 15:24:54 +0000 |
commit | 5cc8538dd346996646f0c2bc41a960e77a1683fc (patch) | |
tree | b1ecefb1e16dab58b7018b40c612cafc0616dfc7 /ui | |
parent | 98f1d362bb40ecd72dbf4c2bcc3013e1913979db (diff) | |
download | chromium_src-5cc8538dd346996646f0c2bc41a960e77a1683fc.zip chromium_src-5cc8538dd346996646f0c2bc41a960e77a1683fc.tar.gz chromium_src-5cc8538dd346996646f0c2bc41a960e77a1683fc.tar.bz2 |
Removing animation observers from the layer animator should also remove them from the sequences.
BUG=None
TEST=compositor_unittests
Review URL: http://codereview.chromium.org/8481005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/compositor/layer_animator.cc | 5 | ||||
-rw-r--r-- | ui/gfx/compositor/layer_animator_unittest.cc | 35 |
2 files changed, 40 insertions, 0 deletions
diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc index 1ec2b78..7bc9698 100644 --- a/ui/gfx/compositor/layer_animator.cc +++ b/ui/gfx/compositor/layer_animator.cc @@ -193,6 +193,11 @@ void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { observers_.RemoveObserver(observer); + // Remove the observer from all sequences as well. + for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); + queue_iter != animation_queue_.end(); ++queue_iter) { + (*queue_iter)->RemoveObserver(observer); + } } LayerAnimator::ScopedSettings::ScopedSettings(LayerAnimator* animator) diff --git a/ui/gfx/compositor/layer_animator_unittest.cc b/ui/gfx/compositor/layer_animator_unittest.cc index 762a3b2..84bc4a3 100644 --- a/ui/gfx/compositor/layer_animator_unittest.cc +++ b/ui/gfx/compositor/layer_animator_unittest.cc @@ -722,6 +722,41 @@ TEST(LayerAnimatorTest, AddObserverImplicit) { EXPECT_TRUE(!scoped_observer.last_ended_sequence()); } +TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { + scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); + AnimationContainerElement* element = animator.get(); + animator->set_disable_timer_for_test(true); + TestLayerAnimationObserver observer; + TestLayerAnimationObserver removed_observer; + TestLayerAnimationDelegate delegate; + animator->SetDelegate(&delegate); + + base::TimeDelta delta = base::TimeDelta::FromSeconds(1); + + LayerAnimationSequence* sequence = new LayerAnimationSequence( + LayerAnimationElement::CreateOpacityElement(1.0f, delta)); + + sequence->AddObserver(&observer); + sequence->AddObserver(&removed_observer); + + animator->StartAnimation(sequence); + + EXPECT_EQ(observer.last_scheduled_sequence(), sequence); + EXPECT_TRUE(!observer.last_ended_sequence()); + EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); + EXPECT_TRUE(!removed_observer.last_ended_sequence()); + + // This should stop the observer from observing sequence. + animator->RemoveObserver(&removed_observer); + + base::TimeTicks start_time = animator->get_last_step_time_for_test(); + + element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + + EXPECT_EQ(observer.last_ended_sequence(), sequence); + EXPECT_TRUE(!removed_observer.last_ended_sequence()); +} + // Check that setting a property during an animation with a default animator // cancels the original animation. TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { |