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

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

Issue 2807653002: Ensure default dialog button focus remains after a dialog update. (Closed)
Patch Set: Addressing Devlin's comments. Created 3 years, 8 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
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..077233688a8a9963896cdd737091e603898117c7 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.
sky 2017/04/28 20:49:52 Just to be clear, does these tests fail without yo
ackermanb 2017/05/17 17:20:54 Yep, the tests do fail out without the patch.
+TEST_F(DialogClientViewTest, DefaultFocus) {
+ // Test with just an ok button.
+ SetDialogButtons(ui::DIALOG_BUTTON_OK);
+ EXPECT_EQ(client_view()->ok_button(), GetInitiallyFocusedView());
+ 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(client_view()->cancel_button(), GetInitiallyFocusedView());
+ 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(client_view()->ok_button(), GetInitiallyFocusedView());
+ 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
« ui/views/window/dialog_client_view.cc ('K') | « ui/views/window/dialog_client_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698