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

Unified Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8538018: Added a unittest for compositor observers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments. Created 9 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4916f680789d2fc9dca54c4792da67b74671bd85 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -173,6 +173,25 @@ 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver);
+};
+
}
#if defined(OS_WIN)
@@ -184,6 +203,7 @@ class NullLayerDelegate : public LayerDelegate {
#define MAYBE_Hierarchy DISABLED_Hierarchy
#define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture
#define MAYBE_DrawPixels DISABLED_DrawPixels
+#define MAYBE_CompositorObservers DISABLED_CompositorObservers
#else
#define MAYBE_Delegate Delegate
#define MAYBE_Draw Draw
@@ -191,6 +211,7 @@ class NullLayerDelegate : public LayerDelegate {
#define MAYBE_Hierarchy Hierarchy
#define MAYBE_HierarchyNoTexture HierarchyNoTexture
#define MAYBE_DrawPixels DrawPixels
+#define MAYBE_CompositorObservers CompositorObservers
#endif
TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) {
@@ -804,4 +825,73 @@ 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.
+// TODO(vollick): could be reorganized into compositor_unittest.cc
+TEST_F(LayerWithRealCompositorTest, MAYBE_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.
+ // NOTE: this call to DrawTree sets l1 to be the compositor's root layer.
+ 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);
+
+ // Opacity changes should no longer alert the removed observer.
+ observer.Reset();
+ l2->SetOpacity(0.5f);
+ RunPendingMessages();
+ EXPECT_FALSE(observer.notified());
+}
+
} // namespace ui
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698