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

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: -- 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 private: 135 private:
136 TestDialog* dialog_; 136 TestDialog* dialog_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(DialogTest); 138 DISALLOW_COPY_AND_ASSIGN(DialogTest);
139 }; 139 };
140 140
141 } // namespace 141 } // namespace
142 142
143 TEST_F(DialogTest, AcceptAndCancel) { 143 TEST_F(DialogTest, AcceptAndCancel) {
144 DialogClientView* client_view = dialog()->GetDialogClientView(); 144 DialogClientView* client_view = dialog()->GetDialogClientView();
145 LabelButton* ok_button = client_view->ok_button();
146 LabelButton* cancel_button = client_view->cancel_button();
147 145
148 // Check that return/escape accelerators accept/close dialogs. 146 // Check that return/escape accelerators accept/close dialogs.
149 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); 147 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
150 const ui::KeyEvent return_event( 148 const ui::KeyEvent return_event(
151 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); 149 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE);
152 SimulateKeyEvent(return_event); 150 SimulateKeyEvent(return_event);
153 dialog()->CheckAndResetStates(false, true, false); 151 dialog()->CheckAndResetStates(false, true, false);
154 const ui::KeyEvent escape_event( 152 const ui::KeyEvent escape_event(
155 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); 153 ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
156 SimulateKeyEvent(escape_event); 154 SimulateKeyEvent(escape_event);
157 dialog()->CheckAndResetStates(false, false, true); 155 dialog()->CheckAndResetStates(false, false, true);
158 156
159 // Check ok and cancel button behavior on a directed return key events. 157 // Check that return accelerators cancel dialogs if cancel is focused, except
160 ok_button->OnKeyPressed(return_event); 158 // on Mac where return should perform the default action.
161 dialog()->CheckAndResetStates(false, true, false); 159 LabelButton* cancel_button = client_view->cancel_button();
tapted 2017/01/04 04:54:31 can we keep the old tests as well? (on non-mac at
karandeepb 2017/01/04 06:14:45 Done. I didn't think these tests were appropriate
162 cancel_button->OnKeyPressed(return_event);
163 dialog()->CheckAndResetStates(true, false, false);
164
165 // Check that return accelerators cancel dialogs if cancel is focused.
166 cancel_button->RequestFocus(); 160 cancel_button->RequestFocus();
167 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView()); 161 EXPECT_EQ(cancel_button, dialog()->GetFocusManager()->GetFocusedView());
168 SimulateKeyEvent(return_event); 162 SimulateKeyEvent(return_event);
163 #if defined(OS_MACOSX)
164 dialog()->CheckAndResetStates(false, true, false);
165 #else
169 dialog()->CheckAndResetStates(true, false, false); 166 dialog()->CheckAndResetStates(true, false, false);
167 #endif
170 168
171 // Check that escape can be overridden. 169 // Check that escape can be overridden.
172 dialog()->set_should_handle_escape(true); 170 dialog()->set_should_handle_escape(true);
173 SimulateKeyEvent(escape_event); 171 SimulateKeyEvent(escape_event);
174 dialog()->CheckAndResetStates(false, false, false); 172 dialog()->CheckAndResetStates(false, false, false);
175 } 173 }
176 174
177 TEST_F(DialogTest, RemoveDefaultButton) { 175 TEST_F(DialogTest, RemoveDefaultButton) {
178 // Removing buttons from the dialog here should not cause a crash on close. 176 // Removing buttons from the dialog here should not cause a crash on close.
179 delete dialog()->GetDialogClientView()->ok_button(); 177 delete dialog()->GetDialogClientView()->ok_button();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 dialog2->TearDown(); 251 dialog2->TearDown();
254 } 252 }
255 253
256 // Tests default focus is assigned correctly when showing a new dialog. 254 // Tests default focus is assigned correctly when showing a new dialog.
257 TEST_F(DialogTest, InitialFocus) { 255 TEST_F(DialogTest, InitialFocus) {
258 EXPECT_TRUE(dialog()->input()->HasFocus()); 256 EXPECT_TRUE(dialog()->input()->HasFocus());
259 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); 257 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
260 } 258 }
261 259
262 } // namespace views 260 } // namespace views
OLDNEW
« ui/views/style/platform_style.h ('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