Chromium Code Reviews| Index: ui/views/window/dialog_client_view_unittest.cc |
| diff --git a/ui/views/window/dialog_client_view_unittest.cc b/ui/views/window/dialog_client_view_unittest.cc |
| index a8d3d8d79c222a876312009c96f65ee9328bfbb9..ce3633b3fd866a850962842b09cd53db5d1163b8 100644 |
| --- a/ui/views/window/dialog_client_view_unittest.cc |
| +++ b/ui/views/window/dialog_client_view_unittest.cc |
| @@ -405,4 +405,33 @@ TEST_F(DialogClientViewTest, LinkedWidths) { |
| EXPECT_EQ(20, boring_view->width()); |
| } |
| +// Tests that the default focus of the button reamins after a dialog update. |
| +TEST_F(DialogClientViewTest, DefaultFocus) { |
| + // Test with just an ok button. |
| + SetDialogButtons(ui::DIALOG_BUTTON_OK); |
| + EXPECT_EQ(GetInitiallyFocusedView(), client_view()->ok_button()); |
|
Devlin
2017/04/12 19:36:31
nitty nit: EXPECT_EQ(expected, actual)
Ackerman
2017/04/28 18:22:59
Done.
|
| + GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. |
| + EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| + client_view()->UpdateDialogButtons(); |
| + EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| + |
| + // Test with just a cancel button. |
| + SetDialogButtons(ui::DIALOG_BUTTON_CANCEL); |
| + EXPECT_EQ(GetInitiallyFocusedView(), client_view()->cancel_button()); |
| + GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. |
| + EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); |
| + client_view()->UpdateDialogButtons(); |
| + EXPECT_TRUE(client_view()->cancel_button()->HasFocus()); |
| + |
| + // Test with both buttons, the ok button is default. |
| + SetDialogButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK); |
| + EXPECT_EQ(GetInitiallyFocusedView(), client_view()->ok_button()); |
| + GetInitiallyFocusedView()->RequestFocus(); // Focus is not given by default. |
| + EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| + EXPECT_FALSE(client_view()->cancel_button()->HasFocus()); |
| + client_view()->UpdateDialogButtons(); |
| + EXPECT_TRUE(client_view()->ok_button()->HasFocus()); |
| + EXPECT_FALSE(client_view()->cancel_button()->HasFocus()); |
| +} |
| + |
| } // namespace views |