Chromium Code Reviews| Index: ui/compositor/layer_unittest.cc |
| diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc |
| index 44ac816a98275d978b4bf946ccc6e2cc5e568048..6778bb9821fee9174a4e17677a63f389d1bdb44f 100644 |
| --- a/ui/compositor/layer_unittest.cc |
| +++ b/ui/compositor/layer_unittest.cc |
| @@ -107,12 +107,16 @@ class LayerWithRealCompositorTest : public testing::Test { |
| } |
| void TearDown() override { |
| - compositor_host_.reset(); |
| + ResetCompositor(); |
| TerminateContextFactoryForTests(); |
| } |
| Compositor* GetCompositor() { return compositor_host_->GetCompositor(); } |
| + void ResetCompositor() { |
| + compositor_host_.reset(); |
| + } |
| + |
| Layer* CreateLayer(LayerType type) { |
| return new Layer(type); |
| } |
| @@ -354,6 +358,43 @@ class TestCompositorObserver : public CompositorObserver { |
| DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); |
| }; |
| +class TestCompositorAnimationObserver : public CompositorAnimationObserver { |
| + public: |
| + explicit TestCompositorAnimationObserver(ui::Compositor* compositor) |
| + : compositor_(compositor), |
| + animation_step_count_(0), |
| + shutdown_(false) { |
| + DCHECK(compositor_); |
| + compositor_->AddAnimationObserver(this); |
| + } |
| + |
| + ~TestCompositorAnimationObserver() override { |
| + if (compositor_) |
| + compositor_->RemoveAnimationObserver(this); |
| + } |
| + |
| + size_t animation_step_count() const { return animation_step_count_; } |
| + bool shutdown() const { return shutdown_; } |
| + |
| + private: |
| + void OnAnimationStep(base::TimeTicks timestamp) override { |
| + ++animation_step_count_; |
| + } |
| + |
| + void OnCompositingShuttingDown(Compositor* compositor) override { |
| + if (compositor_) |
|
danakj
2015/06/02 18:24:15
how can it be null?
|
| + compositor_->RemoveAnimationObserver(this); |
| + compositor_ = nullptr; |
| + shutdown_ = true; |
| + } |
| + |
| + ui::Compositor* compositor_; |
| + size_t animation_step_count_; |
| + bool shutdown_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestCompositorAnimationObserver); |
| +}; |
| + |
| } // namespace |
| TEST_F(LayerWithRealCompositorTest, Draw) { |
| @@ -1810,4 +1851,21 @@ TEST(LayerDelegateTest, DelegatedFrameDamage) { |
| EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| } |
| +TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { |
| + scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
| + |
| + root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
| + |
| + TestCompositorAnimationObserver animation_observer(GetCompositor()); |
| + EXPECT_EQ(0u, animation_observer.animation_step_count()); |
| + |
| + root->SetOpacity(0.5f); |
| + WaitForSwap(); |
| + EXPECT_EQ(1u, animation_observer.animation_step_count()); |
| + |
| + EXPECT_EQ(false, animation_observer.shutdown()); |
| + ResetCompositor(); |
| + EXPECT_EQ(true, animation_observer.shutdown()); |
| +} |
| + |
| } // namespace ui |