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/base/test/scoped_fake_full_keyboard_access.h" | |
|
tapted
2017/01/12 15:30:50
This should be between #if defined(OS_MACOSX)
Patti Lor
2017/01/13 04:19:02
Done.
| |
| 10 #include "ui/events/event_processor.h" | 11 #include "ui/events/event_processor.h" |
| 11 #include "ui/views/bubble/bubble_border.h" | 12 #include "ui/views/bubble/bubble_border.h" |
| 12 #include "ui/views/bubble/bubble_frame_view.h" | 13 #include "ui/views/bubble/bubble_frame_view.h" |
| 13 #include "ui/views/controls/button/checkbox.h" | 14 #include "ui/views/controls/button/checkbox.h" |
| 14 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/controls/textfield/textfield.h" | 16 #include "ui/views/controls/textfield/textfield.h" |
| 16 #include "ui/views/test/views_test_base.h" | 17 #include "ui/views/test/views_test_base.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/window/dialog_client_view.h" | 19 #include "ui/views/window/dialog_client_view.h" |
| 19 #include "ui/views/window/dialog_delegate.h" | 20 #include "ui/views/window/dialog_delegate.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 265 |
| 265 dialog2->TearDown(); | 266 dialog2->TearDown(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 // Tests default focus is assigned correctly when showing a new dialog. | 269 // Tests default focus is assigned correctly when showing a new dialog. |
| 269 TEST_F(DialogTest, InitialFocus) { | 270 TEST_F(DialogTest, InitialFocus) { |
| 270 EXPECT_TRUE(dialog()->input()->HasFocus()); | 271 EXPECT_TRUE(dialog()->input()->HasFocus()); |
| 271 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); | 272 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); |
| 272 } | 273 } |
| 273 | 274 |
| 275 // If the initially focused View provided is unfocusable, check the next | |
| 276 // available focusable View is focused. | |
| 277 TEST_F(DialogTest, UnfocusableInitialFocus) { | |
| 278 #if defined(OS_MACOSX) | |
| 279 // On Mac, make all buttons unfocusable by turning off full keyboard access. | |
|
tapted
2017/01/12 15:30:51
add "This is the more common configuration, and if
Patti Lor
2017/01/13 04:19:02
Done.
| |
| 280 ui::test::ScopedFakeFullKeyboardAccess::GetInstance() | |
| 281 ->set_full_keyboard_access_state(false); | |
| 282 #endif | |
| 283 | |
| 284 DialogDelegateView* dialog = new DialogDelegateView(); | |
| 285 Textfield* textfield = new Textfield(); | |
| 286 dialog->AddChildView(textfield); | |
| 287 Widget* dialog_widget = | |
| 288 DialogDelegate::CreateDialogWidget(dialog, GetContext(), nullptr); | |
| 289 | |
| 290 #if !defined(OS_MACOSX) | |
| 291 // For non-Mac, turn off focusability on all the dialog's buttons manually. | |
|
tapted
2017/01/12 15:30:51
add "This achieves the same effect as disabling fu
Patti Lor
2017/01/13 04:19:02
Done.
| |
| 292 DialogClientView* dcv = dialog->GetDialogClientView(); | |
| 293 dcv->ok_button()->SetFocusBehavior(View::FocusBehavior::NEVER); | |
| 294 dcv->cancel_button()->SetFocusBehavior(View::FocusBehavior::NEVER); | |
| 295 #endif | |
| 296 | |
| 297 // On showing the dialog, the initially focused View will be the OK button. | |
| 298 // Since it is no longer focusable, focus should advance to the next focusable | |
| 299 // View, which is |textfield|. | |
| 300 dialog_widget->Show(); | |
| 301 EXPECT_TRUE(textfield->HasFocus()); | |
| 302 EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView()); | |
| 303 dialog_widget->Close(); | |
| 304 } | |
| 305 | |
| 274 } // namespace views | 306 } // namespace views |
| OLD | NEW |