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 "ash/virtual_keyboard_controller.h" | 5 #include "ash/virtual_keyboard_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/system/virtual_keyboard/virtual_keyboard_observer.h" | 12 #include "ash/system/virtual_keyboard/virtual_keyboard_observer.h" |
13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
14 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 14 #include "ash/wm/tablet_mode/scoped_disable_internal_mouse_and_keyboard.h" |
15 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | 15 #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "ui/events/devices/device_data_manager.h" | 17 #include "ui/events/devices/device_data_manager.h" |
18 #include "ui/events/devices/device_hotplug_event_observer.h" | 18 #include "ui/events/devices/device_hotplug_event_observer.h" |
19 #include "ui/events/devices/input_device.h" | 19 #include "ui/events/devices/input_device.h" |
20 #include "ui/events/devices/touchscreen_device.h" | 20 #include "ui/events/devices/touchscreen_device.h" |
21 #include "ui/keyboard/keyboard_export.h" | 21 #include "ui/keyboard/keyboard_export.h" |
22 #include "ui/keyboard/keyboard_switches.h" | 22 #include "ui/keyboard/keyboard_switches.h" |
23 #include "ui/keyboard/keyboard_util.h" | 23 #include "ui/keyboard/keyboard_util.h" |
24 | 24 |
25 namespace ash { | 25 namespace ash { |
(...skipping 13 matching lines...) Expand all Loading... |
39 | 39 |
40 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) { | 40 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) { |
41 ui::DeviceHotplugEventObserver* manager = | 41 ui::DeviceHotplugEventObserver* manager = |
42 ui::DeviceDataManager::GetInstance(); | 42 ui::DeviceDataManager::GetInstance(); |
43 manager->OnKeyboardDevicesUpdated(keyboard_devices); | 43 manager->OnKeyboardDevicesUpdated(keyboard_devices); |
44 } | 44 } |
45 | 45 |
46 // Sets the event blocker on the maximized window controller. | 46 // Sets the event blocker on the maximized window controller. |
47 void SetEventBlocker( | 47 void SetEventBlocker( |
48 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { | 48 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { |
49 Shell::Get()->maximize_mode_controller()->event_blocker_ = | 49 Shell::Get()->tablet_mode_controller()->event_blocker_ = std::move(blocker); |
50 std::move(blocker); | |
51 } | 50 } |
52 | 51 |
53 void SetUp() override { | 52 void SetUp() override { |
54 AshTestBase::SetUp(); | 53 AshTestBase::SetUp(); |
55 UpdateKeyboardDevices(std::vector<ui::InputDevice>()); | 54 UpdateKeyboardDevices(std::vector<ui::InputDevice>()); |
56 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); | 55 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); |
57 } | 56 } |
58 | 57 |
59 private: | 58 private: |
60 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); | 59 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); |
(...skipping 13 matching lines...) Expand all Loading... |
74 manager->OnKeyboardDevicesUpdated(keyboard_devices); | 73 manager->OnKeyboardDevicesUpdated(keyboard_devices); |
75 } | 74 } |
76 | 75 |
77 private: | 76 private: |
78 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); | 77 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); |
79 }; | 78 }; |
80 | 79 |
81 // Tests that reenabling keyboard devices while shutting down does not | 80 // Tests that reenabling keyboard devices while shutting down does not |
82 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. | 81 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. |
83 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { | 82 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { |
84 // Toggle maximized mode on. | 83 // Toggle tablet mode on. |
85 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 84 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); |
86 true); | |
87 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker( | 85 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker( |
88 new MockEventBlocker); | 86 new MockEventBlocker); |
89 SetEventBlocker(std::move(blocker)); | 87 SetEventBlocker(std::move(blocker)); |
90 } | 88 } |
91 | 89 |
92 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, | 90 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, |
93 public VirtualKeyboardObserver { | 91 public VirtualKeyboardObserver { |
94 public: | 92 public: |
95 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} | 93 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} |
96 ~VirtualKeyboardControllerAutoTest() override {} | 94 ~VirtualKeyboardControllerAutoTest() override {} |
(...skipping 30 matching lines...) Expand all Loading... |
127 // Whether the observer method was called. | 125 // Whether the observer method was called. |
128 bool notified_; | 126 bool notified_; |
129 | 127 |
130 // Whether the keeyboard is suppressed. | 128 // Whether the keeyboard is suppressed. |
131 bool suppressed_; | 129 bool suppressed_; |
132 | 130 |
133 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest); | 131 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest); |
134 }; | 132 }; |
135 | 133 |
136 // Tests that the onscreen keyboard is disabled if an internal keyboard is | 134 // Tests that the onscreen keyboard is disabled if an internal keyboard is |
137 // present and maximized mode is disabled. | 135 // present and tablet mode is disabled. |
138 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) { | 136 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) { |
139 std::vector<ui::TouchscreenDevice> screens; | 137 std::vector<ui::TouchscreenDevice> screens; |
140 screens.push_back( | 138 screens.push_back( |
141 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | 139 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
142 "Touchscreen", gfx::Size(1024, 768), 0)); | 140 "Touchscreen", gfx::Size(1024, 768), 0)); |
143 UpdateTouchscreenDevices(screens); | 141 UpdateTouchscreenDevices(screens); |
144 std::vector<ui::InputDevice> keyboard_devices; | 142 std::vector<ui::InputDevice> keyboard_devices; |
145 keyboard_devices.push_back(ui::InputDevice( | 143 keyboard_devices.push_back(ui::InputDevice( |
146 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); | 144 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); |
147 UpdateKeyboardDevices(keyboard_devices); | 145 UpdateKeyboardDevices(keyboard_devices); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 keyboards.push_back(ui::InputDevice( | 205 keyboards.push_back(ui::InputDevice( |
208 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); | 206 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); |
209 keyboards.push_back(ui::InputDevice( | 207 keyboards.push_back(ui::InputDevice( |
210 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); | 208 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); |
211 keyboards.push_back(ui::InputDevice( | 209 keyboards.push_back(ui::InputDevice( |
212 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); | 210 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); |
213 UpdateKeyboardDevices(keyboards); | 211 UpdateKeyboardDevices(keyboards); |
214 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 212 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
215 } | 213 } |
216 | 214 |
217 // Tests maximized mode interaction without disabling the internal keyboard. | 215 // Tests tablet mode interaction without disabling the internal keyboard. |
218 TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringMaximizeMode) { | 216 TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringTabletMode) { |
219 std::vector<ui::TouchscreenDevice> screens; | 217 std::vector<ui::TouchscreenDevice> screens; |
220 screens.push_back( | 218 screens.push_back( |
221 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | 219 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
222 "Touchscreen", gfx::Size(1024, 768), 0)); | 220 "Touchscreen", gfx::Size(1024, 768), 0)); |
223 UpdateTouchscreenDevices(screens); | 221 UpdateTouchscreenDevices(screens); |
224 std::vector<ui::InputDevice> keyboard_devices; | 222 std::vector<ui::InputDevice> keyboard_devices; |
225 keyboard_devices.push_back(ui::InputDevice( | 223 keyboard_devices.push_back(ui::InputDevice( |
226 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 224 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
227 UpdateKeyboardDevices(keyboard_devices); | 225 UpdateKeyboardDevices(keyboard_devices); |
228 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 226 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
229 // Toggle maximized mode on. | 227 // Toggle tablet mode on. |
230 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 228 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); |
231 true); | |
232 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 229 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
233 // Toggle maximized mode off. | 230 // Toggle tablet mode off. |
234 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 231 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); |
235 false); | |
236 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 232 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
237 } | 233 } |
238 | 234 |
239 // Tests that keyboard gets suppressed in maximized mode. | 235 // Tests that keyboard gets suppressed in tablet mode. |
240 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { | 236 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { |
241 std::vector<ui::TouchscreenDevice> screens; | 237 std::vector<ui::TouchscreenDevice> screens; |
242 screens.push_back( | 238 screens.push_back( |
243 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | 239 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
244 "Touchscreen", gfx::Size(1024, 768), 0)); | 240 "Touchscreen", gfx::Size(1024, 768), 0)); |
245 UpdateTouchscreenDevices(screens); | 241 UpdateTouchscreenDevices(screens); |
246 std::vector<ui::InputDevice> keyboard_devices; | 242 std::vector<ui::InputDevice> keyboard_devices; |
247 keyboard_devices.push_back(ui::InputDevice( | 243 keyboard_devices.push_back(ui::InputDevice( |
248 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 244 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
249 keyboard_devices.push_back(ui::InputDevice( | 245 keyboard_devices.push_back(ui::InputDevice( |
250 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard")); | 246 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard")); |
251 UpdateKeyboardDevices(keyboard_devices); | 247 UpdateKeyboardDevices(keyboard_devices); |
252 // Toggle maximized mode on. | 248 // Toggle tablet mode on. |
253 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 249 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); |
254 true); | |
255 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 250 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
256 ASSERT_TRUE(notified()); | 251 ASSERT_TRUE(notified()); |
257 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 252 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
258 // Toggle show keyboard. Keyboard should be visible. | 253 // Toggle show keyboard. Keyboard should be visible. |
259 ResetObserver(); | 254 ResetObserver(); |
260 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); | 255 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); |
261 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 256 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
262 ASSERT_TRUE(notified()); | 257 ASSERT_TRUE(notified()); |
263 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 258 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
264 // Toggle show keyboard. Keyboard should be hidden. | 259 // Toggle show keyboard. Keyboard should be hidden. |
265 ResetObserver(); | 260 ResetObserver(); |
266 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); | 261 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); |
267 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 262 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
268 ASSERT_TRUE(notified()); | 263 ASSERT_TRUE(notified()); |
269 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 264 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
270 // Remove external keyboard. Should be notified that the keyboard is not | 265 // Remove external keyboard. Should be notified that the keyboard is not |
271 // suppressed. | 266 // suppressed. |
272 ResetObserver(); | 267 ResetObserver(); |
273 keyboard_devices.pop_back(); | 268 keyboard_devices.pop_back(); |
274 UpdateKeyboardDevices(keyboard_devices); | 269 UpdateKeyboardDevices(keyboard_devices); |
275 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 270 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
276 ASSERT_TRUE(notified()); | 271 ASSERT_TRUE(notified()); |
277 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); | 272 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); |
278 // Toggle maximized mode oFF. | 273 // Toggle tablet mode oFF. |
279 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 274 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); |
280 false); | |
281 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 275 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
282 } | 276 } |
283 | 277 |
284 class VirtualKeyboardControllerAlwaysEnabledTest | 278 class VirtualKeyboardControllerAlwaysEnabledTest |
285 : public VirtualKeyboardControllerAutoTest { | 279 : public VirtualKeyboardControllerAutoTest { |
286 public: | 280 public: |
287 VirtualKeyboardControllerAlwaysEnabledTest() | 281 VirtualKeyboardControllerAlwaysEnabledTest() |
288 : VirtualKeyboardControllerAutoTest() {} | 282 : VirtualKeyboardControllerAutoTest() {} |
289 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} | 283 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} |
290 | 284 |
(...skipping 17 matching lines...) Expand all Loading... |
308 UpdateTouchscreenDevices(screens); | 302 UpdateTouchscreenDevices(screens); |
309 std::vector<ui::InputDevice> keyboard_devices; | 303 std::vector<ui::InputDevice> keyboard_devices; |
310 keyboard_devices.push_back(ui::InputDevice( | 304 keyboard_devices.push_back(ui::InputDevice( |
311 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); | 305 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); |
312 UpdateKeyboardDevices(keyboard_devices); | 306 UpdateKeyboardDevices(keyboard_devices); |
313 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 307 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
314 } | 308 } |
315 | 309 |
316 } // namespace test | 310 } // namespace test |
317 } // namespace ash | 311 } // namespace ash |
OLD | NEW |