Chromium Code Reviews| Index: views/view_unittest.cc |
| diff --git a/views/view_unittest.cc b/views/view_unittest.cc |
| index 3ffd2f55fbbb0a56bb4948457d7c184ebc7db3e5..3a3d788def35b9bc7deb1546f3f955765ccfd530 100644 |
| --- a/views/view_unittest.cc |
| +++ b/views/view_unittest.cc |
| @@ -2111,4 +2111,58 @@ TEST_F(ViewTest, GetIndexOf) { |
| ASSERT_EQ(-1, child2->GetIndexOf(foo1)); |
| } |
| +// Verifies that the child views can be reordered correctly. |
| +TEST_F(ViewTest, ReorderChildren) { |
|
tfarina
2011/06/16 16:18:24
I'd add a comment like this (but it's OK to not to
sadrul
2011/06/16 16:25:01
I think the view hierarchy is pretty self-evident,
Ben Goodger (Google)
2011/06/16 16:25:06
I think you mean:
On 2011/06/16 16:18:24, tfarina
tfarina
2011/06/16 16:28:12
Sure, that why I said I'm OK to not have one. It's
|
| + View root; |
| + |
| + View* child = new View(); |
| + root.AddChildView(child); |
| + |
| + View* foo1 = new View(); |
| + child->AddChildView(foo1); |
| + View* foo2 = new View(); |
| + child->AddChildView(foo2); |
| + View* foo3 = new View(); |
| + child->AddChildView(foo3); |
| + foo1->set_focusable(true); |
| + foo2->set_focusable(true); |
| + foo3->set_focusable(true); |
| + |
| + ASSERT_EQ(0, child->GetIndexOf(foo1)); |
| + ASSERT_EQ(1, child->GetIndexOf(foo2)); |
| + ASSERT_EQ(2, child->GetIndexOf(foo3)); |
| + ASSERT_EQ(foo2, foo1->GetNextFocusableView()); |
| + ASSERT_EQ(foo3, foo2->GetNextFocusableView()); |
| + ASSERT_EQ(NULL, foo3->GetNextFocusableView()); |
| + |
| + // Move |foo2| at the end. |
| + child->ReorderChildView(foo2, -1); |
| + ASSERT_EQ(0, child->GetIndexOf(foo1)); |
| + ASSERT_EQ(1, child->GetIndexOf(foo3)); |
| + ASSERT_EQ(2, child->GetIndexOf(foo2)); |
| + ASSERT_EQ(foo3, foo1->GetNextFocusableView()); |
| + ASSERT_EQ(foo2, foo3->GetNextFocusableView()); |
| + ASSERT_EQ(NULL, foo2->GetNextFocusableView()); |
| + |
| + // Move |foo1| at the end. |
| + child->ReorderChildView(foo1, -1); |
| + ASSERT_EQ(0, child->GetIndexOf(foo3)); |
| + ASSERT_EQ(1, child->GetIndexOf(foo2)); |
| + ASSERT_EQ(2, child->GetIndexOf(foo1)); |
| + ASSERT_EQ(NULL, foo1->GetNextFocusableView()); |
| + ASSERT_EQ(foo2, foo1->GetPreviousFocusableView()); |
| + ASSERT_EQ(foo2, foo3->GetNextFocusableView()); |
| + ASSERT_EQ(foo1, foo2->GetNextFocusableView()); |
| + |
| + // Move |foo2| at the front. |
|
tfarina
2011/06/16 16:18:24
nit: at -> to?
sadrul
2011/06/16 16:25:01
Done.
|
| + child->ReorderChildView(foo2, 0); |
| + ASSERT_EQ(0, child->GetIndexOf(foo2)); |
| + ASSERT_EQ(1, child->GetIndexOf(foo3)); |
| + ASSERT_EQ(2, child->GetIndexOf(foo1)); |
| + ASSERT_EQ(NULL, foo1->GetNextFocusableView()); |
| + ASSERT_EQ(foo3, foo1->GetPreviousFocusableView()); |
| + ASSERT_EQ(foo3, foo2->GetNextFocusableView()); |
| + ASSERT_EQ(foo1, foo3->GetNextFocusableView()); |
| +} |
| + |
| } // namespace views |