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

Unified Diff: ui/views/window/dialog_delegate_unittest.cc

Issue 2604303002: (Mac)Views: Widgets focus first View in traversal order if initial focus fails. (Closed)
Patch Set: Review comments. Created 3 years, 11 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 | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/window/dialog_delegate_unittest.cc
diff --git a/ui/views/window/dialog_delegate_unittest.cc b/ui/views/window/dialog_delegate_unittest.cc
index 648175d8d23eb5dca090e03ed87a97c4d3fa4972..9e286eb01cbdef95817bf681ef2ffe66dafc587a 100644
--- a/ui/views/window/dialog_delegate_unittest.cc
+++ b/ui/views/window/dialog_delegate_unittest.cc
@@ -18,6 +18,10 @@
#include "ui/views/window/dialog_client_view.h"
#include "ui/views/window/dialog_delegate.h"
+#if defined(OS_MACOSX)
+#include "ui/base/test/scoped_fake_full_keyboard_access.h"
+#endif
+
namespace views {
namespace {
@@ -271,4 +275,38 @@ TEST_F(DialogTest, InitialFocus) {
EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
}
+// If the initially focused View provided is unfocusable, check the next
+// available focusable View is focused.
+TEST_F(DialogTest, UnfocusableInitialFocus) {
+#if defined(OS_MACOSX)
+ // On Mac, make all buttons unfocusable by turning off full keyboard access.
+ // This is the more common configuration, and if a dialog has a focusable
+ // textfield, tree or table, that should obtain focus instead.
+ ui::test::ScopedFakeFullKeyboardAccess::GetInstance()
+ ->set_full_keyboard_access_state(false);
+#endif
+
+ DialogDelegateView* dialog = new DialogDelegateView();
+ Textfield* textfield = new Textfield();
+ dialog->AddChildView(textfield);
+ Widget* dialog_widget =
+ DialogDelegate::CreateDialogWidget(dialog, GetContext(), nullptr);
+
+#if !defined(OS_MACOSX)
+ // For non-Mac, turn off focusability on all the dialog's buttons manually.
+ // This achieves the same effect as disabling full keyboard access.
+ DialogClientView* dcv = dialog->GetDialogClientView();
+ dcv->ok_button()->SetFocusBehavior(View::FocusBehavior::NEVER);
+ dcv->cancel_button()->SetFocusBehavior(View::FocusBehavior::NEVER);
+#endif
+
+ // On showing the dialog, the initially focused View will be the OK button.
+ // Since it is no longer focusable, focus should advance to the next focusable
+ // View, which is |textfield|.
+ dialog_widget->Show();
+ EXPECT_TRUE(textfield->HasFocus());
+ EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView());
+ dialog_widget->Close();
+}
+
} // namespace views
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698