Chromium Code Reviews| Index: ui/gfx/compositor/layer_unittest.cc |
| diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc |
| index 7445256c199f3696227ee0e16b7e31ed0e055ada..513b14cc72d46be89017a9795a43a587d0d72f37 100644 |
| --- a/ui/gfx/compositor/layer_unittest.cc |
| +++ b/ui/gfx/compositor/layer_unittest.cc |
| @@ -173,6 +173,23 @@ class NullLayerDelegate : public LayerDelegate { |
| DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
| }; |
| +// Remembers if it has been notified. |
| +class TestCompositorObserver : public CompositorObserver { |
| + public: |
| + TestCompositorObserver() : notified_(false) {} |
| + |
| + bool notified() const { return notified_; } |
| + |
| + void Reset() { notified_ = false; } |
| + |
| + private: |
| + virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE { |
| + notified_ = true; |
| + } |
| + |
| + bool notified_; |
|
jonathan.backer
2011/11/11 20:17:16
DISALLOW_COPY_AND_ASSIGN
|
| +}; |
| + |
| } |
| #if defined(OS_WIN) |
| @@ -804,4 +821,65 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { |
| EXPECT_TRUE(is_all_red); |
| } |
| +// Checks that compositor observers are notified when: |
| +// - DrawTree is called, |
| +// - After ScheduleDraw is called, or |
| +// - Whenever SetBounds, SetOpacity or SetTransform are called. |
| +TEST_F(LayerWithRealCompositorTest, CompositorObservers) { |
| + scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| + gfx::Rect(20, 20, 400, 400))); |
| + scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| + gfx::Rect(10, 10, 350, 350))); |
| + l1->Add(l2.get()); |
| + TestCompositorObserver observer; |
| + GetCompositor()->AddObserver(&observer); |
| + |
| + // Explicitly called DrawTree should cause the observers to be notified. |
| + DrawTree(l1.get()); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // As should scheduling a draw and waiting. |
| + observer.Reset(); |
| + l1->ScheduleDraw(); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // Moving, but not resizing, a layer should alert the observers. |
| + observer.Reset(); |
| + l2->SetBounds(gfx::Rect(0, 0, 350, 350)); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // So should resizing a layer. |
| + observer.Reset(); |
| + l2->SetBounds(gfx::Rect(0, 0, 400, 400)); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // Opacity changes should alert the observers. |
| + observer.Reset(); |
| + l2->SetOpacity(0.5f); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // So should setting the opacity back. |
| + observer.Reset(); |
| + l2->SetOpacity(1.0f); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + // Setting the transform of a layer should alert the observers. |
| + observer.Reset(); |
| + Transform transform; |
| + transform.ConcatTranslate(-200, -200); |
| + transform.ConcatRotate(90.0f); |
| + transform.ConcatTranslate(200, 200); |
| + l2->SetTransform(transform); |
| + RunPendingMessages(); |
| + EXPECT_TRUE(observer.notified()); |
| + |
| + GetCompositor()->RemoveObserver(&observer); |
|
jonathan.backer
2011/11/11 20:17:16
Test this?
|
| +} |
| + |
| } // namespace ui |