Index: mojo/services/public/cpp/view_manager/tests/view_unittest.cc |
diff --git a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc |
index c63089eeddd38915d0e7b47b1ded4b4de58ab61b..3f08075050e9375a28c3d8d0036e2feff66923dc 100644 |
--- a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc |
+++ b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc |
@@ -85,6 +85,23 @@ TEST_F(ViewTest, GetChildById) { |
EXPECT_EQ(&v111, v1.GetChildById(v111.id())); |
} |
+TEST_F(ViewTest, DrawnAndVisible) { |
+ TestView v1; |
+ EXPECT_TRUE(v1.visible()); |
+ EXPECT_FALSE(v1.IsDrawn()); |
+ |
+ ViewPrivate(&v1).set_drawn(true); |
+ |
+ TestView v11; |
+ v1.AddChild(&v11); |
+ EXPECT_TRUE(v11.visible()); |
+ EXPECT_TRUE(v11.IsDrawn()); |
+ |
+ v1.RemoveChild(&v11); |
+ EXPECT_TRUE(v11.visible()); |
+ EXPECT_FALSE(v11.IsDrawn()); |
+} |
+ |
// ViewObserver -------------------------------------------------------- |
typedef testing::Test ViewObserverTest; |
@@ -393,7 +410,7 @@ TEST_F(ViewObserverTest, Order) { |
EXPECT_EQ(&v11, v1.children().back()); |
OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
- EXPECT_EQ(2U, changes.size()); |
+ ASSERT_EQ(2U, changes.size()); |
EXPECT_EQ(&v11, changes[0].view); |
EXPECT_EQ(&v13, changes[0].relative_view); |
EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[0].direction); |
@@ -413,7 +430,7 @@ TEST_F(ViewObserverTest, Order) { |
EXPECT_EQ(&v13, v1.children().back()); |
OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
- EXPECT_EQ(2U, changes.size()); |
+ ASSERT_EQ(2U, changes.size()); |
EXPECT_EQ(&v11, changes[0].view); |
EXPECT_EQ(&v12, changes[0].relative_view); |
EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[0].direction); |
@@ -433,7 +450,7 @@ TEST_F(ViewObserverTest, Order) { |
EXPECT_EQ(&v13, v1.children().back()); |
OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
- EXPECT_EQ(2U, changes.size()); |
+ ASSERT_EQ(2U, changes.size()); |
EXPECT_EQ(&v11, changes[0].view); |
EXPECT_EQ(&v12, changes[0].relative_view); |
EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[0].direction); |
@@ -453,7 +470,7 @@ TEST_F(ViewObserverTest, Order) { |
EXPECT_EQ(&v13, v1.children().back()); |
OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
- EXPECT_EQ(2U, changes.size()); |
+ ASSERT_EQ(2U, changes.size()); |
EXPECT_EQ(&v11, changes[0].view); |
EXPECT_EQ(&v12, changes[0].relative_view); |
EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[0].direction); |
@@ -531,7 +548,7 @@ TEST_F(ViewObserverTest, SetBounds) { |
v1.SetBounds(gfx::Rect(0, 0, 100, 100)); |
Changes changes = observer.GetAndClearChanges(); |
- EXPECT_EQ(2U, changes.size()); |
+ ASSERT_EQ(2U, changes.size()); |
EXPECT_EQ( |
"view=0,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100 phase=changing", |
changes[0]); |
@@ -541,4 +558,62 @@ TEST_F(ViewObserverTest, SetBounds) { |
} |
} |
+namespace { |
+ |
+class VisibilityChangeObserver : public ViewObserver { |
+ public: |
+ explicit VisibilityChangeObserver(View* view) : view_(view) { |
+ view_->AddObserver(this); |
+ } |
+ virtual ~VisibilityChangeObserver() { view_->RemoveObserver(this); } |
+ |
+ Changes GetAndClearChanges() { |
+ Changes changes; |
+ changes.swap(changes_); |
+ return changes; |
+ } |
+ |
+ private: |
+ // Overridden from ViewObserver: |
+ virtual void OnViewVisibilityChanging(View* view) OVERRIDE { |
+ changes_.push_back( |
+ base::StringPrintf("view=%s phase=changing visibility=%s", |
+ ViewIdToString(view->id()).c_str(), |
+ view->visible() ? "true" : "false")); |
+ } |
+ virtual void OnViewVisibilityChanged(View* view) OVERRIDE { |
+ changes_.push_back(base::StringPrintf("view=%s phase=changed visibility=%s", |
+ ViewIdToString(view->id()).c_str(), |
+ view->visible() ? "true" : "false")); |
+ } |
+ |
+ View* view_; |
+ Changes changes_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); |
+}; |
+ |
+} // namespace |
+ |
+TEST_F(ViewObserverTest, SetVisible) { |
+ TestView v1; |
+ EXPECT_TRUE(v1.visible()); |
+ { |
+ // Change visibility from true to false and make sure we get notifications. |
+ VisibilityChangeObserver observer(&v1); |
+ v1.SetVisible(false); |
+ |
+ Changes changes = observer.GetAndClearChanges(); |
+ ASSERT_EQ(2U, changes.size()); |
+ EXPECT_EQ("view=0,1 phase=changing visibility=true", changes[0]); |
+ EXPECT_EQ("view=0,1 phase=changed visibility=false", changes[1]); |
+ } |
+ { |
+ // Set visible to existing value and verify no notifications. |
+ VisibilityChangeObserver observer(&v1); |
+ v1.SetVisible(false); |
+ EXPECT_TRUE(observer.GetAndClearChanges().empty()); |
+ } |
+} |
+ |
} // namespace mojo |