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

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: Showing widget for only the focus tests. Created 3 years, 7 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
« no previous file with comments | « ui/views/window/dialog_client_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bb8ec3647fdd6cf49ca65a1934b3cc2727ab9e95..3d933752f6a8a31467bfcf9a9cb069c0bac4e1ae 100644
--- a/ui/views/window/dialog_client_view_unittest.cc
+++ b/ui/views/window/dialog_client_view_unittest.cc
@@ -141,6 +141,8 @@ class DialogClientViewTest : public test::WidgetTest,
DialogClientView* client_view() { return client_view_; }
+ Widget* widget() { return widget_; }
+
private:
// The dialog Widget.
Widget* widget_ = nullptr;
@@ -436,4 +438,31 @@ TEST_F(DialogClientViewTest, ButtonPosition) {
height() + client_view()->ok_button()->y());
}
+// Ensures that the focus of the button remains after a dialog update.
+TEST_F(DialogClientViewTest, FocusUpdate) {
+ // Test with just an ok button.
+ widget()->Show();
+ SetDialogButtons(ui::DIALOG_BUTTON_OK);
+ EXPECT_FALSE(client_view()->ok_button()->HasFocus());
+ client_view()->ok_button()->RequestFocus(); // Set focus.
+ EXPECT_TRUE(client_view()->ok_button()->HasFocus());
+ client_view()->UpdateDialogButtons();
+ EXPECT_TRUE(client_view()->ok_button()->HasFocus());
+}
+
+// Ensures that the focus of the button remains after a dialog update that
+// contains multiple buttons.
+TEST_F(DialogClientViewTest, FocusMultipleButtons) {
+ // Test with ok and cancel buttons.
+ widget()->Show();
+ SetDialogButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK);
+ EXPECT_FALSE(client_view()->ok_button()->HasFocus());
+ EXPECT_FALSE(client_view()->cancel_button()->HasFocus());
+ client_view()->cancel_button()->RequestFocus(); // Set focus.
+ EXPECT_FALSE(client_view()->ok_button()->HasFocus());
+ EXPECT_TRUE(client_view()->cancel_button()->HasFocus());
+ client_view()->UpdateDialogButtons();
+ EXPECT_TRUE(client_view()->cancel_button()->HasFocus());
+}
+
} // namespace views
« no previous file with comments | « 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