OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/shell/browser/shell_desktop_controller_aura.h" | 5 #include "extensions/shell/browser/shell_desktop_controller_aura.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "build/build_config.h" | |
13 #include "ui/aura/test/aura_test_base.h" | 12 #include "ui/aura/test/aura_test_base.h" |
13 #include "ui/base/ime/dummy_text_input_client.h" | |
14 #include "ui/base/ime/input_method.h" | |
15 #include "ui/base/ime/input_method_factory.h" | |
16 #include "ui/base/ime/input_method_minimal.h" | |
17 #include "ui/events/event.h" | |
18 #include "ui/events/event_dispatcher.h" | |
19 #include "ui/events/keycodes/keyboard_codes.h" | |
14 | 20 |
15 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
16 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
17 #include "chromeos/dbus/fake_power_manager_client.h" | 23 #include "chromeos/dbus/fake_power_manager_client.h" |
18 #endif | 24 #endif |
19 | 25 |
20 namespace extensions { | 26 namespace extensions { |
21 | 27 |
28 // TODO(michaelpg): Why do we use AuraTestBase when ShellDesktopControllerAura | |
29 // already creates a screen and root window host itself? | |
22 class ShellDesktopControllerAuraTest : public aura::test::AuraTestBase { | 30 class ShellDesktopControllerAuraTest : public aura::test::AuraTestBase { |
23 public: | 31 public: |
24 ShellDesktopControllerAuraTest() | 32 ShellDesktopControllerAuraTest() |
25 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
26 : power_manager_client_(NULL) | 34 : power_manager_client_(NULL) |
27 #endif | 35 #endif |
28 { | 36 { |
29 } | 37 } |
30 ~ShellDesktopControllerAuraTest() override {} | 38 ~ShellDesktopControllerAuraTest() override {} |
31 | 39 |
32 void SetUp() override { | 40 void SetUp() override { |
33 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
34 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | 42 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = |
35 chromeos::DBusThreadManager::GetSetterForTesting(); | 43 chromeos::DBusThreadManager::GetSetterForTesting(); |
36 power_manager_client_ = new chromeos::FakePowerManagerClient(); | 44 power_manager_client_ = new chromeos::FakePowerManagerClient(); |
37 dbus_setter->SetPowerManagerClient(base::WrapUnique(power_manager_client_)); | 45 dbus_setter->SetPowerManagerClient(base::WrapUnique(power_manager_client_)); |
38 #endif | 46 #endif |
39 aura::test::AuraTestBase::SetUp(); | 47 aura::test::AuraTestBase::SetUp(); |
48 | |
49 // The input method will be used for the next CreateInputMethod call, | |
50 // causing the host to take ownership. | |
51 ui::SetUpInputMethodForTesting(new ui::InputMethodMinimal(nullptr)); | |
52 | |
40 controller_.reset(new ShellDesktopControllerAura()); | 53 controller_.reset(new ShellDesktopControllerAura()); |
41 } | 54 } |
42 | 55 |
43 void TearDown() override { | 56 void TearDown() override { |
44 controller_.reset(); | 57 controller_.reset(); |
45 aura::test::AuraTestBase::TearDown(); | 58 aura::test::AuraTestBase::TearDown(); |
46 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
47 chromeos::DBusThreadManager::Shutdown(); | 60 chromeos::DBusThreadManager::Shutdown(); |
48 #endif | 61 #endif |
49 } | 62 } |
(...skipping 18 matching lines...) Expand all Loading... | |
68 base::TimeTicks()); | 81 base::TimeTicks()); |
69 EXPECT_EQ(0, power_manager_client_->num_request_shutdown_calls()); | 82 EXPECT_EQ(0, power_manager_client_->num_request_shutdown_calls()); |
70 | 83 |
71 // A button press should trigger a shutdown request. | 84 // A button press should trigger a shutdown request. |
72 power_manager_client_->SendPowerButtonEvent(true /* down */, | 85 power_manager_client_->SendPowerButtonEvent(true /* down */, |
73 base::TimeTicks()); | 86 base::TimeTicks()); |
74 EXPECT_EQ(1, power_manager_client_->num_request_shutdown_calls()); | 87 EXPECT_EQ(1, power_manager_client_->num_request_shutdown_calls()); |
75 } | 88 } |
76 #endif | 89 #endif |
77 | 90 |
91 // Tests that basic input events are handled and forwarded to the host. | |
92 // TODO(michaelpg): Test other types of input. | |
93 TEST_F(ShellDesktopControllerAuraTest, InputEvents) { | |
94 ui::InputMethod* input_method = controller_->host_->GetInputMethod(); | |
95 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.
| |
96 | |
97 // Set up a focused text input to receive the keypress event. | |
98 ui::DummyTextInputClient client(ui::TEXT_INPUT_TYPE_TEXT); | |
99 input_method->SetFocusedTextInputClient(&client); | |
100 EXPECT_EQ(0, client.insert_char_count()); | |
101 | |
102 // Dispatch a keypress on the window tree host to verify it is processed. | |
103 ui::KeyEvent key_press(base::char16(97), ui::VKEY_A, ui::EF_NONE); | |
104 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.
| |
105 controller_->host_->window(), &key_press)); | |
106 EXPECT_TRUE(key_press.handled()); | |
107 EXPECT_EQ(1, client.insert_char_count()); | |
108 | |
109 // Clean up. | |
110 input_method->DetachTextInputClient(&client); | |
111 } | |
112 | |
78 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |