Chromium Code Reviews| Index: extensions/shell/browser/shell_desktop_controller_aura_unittest.cc |
| diff --git a/extensions/shell/browser/shell_desktop_controller_aura_unittest.cc b/extensions/shell/browser/shell_desktop_controller_aura_unittest.cc |
| index d83b97757cbd7ec096bb23b658971bfcdc68f9a7..c2257b7314e539b1d899da2212d610bcd202a186 100644 |
| --- a/extensions/shell/browser/shell_desktop_controller_aura_unittest.cc |
| +++ b/extensions/shell/browser/shell_desktop_controller_aura_unittest.cc |
| @@ -9,8 +9,14 @@ |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/time/time.h" |
| -#include "build/build_config.h" |
| #include "ui/aura/test/aura_test_base.h" |
| +#include "ui/base/ime/dummy_text_input_client.h" |
| +#include "ui/base/ime/input_method.h" |
| +#include "ui/base/ime/input_method_factory.h" |
| +#include "ui/base/ime/input_method_minimal.h" |
| +#include "ui/events/event.h" |
| +#include "ui/events/event_dispatcher.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| #if defined(OS_CHROMEOS) |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| @@ -19,6 +25,8 @@ |
| namespace extensions { |
| +// TODO(michaelpg): Why do we use AuraTestBase when ShellDesktopControllerAura |
| +// already creates a screen and root window host itself? |
| class ShellDesktopControllerAuraTest : public aura::test::AuraTestBase { |
| public: |
| ShellDesktopControllerAuraTest() |
| @@ -37,6 +45,11 @@ class ShellDesktopControllerAuraTest : public aura::test::AuraTestBase { |
| dbus_setter->SetPowerManagerClient(base::WrapUnique(power_manager_client_)); |
| #endif |
| aura::test::AuraTestBase::SetUp(); |
| + |
| + // The input method will be used for the next CreateInputMethod call, |
| + // causing the host to take ownership. |
| + ui::SetUpInputMethodForTesting(new ui::InputMethodMinimal(nullptr)); |
| + |
| controller_.reset(new ShellDesktopControllerAura()); |
| } |
| @@ -75,4 +88,26 @@ TEST_F(ShellDesktopControllerAuraTest, PowerButton) { |
| } |
| #endif |
| +// Tests that basic input events are handled and forwarded to the host. |
| +// TODO(michaelpg): Test other types of input. |
| +TEST_F(ShellDesktopControllerAuraTest, InputEvents) { |
| + ui::InputMethod* input_method = controller_->host_->GetInputMethod(); |
| + EXPECT_TRUE(input_method); |
|
James Cook
2016/12/17 18:24:41
ASSERT_TRUE since line 99 will crash if input_meth
michaelpg
2016/12/18 01:46:10
Done.
|
| + |
| + // Set up a focused text input to receive the keypress event. |
| + ui::DummyTextInputClient client(ui::TEXT_INPUT_TYPE_TEXT); |
| + input_method->SetFocusedTextInputClient(&client); |
| + EXPECT_EQ(0, client.insert_char_count()); |
| + |
| + // Dispatch a keypress on the window tree host to verify it is processed. |
| + ui::KeyEvent key_press(base::char16(97), ui::VKEY_A, ui::EF_NONE); |
| + ignore_result(controller_->host_->dispatcher()->DispatchEvent( |
|
James Cook
2016/12/17 18:24:41
Do you know what this will return? If so, EXPECT i
michaelpg
2016/12/18 01:46:10
Done.
|
| + controller_->host_->window(), &key_press)); |
| + EXPECT_TRUE(key_press.handled()); |
| + EXPECT_EQ(1, client.insert_char_count()); |
| + |
| + // Clean up. |
| + input_method->DetachTextInputClient(&client); |
| +} |
| + |
| } // namespace extensions |