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 |