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..5ee93ab9039b96da3e039ad3b6eb107a1c7525bd 100644 |
--- a/ui/views/window/dialog_delegate_unittest.cc |
+++ b/ui/views/window/dialog_delegate_unittest.cc |
@@ -49,6 +49,8 @@ class TestDialog : public DialogDelegateView, public ButtonListener { |
return !title_.empty(); |
} |
+ bool ShouldShowCloseButton() const override { return false; } |
+ |
// DialogDelegateView overrides: |
bool Cancel() override { |
canceled_ = true; |
@@ -128,7 +130,7 @@ class DialogTest : public ViewsTestBase { |
ViewsTestBase::SetUp(); |
dialog_ = new TestDialog(); |
dialog_->Init(); |
- DialogDelegate::CreateDialogWidget(dialog_, GetContext(), nullptr)->Show(); |
+ DialogDelegate::CreateDialogWidget(dialog_, GetContext(), nullptr); |
} |
void TearDown() override { |
@@ -142,6 +144,8 @@ class DialogTest : public ViewsTestBase { |
dialog()->GetWidget()->OnKeyEvent(&event_copy); |
} |
+ void ShowDialog() { dialog()->GetWidget()->Show(); } |
+ |
TestDialog* dialog() const { return dialog_; } |
private: |
@@ -153,6 +157,7 @@ class DialogTest : public ViewsTestBase { |
} // namespace |
TEST_F(DialogTest, AcceptAndCancel) { |
+ ShowDialog(); |
DialogClientView* client_view = dialog()->GetDialogClientView(); |
LabelButton* ok_button = client_view->ok_button(); |
LabelButton* cancel_button = client_view->cancel_button(); |
@@ -187,12 +192,14 @@ TEST_F(DialogTest, AcceptAndCancel) { |
} |
TEST_F(DialogTest, RemoveDefaultButton) { |
+ ShowDialog(); |
// Removing buttons from the dialog here should not cause a crash on close. |
delete dialog()->GetDialogClientView()->ok_button(); |
delete dialog()->GetDialogClientView()->cancel_button(); |
} |
TEST_F(DialogTest, HitTest_HiddenTitle) { |
+ ShowDialog(); |
// Ensure that BubbleFrameView hit-tests as expected when the title is hidden. |
const NonClientView* view = dialog()->GetWidget()->non_client_view(); |
BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); |
@@ -219,6 +226,7 @@ TEST_F(DialogTest, HitTest_HiddenTitle) { |
} |
TEST_F(DialogTest, HitTest_WithTitle) { |
+ ShowDialog(); |
// Ensure that BubbleFrameView hit-tests as expected when the title is shown. |
const NonClientView* view = dialog()->GetWidget()->non_client_view(); |
dialog()->set_title(base::ASCIIToUTF16("Title")); |
@@ -246,6 +254,7 @@ TEST_F(DialogTest, HitTest_WithTitle) { |
} |
TEST_F(DialogTest, BoundsAccommodateTitle) { |
+ ShowDialog(); |
TestDialog* dialog2(new TestDialog()); |
dialog2->set_title(base::ASCIIToUTF16("Title")); |
DialogDelegate::CreateDialogWidget(dialog2, GetContext(), nullptr); |
@@ -267,8 +276,37 @@ TEST_F(DialogTest, BoundsAccommodateTitle) { |
// Tests default focus is assigned correctly when showing a new dialog. |
TEST_F(DialogTest, InitialFocus) { |
+ ShowDialog(); |
EXPECT_TRUE(dialog()->input()->HasFocus()); |
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) { |
+ DialogDelegateView* dialog = new DialogDelegateView(); |
+ Textfield* textfield = new Textfield(); |
+ dialog->AddChildView(textfield); |
+ Widget* dialog_widget = |
+ DialogDelegate::CreateDialogWidget(dialog, GetContext(), nullptr); |
+ |
+ // Turn off focusability on all the dialog's buttons. On Mac, we can just do |
+ // this by turning off full keyboard access. On non-Mac, this will have no |
+ // effect - turn off focusability for Views there manually. |
+ SetFullKeyboardAccessState(dialog_widget, false); |
tapted
2017/01/12 02:25:43
if you do this before creating the widget, I think
Patti Lor
2017/01/12 06:12:37
Oh, that works! Thanks, reverted stuff back.
|
+#if !defined(OS_MACOSX) |
+ 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 |