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

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

Issue 1759453002: Convert location bar bubble delegates to bubble dialog delegates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ImmersiveFullscreenController Created 4 years, 9 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_delegate_unittest.cc
diff --git a/ui/views/window/dialog_delegate_unittest.cc b/ui/views/window/dialog_delegate_unittest.cc
index 124e0e49996d2d0ea6a7151afba52c8b6d1b6faf..df9d192de8a198b6c8cf6f30ed74a8385f9e9003 100644
--- a/ui/views/window/dialog_delegate_unittest.cc
+++ b/ui/views/window/dialog_delegate_unittest.cc
@@ -33,11 +33,20 @@ class TestDialog : public DialogDelegateView, public ButtonListener {
canceled_(false),
accepted_(false),
closeable_(false),
- last_pressed_button_(NULL) {
+ last_pressed_button_(nullptr),
+ should_handle_escape_(false) {
AddChildView(input_);
}
~TestDialog() override {}
+ void Init() {
+ // Add the accelerator before being added to the widget hierarchy (before
+ // DCV has registered its accelerator) to make sure accelerator handling is
+ // not dependent on the order of AddAccelerator calls.
+ EXPECT_FALSE(GetWidget());
+ AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
+ }
+
// WidgetDelegate overrides:
bool ShouldShowWindowTitle() const override {
return !title_.empty();
@@ -55,6 +64,9 @@ class TestDialog : public DialogDelegateView, public ButtonListener {
// DialogDelegateView overrides:
gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
+ bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
+ return should_handle_escape_;
+ }
base::string16 GetWindowTitle() const override { return title_; }
View* GetInitiallyFocusedView() override { return input_; }
bool UseNewStyleForThisDialog() const override { return true; }
@@ -72,7 +84,7 @@ class TestDialog : public DialogDelegateView, public ButtonListener {
EXPECT_EQ(accepted, accepted_);
accepted_ = false;
EXPECT_EQ(last_pressed, last_pressed_button_);
- last_pressed_button_ = NULL;
+ last_pressed_button_ = nullptr;
}
void TearDown() {
@@ -81,6 +93,9 @@ class TestDialog : public DialogDelegateView, public ButtonListener {
}
void set_title(const base::string16& title) { title_ = title; }
+ void set_should_handle_escape(bool should_handle_escape) {
+ should_handle_escape_ = should_handle_escape;
+ }
views::Textfield* input() { return input_; }
@@ -92,19 +107,21 @@ class TestDialog : public DialogDelegateView, public ButtonListener {
bool closeable_;
Button* last_pressed_button_;
base::string16 title_;
+ bool should_handle_escape_;
DISALLOW_COPY_AND_ASSIGN(TestDialog);
};
class DialogTest : public ViewsTestBase {
public:
- DialogTest() : dialog_(NULL) {}
+ DialogTest() : dialog_(nullptr) {}
~DialogTest() override {}
void SetUp() override {
ViewsTestBase::SetUp();
dialog_ = new TestDialog();
- DialogDelegate::CreateDialogWidget(dialog_, GetContext(), NULL)->Show();
+ dialog_->Init();
+ DialogDelegate::CreateDialogWidget(dialog_, GetContext(), nullptr)->Show();
}
void TearDown() override {
@@ -144,23 +161,28 @@ TEST_F(DialogTest, AcceptAndCancel) {
const ui::KeyEvent return_event(
ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE);
SimulateKeyEvent(return_event);
- dialog()->CheckAndResetStates(false, true, NULL);
+ dialog()->CheckAndResetStates(false, true, nullptr);
const ui::KeyEvent escape_event(
ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
SimulateKeyEvent(escape_event);
- dialog()->CheckAndResetStates(true, false, NULL);
+ dialog()->CheckAndResetStates(true, false, nullptr);
// Check ok and cancel button behavior on a directed return key events.
ok_button->OnKeyPressed(return_event);
- dialog()->CheckAndResetStates(false, true, NULL);
+ dialog()->CheckAndResetStates(false, true, nullptr);
cancel_button->OnKeyPressed(return_event);
- dialog()->CheckAndResetStates(true, false, NULL);
+ dialog()->CheckAndResetStates(true, false, nullptr);
// Check that return accelerators cancel dialogs if cancel is focused.
cancel_button->RequestFocus();
EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView());
SimulateKeyEvent(return_event);
- dialog()->CheckAndResetStates(true, false, NULL);
+ dialog()->CheckAndResetStates(true, false, nullptr);
+
+ // Check that escape can be overridden.
+ dialog()->set_should_handle_escape(true);
+ SimulateKeyEvent(escape_event);
+ dialog()->CheckAndResetStates(false, false, nullptr);
}
TEST_F(DialogTest, RemoveDefaultButton) {
@@ -224,7 +246,7 @@ TEST_F(DialogTest, HitTest_WithTitle) {
TEST_F(DialogTest, BoundsAccommodateTitle) {
TestDialog* dialog2(new TestDialog());
dialog2->set_title(base::ASCIIToUTF16("Title"));
- DialogDelegate::CreateDialogWidget(dialog2, GetContext(), NULL);
+ DialogDelegate::CreateDialogWidget(dialog2, GetContext(), nullptr);
// Titled dialogs have taller initial frame bounds than untitled dialogs.
View* frame1 = dialog()->GetWidget()->non_client_view()->frame_view();
« ash/wm/immersive_fullscreen_controller.h ('K') | « ui/views/window/dialog_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698