| 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" |
| 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_nswindow_focus.h" | |
| 23 #endif | |
| 24 | |
| 25 namespace views { | 21 namespace views { |
| 26 | 22 |
| 27 namespace { | 23 namespace { |
| 28 | 24 |
| 29 class TestDialog : public DialogDelegateView, public ButtonListener { | 25 class TestDialog : public DialogDelegateView, public ButtonListener { |
| 30 public: | 26 public: |
| 31 TestDialog() | 27 TestDialog() |
| 32 : input_(new views::Textfield()), | 28 : input_(new views::Textfield()), |
| 33 canceled_(false), | 29 canceled_(false), |
| 34 accepted_(false), | 30 accepted_(false), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DISALLOW_COPY_AND_ASSIGN(TestDialog); | 92 DISALLOW_COPY_AND_ASSIGN(TestDialog); |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 class DialogTest : public ViewsTestBase { | 95 class DialogTest : public ViewsTestBase { |
| 100 public: | 96 public: |
| 101 DialogTest() : dialog_(NULL) {} | 97 DialogTest() : dialog_(NULL) {} |
| 102 ~DialogTest() override {} | 98 ~DialogTest() override {} |
| 103 | 99 |
| 104 void SetUp() override { | 100 void SetUp() override { |
| 105 ViewsTestBase::SetUp(); | 101 ViewsTestBase::SetUp(); |
| 102 EnableMacFakeWindowActivation(); |
| 106 dialog_ = new TestDialog(); | 103 dialog_ = new TestDialog(); |
| 107 DialogDelegate::CreateDialogWidget(dialog_, GetContext(), NULL)->Show(); | 104 DialogDelegate::CreateDialogWidget(dialog_, GetContext(), NULL)->Show(); |
| 108 } | 105 } |
| 109 | 106 |
| 110 void TearDown() override { | 107 void TearDown() override { |
| 111 dialog_->TearDown(); | 108 dialog_->TearDown(); |
| 112 ViewsTestBase::TearDown(); | 109 ViewsTestBase::TearDown(); |
| 113 } | 110 } |
| 114 | 111 |
| 115 void SimulateKeyEvent(const ui::KeyEvent& event) { | 112 void SimulateKeyEvent(const ui::KeyEvent& event) { |
| 116 ui::KeyEvent event_copy = event; | 113 ui::KeyEvent event_copy = event; |
| 117 if (dialog()->GetFocusManager()->OnKeyEvent(event_copy)) | 114 if (dialog()->GetFocusManager()->OnKeyEvent(event_copy)) |
| 118 dialog()->GetWidget()->OnKeyEvent(&event_copy); | 115 dialog()->GetWidget()->OnKeyEvent(&event_copy); |
| 119 } | 116 } |
| 120 | 117 |
| 121 TestDialog* dialog() const { return dialog_; } | 118 TestDialog* dialog() const { return dialog_; } |
| 122 | 119 |
| 123 private: | 120 private: |
| 124 TestDialog* dialog_; | 121 TestDialog* dialog_; |
| 125 | 122 |
| 126 #if defined(OS_MACOSX) | |
| 127 // Causes Widget::Show() to transfer focus synchronously and become immune to | |
| 128 // losing focus to processes running in parallel. | |
| 129 ui::test::ScopedFakeNSWindowFocus fake_focus; | |
| 130 #endif | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(DialogTest); | 123 DISALLOW_COPY_AND_ASSIGN(DialogTest); |
| 133 }; | 124 }; |
| 134 | 125 |
| 135 } // namespace | 126 } // namespace |
| 136 | 127 |
| 137 TEST_F(DialogTest, AcceptAndCancel) { | 128 TEST_F(DialogTest, AcceptAndCancel) { |
| 138 DialogClientView* client_view = dialog()->GetDialogClientView(); | 129 DialogClientView* client_view = dialog()->GetDialogClientView(); |
| 139 LabelButton* ok_button = client_view->ok_button(); | 130 LabelButton* ok_button = client_view->ok_button(); |
| 140 LabelButton* cancel_button = client_view->cancel_button(); | 131 LabelButton* cancel_button = client_view->cancel_button(); |
| 141 | 132 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 dialog2->TearDown(); | 232 dialog2->TearDown(); |
| 242 } | 233 } |
| 243 | 234 |
| 244 // Tests default focus is assigned correctly when showing a new dialog. | 235 // Tests default focus is assigned correctly when showing a new dialog. |
| 245 TEST_F(DialogTest, InitialFocus) { | 236 TEST_F(DialogTest, InitialFocus) { |
| 246 EXPECT_TRUE(dialog()->input()->HasFocus()); | 237 EXPECT_TRUE(dialog()->input()->HasFocus()); |
| 247 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); | 238 EXPECT_EQ(dialog()->input(), dialog()->GetFocusManager()->GetFocusedView()); |
| 248 } | 239 } |
| 249 | 240 |
| 250 } // namespace views | 241 } // namespace views |
| OLD | NEW |