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

Unified Diff: ui/views/view_unittest.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted to common code into FocusManager class Created 7 years 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
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 264da270b417122b8b93fcd592f2ecdb6b327f47..25b99e75486fc3ff03b168d664e10c6630855ce6 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -2770,9 +2770,9 @@ TEST_F(ViewTest, ReorderChildren) {
child->AddChildView(foo2);
View* foo3 = new View();
child->AddChildView(foo3);
- foo1->set_focusable(true);
- foo2->set_focusable(true);
- foo3->set_focusable(true);
+ foo1->SetFocusable(true);
+ foo2->SetFocusable(true);
+ foo3->SetFocusable(true);
ASSERT_EQ(0, child->GetIndexOf(foo1));
ASSERT_EQ(1, child->GetIndexOf(foo2));
@@ -2897,6 +2897,50 @@ TEST_F(ViewTest, AddExistingChild) {
}
////////////////////////////////////////////////////////////////////////////////
+// FocusManager
+////////////////////////////////////////////////////////////////////////////////
+
+TEST_F(ViewTest, ClearFocusIfUnfocusable) {
+ // Create a View and focus it.
+ View* view = new View();
+ view->SetFocusable(true);
+
+ scoped_ptr<Widget> widget(new Widget());
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget->Init(params);
+ widget->GetRootView()->AddChildView(view);
+
+ FocusManager* focus_manager = widget->GetFocusManager();
+ ASSERT_TRUE(focus_manager);
+
+ focus_manager->SetFocusedView(view);
+ EXPECT_EQ(view, focus_manager->GetFocusedView());
+
+ // Disable the focused view and check if it loses focus.
+ view->SetEnabled(false);
+ EXPECT_EQ(NULL, focus_manager->GetFocusedView());
+
+ // Re-enable and re-focus.
+ view->SetEnabled(true);
+ focus_manager->SetFocusedView(view);
+ EXPECT_EQ(view, focus_manager->GetFocusedView());
+
+ // Hide the focused view and check it it loses focus.
+ view->SetVisible(false);
+ EXPECT_EQ(NULL, focus_manager->GetFocusedView());
+
+ // Re-show and re-focus.
+ view->SetVisible(true);
+ focus_manager->SetFocusedView(view);
+ EXPECT_EQ(view, focus_manager->GetFocusedView());
+
+ // Set as not focusable and check if it loses focus.
+ view->SetFocusable(false);
+ EXPECT_EQ(NULL, focus_manager->GetFocusedView());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Layers
////////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698