Index: ui/views/view_unittest.cc |
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc |
index 42ba4f3319b73c539f34d668a01a900a3f1d522c..592aa83ade895e0a76a278d8450687d8659ccac7 100644 |
--- a/ui/views/view_unittest.cc |
+++ b/ui/views/view_unittest.cc |
@@ -5023,4 +5023,81 @@ TEST_F(ViewObserverTest, ChildViewReordered) { |
EXPECT_EQ(child_view2.get(), view_reordered()); |
} |
+// Remove this ifdef once AURA is enabled for MAC. |
+#if !defined(OS_MACOSX) |
sky
2017/04/18 23:02:21
I don't think you need the ifdef, instead early ou
|
+// Validates that if a child of a ScrollView adds a layer, then a layer |
+// is added to the ScrollView's viewport. |
+TEST_F(ViewObserverTest, ScrollViewChildAddLayerTest) { |
+ std::unique_ptr<ScrollView> scroll_view(new ScrollView()); |
+ scroll_view->SetContents(new View()); |
+ EXPECT_FALSE(scroll_view->contents_viewport_->layer()); |
+ |
+ std::unique_ptr<View> child_view = NewView(); |
+ scroll_view->AddChildView(child_view.get()); |
+ child_view->SetPaintToLayer(ui::LAYER_TEXTURED); |
+ |
+ EXPECT_TRUE(scroll_view->contents_viewport_->layer()); |
+ scroll_view->RemoveChildView(child_view.get()); |
+} |
+ |
+// Provides a simple parent view implementation which tracks layer change |
+// notifications from child views. |
+class TestParentView : public View { |
+ public: |
+ TestParentView() |
+ : View(), |
sky
2017/04/18 23:02:21
This line isn't necessary.
ananta
2017/04/18 23:14:46
Done.
|
+ received_layer_change_notification_(false), |
+ layer_change_count_(0) {} |
+ |
+ void Reset() { |
+ received_layer_change_notification_ = false; |
+ layer_change_count_ = 0; |
+ } |
+ |
+ bool received_layer_change_notification() const { |
+ return received_layer_change_notification_; |
+ } |
+ |
+ int layer_change_count() const { return layer_change_count_; } |
+ |
+ // View overrides. |
+ void OnChildLayerChanged(View* child) override { |
+ received_layer_change_notification_ = true; |
+ layer_change_count_++; |
+ } |
+ |
+ private: |
+ // Set to true if we receive the OnChildLayerChanged() notification for a |
+ // child. |
+ bool received_layer_change_notification_; |
+ |
+ // Contains the number of OnChildLayerChanged() notifications for a child. |
+ int layer_change_count_; |
+}; |
sky
2017/04/18 23:02:21
DISALLOW...
ananta
2017/04/18 23:14:46
Done.
|
+ |
+// Tests the following cases. |
+// 1. We receive the OnChildLayerChanged() notification when a layer change |
+// occurs in a child view. |
+// 2. We don't receive two layer changes when a child with an existing layer |
+// creates a new layer. |
+TEST_F(ViewObserverTest, ChildViewLayerNotificationTest) { |
+ std::unique_ptr<TestParentView> parent_view(new TestParentView); |
+ std::unique_ptr<View> child_view = NewView(); |
+ parent_view->AddChildView(child_view.get()); |
+ |
+ EXPECT_FALSE(parent_view->received_layer_change_notification()); |
+ EXPECT_EQ(parent_view->layer_change_count(), 0); |
sky
2017/04/18 23:02:21
Generally we go with expected, actual, e.g.
EXPECT
ananta
2017/04/18 23:14:46
Done.
|
+ |
+ child_view->SetPaintToLayer(ui::LAYER_TEXTURED); |
+ EXPECT_TRUE(parent_view->received_layer_change_notification()); |
+ EXPECT_EQ(parent_view->layer_change_count(), 1); |
+ |
+ parent_view->Reset(); |
+ child_view->SetPaintToLayer(ui::LAYER_SOLID_COLOR); |
+ EXPECT_TRUE(parent_view->received_layer_change_notification()); |
+ EXPECT_EQ(parent_view->layer_change_count(), 1); |
+} |
+ |
+#endif // OS_MACOSX |
+ |
} // namespace views |