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

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: Try to advance focus first 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
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/widget_interactive_uitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 264da270b417122b8b93fcd592f2ecdb6b327f47..5bcc2b17126a88073864cd3c78a7043e9c62b787 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,96 @@ TEST_F(ViewTest, AddExistingChild) {
}
////////////////////////////////////////////////////////////////////////////////
+// FocusManager
+////////////////////////////////////////////////////////////////////////////////
+
+TEST_F(ViewTest, ReviseFocusedViewForUnfocusableView) {
+ // 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());
+}
+
+TEST_F(ViewTest, DisableViewDoesNotActivateWidget) {
sky 2013/12/13 17:41:57 Focus related tests need to be in interactive_ui_t
+ // Create first widget and view, activate the widget, and focus the view.
+ scoped_ptr<Widget> widget1(new Widget());
+ Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget1->Init(params1);
+
+ View* view1 = new View();
+ view1->SetFocusable(true);
+ widget1->GetRootView()->AddChildView(view1);
+
+ widget1->Activate();
+ EXPECT_TRUE(widget1->IsActive());
+
+ FocusManager* focus_manager1 = widget1->GetFocusManager();
+ ASSERT_TRUE(focus_manager1);
+ focus_manager1->SetFocusedView(view1);
+ EXPECT_EQ(view1, focus_manager1->GetFocusedView());
+
+ // Create second widget and view, activate the widget, and focus the view.
+ scoped_ptr<Widget> widget2(new Widget());
+ Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget2->Init(params2);
+
+ View* view2 = new View();
+ view2->SetFocusable(true);
+ widget2->GetRootView()->AddChildView(view2);
+
+ widget2->Activate();
+ EXPECT_TRUE(widget2->IsActive());
+ EXPECT_FALSE(widget1->IsActive());
+
+ FocusManager* focus_manager2 = widget2->GetFocusManager();
+ ASSERT_TRUE(focus_manager2);
+ focus_manager2->SetFocusedView(view2);
+ EXPECT_EQ(view2, focus_manager2->GetFocusedView());
+
+ // Disable the first view and make sure it loses focus, but its widget is not
+ // activated.
+ view1->SetEnabled(false);
+ EXPECT_NE(view1, focus_manager1->GetFocusedView());
+ EXPECT_FALSE(widget1->IsActive());
+ EXPECT_TRUE(widget2->IsActive());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Layers
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/widget_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698