Chromium Code Reviews| Index: ui/views/controls/combobox/combobox_unittest.cc |
| diff --git a/ui/views/controls/combobox/combobox_unittest.cc b/ui/views/controls/combobox/combobox_unittest.cc |
| index c81160362cdfbf239265b8451cc09ff75eee1faf..f3db6c06e4c7cbb52ec69fea0727bd09eaf15b8b 100644 |
| --- a/ui/views/controls/combobox/combobox_unittest.cc |
| +++ b/ui/views/controls/combobox/combobox_unittest.cc |
| @@ -8,6 +8,8 @@ |
| #include "base/basictypes.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "ui/base/ime/input_method.h" |
| +#include "ui/base/ime/input_method_factory.h" |
| #include "ui/base/ime/text_input_client.h" |
| #include "ui/base/models/combobox_model.h" |
| #include "ui/events/event.h" |
| @@ -17,7 +19,6 @@ |
| #include "ui/views/controls/combobox/combobox_listener.h" |
| #include "ui/views/controls/menu/menu_runner.h" |
| #include "ui/views/controls/menu/menu_runner_handler.h" |
| -#include "ui/views/ime/mock_input_method.h" |
| #include "ui/views/test/menu_runner_test_api.h" |
| #include "ui/views/test/views_test_base.h" |
| #include "ui/views/widget/widget.h" |
| @@ -201,6 +202,11 @@ class ComboboxTest : public ViewsTestBase { |
| public: |
| ComboboxTest() : widget_(NULL), combobox_(NULL) {} |
| + void SetUp() override { |
| + ui::SetUpInputMethodFactoryForTesting(); |
|
sky
2015/06/29 02:17:41
Should we move this clal to ViewsTestBase?
Shu Chen
2015/06/29 02:56:34
Done.
|
| + ViewsTestBase::SetUp(); |
| + } |
| + |
| void TearDown() override { |
| if (widget_) |
| widget_->Close(); |
| @@ -225,11 +231,6 @@ class ComboboxTest : public ViewsTestBase { |
| widget_->SetContentsView(container); |
| container->AddChildView(combobox_); |
| - widget_->ReplaceInputMethod(new MockInputMethod); |
| - |
| - // Assumes the Widget is always focused. |
| - widget_->GetInputMethod()->OnFocus(); |
| - |
| combobox_->RequestFocus(); |
| combobox_->SizeToPreferredSize(); |
| } |
| @@ -241,7 +242,10 @@ class ComboboxTest : public ViewsTestBase { |
| void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) { |
| ui::KeyEvent event(type, key_code, ui::EF_NONE); |
| - widget_->GetInputMethod()->DispatchKeyEvent(event); |
| + FocusManager* focus_manager = widget_->GetFocusManager(); |
| + widget_->OnKeyEvent(&event); |
| + if (!event.handled() && focus_manager) |
| + focus_manager->OnKeyEvent(event); |
| } |
| View* GetFocusedView() { |
| @@ -669,24 +673,27 @@ TEST_F(ComboboxTest, TypingPrefixNotifiesListener) { |
| TestComboboxListener listener; |
| combobox_->set_listener(&listener); |
| + ui::TextInputClient* input_client = |
| + widget_->GetInputMethod()->GetTextInputClient(); |
| // Type the first character of the second menu item ("JELLY"). |
| - combobox_->GetTextInputClient()->InsertChar('J', ui::EF_NONE); |
| + input_client->InsertChar('J', ui::EF_NONE); |
| EXPECT_EQ(1, listener.actions_performed()); |
| EXPECT_EQ(1, listener.perform_action_index()); |
| // Type the second character of "JELLY", item shouldn't change and |
| // OnPerformAction() shouldn't be re-called. |
| - combobox_->GetTextInputClient()->InsertChar('E', ui::EF_NONE); |
| + input_client->InsertChar('E', ui::EF_NONE); |
| EXPECT_EQ(1, listener.actions_performed()); |
| EXPECT_EQ(1, listener.perform_action_index()); |
| // Clears the typed text. |
| combobox_->OnBlur(); |
| + combobox_->RequestFocus(); |
| // Type the first character of "PEANUT BUTTER", which should change the |
| // selected index and perform an action. |
| - combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE); |
| + input_client->InsertChar('P', ui::EF_NONE); |
| EXPECT_EQ(2, listener.actions_performed()); |
| EXPECT_EQ(2, listener.perform_action_index()); |
| } |