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

Side by Side Diff: ui/views/window/dialog_delegate_unittest.cc

Issue 2607923002: MacViews: Handle Space and Return keys correctly for Buttons. (Closed)
Patch Set: Address review. Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); 149 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
150 const ui::KeyEvent return_event( 150 const ui::KeyEvent return_event(
151 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); 151 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE);
152 SimulateKeyEvent(return_event); 152 SimulateKeyEvent(return_event);
153 dialog()->CheckAndResetStates(false, true, false); 153 dialog()->CheckAndResetStates(false, true, false);
154 const ui::KeyEvent escape_event( 154 const ui::KeyEvent escape_event(
155 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); 155 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
156 SimulateKeyEvent(escape_event); 156 SimulateKeyEvent(escape_event);
157 dialog()->CheckAndResetStates(false, false, true); 157 dialog()->CheckAndResetStates(false, false, true);
158 158
159 // Check ok and cancel button behavior on a directed return key events. 159 // Check ok and cancel button behavior on a directed return key event. Buttons
160 ok_button->OnKeyPressed(return_event); 160 // won't respond to a return key event on Mac, since it performs the default
161 // action.
162 #if defined(OS_MACOSX)
163 EXPECT_FALSE(ok_button->OnKeyPressed(return_event));
164 dialog()->CheckAndResetStates(false, false, false);
165 EXPECT_FALSE(cancel_button->OnKeyPressed(return_event));
166 dialog()->CheckAndResetStates(false, false, false);
167 #else
168 EXPECT_TRUE(ok_button->OnKeyPressed(return_event));
161 dialog()->CheckAndResetStates(false, true, false); 169 dialog()->CheckAndResetStates(false, true, false);
162 cancel_button->OnKeyPressed(return_event); 170 EXPECT_TRUE(cancel_button->OnKeyPressed(return_event));
163 dialog()->CheckAndResetStates(true, false, false); 171 dialog()->CheckAndResetStates(true, false, false);
172 #endif
164 173
165 // Check that return accelerators cancel dialogs if cancel is focused. 174 // Check that return accelerators cancel dialogs if cancel is focused, except
175 // on Mac where return should perform the default action.
166 cancel_button->RequestFocus(); 176 cancel_button->RequestFocus();
167 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView()); 177 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView());
168 SimulateKeyEvent(return_event); 178 SimulateKeyEvent(return_event);
179 #if defined(OS_MACOSX)
180 dialog()->CheckAndResetStates(false, true, false);
181 #else
169 dialog()->CheckAndResetStates(true, false, false); 182 dialog()->CheckAndResetStates(true, false, false);
183 #endif
170 184
171 // Check that escape can be overridden. 185 // Check that escape can be overridden.
172 dialog()->set_should_handle_escape(true); 186 dialog()->set_should_handle_escape(true);
173 SimulateKeyEvent(escape_event); 187 SimulateKeyEvent(escape_event);
174 dialog()->CheckAndResetStates(false, false, false); 188 dialog()->CheckAndResetStates(false, false, false);
175 } 189 }
176 190
177 TEST_F(DialogTest, RemoveDefaultButton) { 191 TEST_F(DialogTest, RemoveDefaultButton) {
178 // Removing buttons from the dialog here should not cause a crash on close. 192 // Removing buttons from the dialog here should not cause a crash on close.
179 delete dialog()->GetDialogClientView()->ok_button(); 193 delete dialog()->GetDialogClientView()->ok_button();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 dialog2->TearDown(); 267 dialog2->TearDown();
254 } 268 }
255 269
256 // Tests default focus is assigned correctly when showing a new dialog. 270 // Tests default focus is assigned correctly when showing a new dialog.
257 TEST_F(DialogTest, InitialFocus) { 271 TEST_F(DialogTest, InitialFocus) {
258 EXPECT_TRUE(dialog()->input()->HasFocus()); 272 EXPECT_TRUE(dialog()->input()->HasFocus());
259 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); 273 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
260 } 274 }
261 275
262 } // namespace views 276 } // namespace views
OLDNEW
« ui/views/style/platform_style_mac.mm ('K') | « ui/views/style/platform_style_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698