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

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: Rebased + Some updates Created 6 years, 4 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
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 544e9997450b7643b940e0d388a0c42600f241ec..b2712487278df19f61d22aa0e584253b49977a7b 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -2642,6 +2642,55 @@ TEST_F(ViewTest, AddExistingChild) {
}
////////////////////////////////////////////////////////////////////////////////
+// FocusManager
+////////////////////////////////////////////////////////////////////////////////
+
+TEST_F(ViewTest, ReviseFocusedViewForUnfocusableView) {
+ // Create a widget with two views and give the first one focus.
+ Widget widget;
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget.Init(params);
+ widget.Activate();
sky 2014/08/07 21:40:34 I suspect doing this is going to require the test
mohsen 2014/08/08 01:32:07 This test is not meant to test activation. It is o
sky 2014/08/08 14:52:30 You're new code triggers calling off to NativeWidg
mohsen 2014/08/08 17:45:07 I guess by NativeWidgetDelegate you mean NativeWid
+
+ View* view1 = new View();
+ view1->SetFocusable(true);
+ widget.GetRootView()->AddChildView(view1);
+ View* view2 = new View();
+ view2->SetFocusable(true);
+ widget.GetRootView()->AddChildView(view2);
+
+ FocusManager* focus_manager = widget.GetFocusManager();
+ ASSERT_TRUE(focus_manager);
+
+ focus_manager->SetFocusedView(view1);
+ EXPECT_EQ(view1, focus_manager->GetFocusedView());
+
+ // Disable the focused view and check if the next view gets focused.
+ view1->SetEnabled(false);
+ EXPECT_EQ(view2, focus_manager->GetFocusedView());
+
+ // Re-enable and re-focus.
+ view1->SetEnabled(true);
+ focus_manager->SetFocusedView(view1);
+ EXPECT_EQ(view1, focus_manager->GetFocusedView());
+
+ // Hide the focused view and check it the next view gets focused.
+ view1->SetVisible(false);
+ EXPECT_EQ(view2, focus_manager->GetFocusedView());
+
+ // Re-show and re-focus.
+ view1->SetVisible(true);
+ focus_manager->SetFocusedView(view1);
+ EXPECT_EQ(view1, focus_manager->GetFocusedView());
+
+ // Set the focused view as not focusable and check if the next view gets
+ // focused.
+ view1->SetFocusable(false);
+ EXPECT_EQ(view2, focus_manager->GetFocusedView());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Layers
////////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698