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

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

Issue 2684403002: Views: Don't advance focus in Widgets when the stored focus view is not null. (Closed)
Patch Set: Check Widget active state instead of StoredFocusView. Created 3 years, 10 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/widget/widget.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_delegate_unittest.cc
diff --git a/ui/views/window/dialog_delegate_unittest.cc b/ui/views/window/dialog_delegate_unittest.cc
index bf2a32ed261a9e6407df775e63355968b8e67448..d11cfddde8f6aabf0595da8212e837a7e92e24b4 100644
--- a/ui/views/window/dialog_delegate_unittest.cc
+++ b/ui/views/window/dialog_delegate_unittest.cc
@@ -277,6 +277,44 @@ TEST_F(DialogTest, InitialFocus) {
EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
}
+// A dialog for testing initial focus with only an OK button.
+class InitialFocusTestDialog : public DialogDelegateView {
+ public:
+ InitialFocusTestDialog() {}
+ ~InitialFocusTestDialog() override {}
+
+ views::View* OkButton() { return GetDialogClientView()->ok_button(); }
+
+ // DialogDelegateView overrides:
+ int GetDialogButtons() const override { return ui::DIALOG_BUTTON_OK; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(InitialFocusTestDialog);
+};
+
+// If the Widget can't be activated while the initial focus View is requesting
+// focus, test it is still able to receive focus once the Widget is activated.
+TEST_F(DialogTest, InitialFocusWithDeactivatedWidget) {
+ InitialFocusTestDialog* dialog = new InitialFocusTestDialog();
+ Widget* dialog_widget =
+ DialogDelegate::CreateDialogWidget(dialog, GetContext(), nullptr);
+ // Set the initial focus while the Widget is unactivated to prevent the
+ // initially focused View from receiving focus. Use a minimised state here to
+ // prevent the Widget from being activated while this happens.
+ dialog_widget->SetInitialFocus(ui::WindowShowState::SHOW_STATE_MINIMIZED);
+
+ // Nothing should be focused, because the Widget is still deactivated.
+ EXPECT_EQ(nullptr, dialog_widget->GetFocusManager()->GetFocusedView());
+ EXPECT_EQ(dialog->OkButton(),
+ dialog_widget->GetFocusManager()->GetStoredFocusView());
+ dialog_widget->Show();
+ // After activation, the initially focused View should have focus as intended.
+ EXPECT_EQ(dialog->OkButton(),
+ dialog_widget->GetFocusManager()->GetFocusedView());
+ EXPECT_TRUE(dialog->OkButton()->HasFocus());
+ dialog_widget->CloseNow();
+}
+
// If the initially focused View provided is unfocusable, check the next
// available focusable View is focused.
TEST_F(DialogTest, UnfocusableInitialFocus) {
@@ -308,7 +346,7 @@ TEST_F(DialogTest, UnfocusableInitialFocus) {
dialog_widget->Show();
EXPECT_TRUE(textfield->HasFocus());
EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView());
- dialog_widget->Close();
+ dialog_widget->CloseNow();
}
} // namespace views
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698