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

Unified Diff: views/view_unittest.cc

Issue 7185005: Add View::ReorderChildView and Widget::MoveToTop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test Created 9 years, 6 months 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 | « views/view.cc ('k') | views/widget/native_widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/view_unittest.cc
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 3ffd2f55fbbb0a56bb4948457d7c184ebc7db3e5..863a15709ff1d072d9df219fe6af21320f2ad1c2 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -2111,4 +2111,47 @@ TEST_F(ViewTest, GetIndexOf) {
ASSERT_EQ(-1, child2->GetIndexOf(foo1));
}
+// Verifies that the child views can be reordered correctly.
+TEST_F(ViewTest, ReorderChildren) {
+ 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.
tfarina 2011/06/16 15:59:42 Could you test adding it to another position besid
sadrul 2011/06/16 16:12:54 Done.
+ 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, foo3->GetNextFocusableView());
+ ASSERT_EQ(foo1, foo2->GetNextFocusableView());
+}
tfarina 2011/06/16 15:59:42 Nice! Thanks for adding it. Looks good.
+
} // namespace views
« no previous file with comments | « views/view.cc ('k') | views/widget/native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698