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..ab9db3b1560db840640ebaf8c03f3579650db2e2 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; } |
tapted
2017/01/06 11:45:15
This makes the test a bit "unauthentic". That is,
Patti Lor
2017/01/12 02:16:22
Apparently you have to call [bridge_->ns_view() up
|
+ |
// 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,26 @@ 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) { |
+ // Make the View to focus by default unfocusable, and add a second View that |
+ // will be the first in the focus traversal order. |
+ dialog()->input()->SetFocusBehavior(View::FocusBehavior::NEVER); |
tapted
2017/01/06 11:45:15
My approach here would be something like do this l
Patti Lor
2017/01/12 02:16:22
With keyboard-focus off on Mac, I think we don't n
tapted
2017/01/12 02:25:43
yep - that makes sense - buttons are skipped with
Patti Lor
2017/01/12 06:12:37
Sorry, by the close button I meant the little 'x'
|
+ Textfield* textfield = new Textfield(); |
+ dialog()->AddChildView(textfield); |
+ |
+ // On showing the dialog, the default focus item shouldn't have focus, but |
+ // |textfield| should. |
+ ShowDialog(); |
+ EXPECT_FALSE(dialog()->input()->HasFocus()); |
+ EXPECT_TRUE(textfield->HasFocus()); |
+ EXPECT_EQ(textfield, dialog()->GetFocusManager()->GetFocusedView()); |
+} |
+ |
} // namespace views |