Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/base/hit_test.h" | 9 #include "ui/base/hit_test.h" |
| 10 #include "ui/events/event_processor.h" | 10 #include "ui/events/event_processor.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 // DialogDelegateView overrides: | 51 // DialogDelegateView overrides: |
| 52 bool Cancel() override { | 52 bool Cancel() override { |
| 53 canceled_ = true; | 53 canceled_ = true; |
| 54 return closeable_; | 54 return closeable_; |
| 55 } | 55 } |
| 56 bool Accept() override { | 56 bool Accept() override { |
| 57 accepted_ = true; | 57 accepted_ = true; |
| 58 return closeable_; | 58 return closeable_; |
| 59 } | 59 } |
| 60 bool Close() override { | |
| 61 return closeable_; | |
| 62 } | |
| 60 | 63 |
| 61 // DialogDelegateView overrides: | 64 // DialogDelegateView overrides: |
| 62 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } | 65 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } |
| 63 bool AcceleratorPressed(const ui::Accelerator& accelerator) override { | 66 bool AcceleratorPressed(const ui::Accelerator& accelerator) override { |
| 64 return should_handle_escape_; | 67 return should_handle_escape_; |
| 65 } | 68 } |
| 66 base::string16 GetWindowTitle() const override { return title_; } | 69 base::string16 GetWindowTitle() const override { return title_; } |
| 67 View* GetInitiallyFocusedView() override { return input_; } | 70 View* GetInitiallyFocusedView() override { return input_; } |
| 68 bool UseNewStyleForThisDialog() const override { return true; } | 71 bool UseNewStyleForThisDialog() const override { return true; } |
| 69 | 72 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 DISALLOW_COPY_AND_ASSIGN(DialogTest); | 142 DISALLOW_COPY_AND_ASSIGN(DialogTest); |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 } // namespace | 145 } // namespace |
| 143 | 146 |
| 144 TEST_F(DialogTest, AcceptAndCancel) { | 147 TEST_F(DialogTest, AcceptAndCancel) { |
| 145 DialogClientView* client_view = dialog()->GetDialogClientView(); | 148 DialogClientView* client_view = dialog()->GetDialogClientView(); |
| 146 LabelButton* ok_button = client_view->ok_button(); | 149 LabelButton* ok_button = client_view->ok_button(); |
| 147 LabelButton* cancel_button = client_view->cancel_button(); | 150 LabelButton* cancel_button = client_view->cancel_button(); |
| 148 | 151 |
| 149 // Check that return/escape accelerators accept/cancel dialogs. | 152 // Check that return/escape accelerators accept/close dialogs. |
| 150 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); | 153 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); |
| 151 const ui::KeyEvent return_event( | 154 const ui::KeyEvent return_event( |
| 152 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); | 155 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); |
| 153 SimulateKeyEvent(return_event); | 156 SimulateKeyEvent(return_event); |
| 154 dialog()->CheckAndResetStates(false, true, nullptr); | 157 dialog()->CheckAndResetStates(false, true, nullptr); |
| 155 const ui::KeyEvent escape_event( | 158 const ui::KeyEvent escape_event( |
| 156 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); | 159 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); |
| 157 SimulateKeyEvent(escape_event); | 160 SimulateKeyEvent(escape_event); |
| 158 dialog()->CheckAndResetStates(true, false, nullptr); | 161 dialog()->CheckAndResetStates(false, false, nullptr); |
|
msw
2016/05/10 18:23:32
Can you add a test case that Esc closes the dialog
Evan Stade
2016/05/10 19:27:35
Done.
| |
| 159 | 162 |
| 160 // Check ok and cancel button behavior on a directed return key events. | 163 // Check ok and cancel button behavior on a directed return key events. |
| 161 ok_button->OnKeyPressed(return_event); | 164 ok_button->OnKeyPressed(return_event); |
| 162 dialog()->CheckAndResetStates(false, true, nullptr); | 165 dialog()->CheckAndResetStates(false, true, nullptr); |
| 163 cancel_button->OnKeyPressed(return_event); | 166 cancel_button->OnKeyPressed(return_event); |
| 164 dialog()->CheckAndResetStates(true, false, nullptr); | 167 dialog()->CheckAndResetStates(true, false, nullptr); |
| 165 | 168 |
| 166 // Check that return accelerators cancel dialogs if cancel is focused. | 169 // Check that return accelerators cancel dialogs if cancel is focused. |
| 167 cancel_button->RequestFocus(); | 170 cancel_button->RequestFocus(); |
| 168 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView()); | 171 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 dialog2->TearDown(); | 257 dialog2->TearDown(); |
| 255 } | 258 } |
| 256 | 259 |
| 257 // Tests default focus is assigned correctly when showing a new dialog. | 260 // Tests default focus is assigned correctly when showing a new dialog. |
| 258 TEST_F(DialogTest, InitialFocus) { | 261 TEST_F(DialogTest, InitialFocus) { |
| 259 EXPECT_TRUE(dialog()->input()->HasFocus()); | 262 EXPECT_TRUE(dialog()->input()->HasFocus()); |
| 260 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); | 263 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); |
| 261 } | 264 } |
| 262 | 265 |
| 263 } // namespace views | 266 } // namespace views |
| OLD | NEW |