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

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

Issue 2604303002: (Mac)Views: Widgets focus first View in traversal order if initial focus fails. (Closed)
Patch Set: Review comments. 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
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "ui/views/bubble/bubble_border.h" 11 #include "ui/views/bubble/bubble_border.h"
12 #include "ui/views/bubble/bubble_frame_view.h" 12 #include "ui/views/bubble/bubble_frame_view.h"
13 #include "ui/views/controls/button/checkbox.h" 13 #include "ui/views/controls/button/checkbox.h"
14 #include "ui/views/controls/button/label_button.h" 14 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/textfield/textfield.h" 15 #include "ui/views/controls/textfield/textfield.h"
16 #include "ui/views/test/views_test_base.h" 16 #include "ui/views/test/views_test_base.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 #include "ui/views/window/dialog_client_view.h" 18 #include "ui/views/window/dialog_client_view.h"
19 #include "ui/views/window/dialog_delegate.h" 19 #include "ui/views/window/dialog_delegate.h"
20 20
21 #if defined(OS_MACOSX)
22 #include "ui/base/test/scoped_fake_full_keyboard_access.h"
23 #endif
24
21 namespace views { 25 namespace views {
22 26
23 namespace { 27 namespace {
24 28
25 class TestDialog : public DialogDelegateView, public ButtonListener { 29 class TestDialog : public DialogDelegateView, public ButtonListener {
26 public: 30 public:
27 TestDialog() 31 TestDialog()
28 : input_(new views::Textfield()), 32 : input_(new views::Textfield()),
29 canceled_(false), 33 canceled_(false),
30 accepted_(false), 34 accepted_(false),
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 268
265 dialog2->TearDown(); 269 dialog2->TearDown();
266 } 270 }
267 271
268 // Tests default focus is assigned correctly when showing a new dialog. 272 // Tests default focus is assigned correctly when showing a new dialog.
269 TEST_F(DialogTest, InitialFocus) { 273 TEST_F(DialogTest, InitialFocus) {
270 EXPECT_TRUE(dialog()->input()->HasFocus()); 274 EXPECT_TRUE(dialog()->input()->HasFocus());
271 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); 275 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView());
272 } 276 }
273 277
278 // If the initially focused View provided is unfocusable, check the next
279 // available focusable View is focused.
280 TEST_F(DialogTest, UnfocusableInitialFocus) {
281 #if defined(OS_MACOSX)
282 // On Mac, make all buttons unfocusable by turning off full keyboard access.
283 // This is the more common configuration, and if a dialog has a focusable
284 // textfield, tree or table, that should obtain focus instead.
285 ui::test::ScopedFakeFullKeyboardAccess::GetInstance()
286 ->set_full_keyboard_access_state(false);
287 #endif
288
289 DialogDelegateView* dialog = new DialogDelegateView();
290 Textfield* textfield = new Textfield();
291 dialog->AddChildView(textfield);
292 Widget* dialog_widget =
293 DialogDelegate::CreateDialogWidget(dialog, GetContext(), nullptr);
294
295 #if !defined(OS_MACOSX)
296 // For non-Mac, turn off focusability on all the dialog's buttons manually.
297 // This achieves the same effect as disabling full keyboard access.
298 DialogClientView* dcv = dialog->GetDialogClientView();
299 dcv->ok_button()->SetFocusBehavior(View::FocusBehavior::NEVER);
300 dcv->cancel_button()->SetFocusBehavior(View::FocusBehavior::NEVER);
301 #endif
302
303 // On showing the dialog, the initially focused View will be the OK button.
304 // Since it is no longer focusable, focus should advance to the next focusable
305 // View, which is |textfield|.
306 dialog_widget->Show();
307 EXPECT_TRUE(textfield->HasFocus());
308 EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView());
309 dialog_widget->Close();
310 }
311
274 } // namespace views 312 } // namespace views
OLDNEW
« 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