| 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/common/system/chromeos/virtual_keyboard/virtual_keyboard_observer.
h" | 10 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_observer.
h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) { | 41 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) { |
| 42 ui::DeviceHotplugEventObserver* manager = | 42 ui::DeviceHotplugEventObserver* manager = |
| 43 ui::DeviceDataManager::GetInstance(); | 43 ui::DeviceDataManager::GetInstance(); |
| 44 manager->OnKeyboardDevicesUpdated(keyboard_devices); | 44 manager->OnKeyboardDevicesUpdated(keyboard_devices); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Sets the event blocker on the maximized window controller. | 47 // Sets the event blocker on the maximized window controller. |
| 48 void SetEventBlocker( | 48 void SetEventBlocker( |
| 49 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { | 49 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { |
| 50 WmShell::Get()->maximize_mode_controller()->event_blocker_ = | 50 Shell::Get()->maximize_mode_controller()->event_blocker_ = |
| 51 std::move(blocker); | 51 std::move(blocker); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SetUp() override { | 54 void SetUp() override { |
| 55 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 55 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 56 keyboard::switches::kDisableSmartVirtualKeyboard); | 56 keyboard::switches::kDisableSmartVirtualKeyboard); |
| 57 AshTestBase::SetUp(); | 57 AshTestBase::SetUp(); |
| 58 UpdateKeyboardDevices(std::vector<ui::InputDevice>()); | 58 UpdateKeyboardDevices(std::vector<ui::InputDevice>()); |
| 59 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); | 59 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); | 63 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { | 66 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { |
| 67 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 67 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 68 // Toggle maximized mode on. | 68 // Toggle maximized mode on. |
| 69 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 69 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 70 true); | 70 true); |
| 71 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | 71 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
| 72 // Toggle maximized mode off. | 72 // Toggle maximized mode off. |
| 73 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 73 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 74 false); | 74 false); |
| 75 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 75 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Mock event blocker that enables the internal keyboard when it's destructor | 78 // Mock event blocker that enables the internal keyboard when it's destructor |
| 79 // is called. | 79 // is called. |
| 80 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard { | 80 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard { |
| 81 public: | 81 public: |
| 82 MockEventBlocker() {} | 82 MockEventBlocker() {} |
| 83 ~MockEventBlocker() override { | 83 ~MockEventBlocker() override { |
| 84 std::vector<ui::InputDevice> keyboard_devices; | 84 std::vector<ui::InputDevice> keyboard_devices; |
| 85 keyboard_devices.push_back(ui::InputDevice( | 85 keyboard_devices.push_back(ui::InputDevice( |
| 86 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); | 86 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); |
| 87 ui::DeviceHotplugEventObserver* manager = | 87 ui::DeviceHotplugEventObserver* manager = |
| 88 ui::DeviceDataManager::GetInstance(); | 88 ui::DeviceDataManager::GetInstance(); |
| 89 manager->OnKeyboardDevicesUpdated(keyboard_devices); | 89 manager->OnKeyboardDevicesUpdated(keyboard_devices); |
| 90 } | 90 } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); | 93 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Tests that reenabling keyboard devices while shutting down does not | 96 // Tests that reenabling keyboard devices while shutting down does not |
| 97 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. | 97 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. |
| 98 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { | 98 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { |
| 99 // Toggle maximized mode on. | 99 // Toggle maximized mode on. |
| 100 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 100 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 101 true); | 101 true); |
| 102 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker( | 102 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker( |
| 103 new MockEventBlocker); | 103 new MockEventBlocker); |
| 104 SetEventBlocker(std::move(blocker)); | 104 SetEventBlocker(std::move(blocker)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, | 107 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, |
| 108 public VirtualKeyboardObserver { | 108 public VirtualKeyboardObserver { |
| 109 public: | 109 public: |
| 110 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} | 110 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 screens.push_back( | 239 screens.push_back( |
| 240 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | 240 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
| 241 "Touchscreen", gfx::Size(1024, 768), 0)); | 241 "Touchscreen", gfx::Size(1024, 768), 0)); |
| 242 UpdateTouchscreenDevices(screens); | 242 UpdateTouchscreenDevices(screens); |
| 243 std::vector<ui::InputDevice> keyboard_devices; | 243 std::vector<ui::InputDevice> keyboard_devices; |
| 244 keyboard_devices.push_back(ui::InputDevice( | 244 keyboard_devices.push_back(ui::InputDevice( |
| 245 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 245 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 246 UpdateKeyboardDevices(keyboard_devices); | 246 UpdateKeyboardDevices(keyboard_devices); |
| 247 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 247 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 248 // Toggle maximized mode on. | 248 // Toggle maximized mode on. |
| 249 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 249 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 250 true); | 250 true); |
| 251 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 251 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 252 // Toggle maximized mode off. | 252 // Toggle maximized mode off. |
| 253 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 253 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 254 false); | 254 false); |
| 255 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 255 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Tests that keyboard gets suppressed in maximized mode. | 258 // Tests that keyboard gets suppressed in maximized mode. |
| 259 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { | 259 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { |
| 260 std::vector<ui::TouchscreenDevice> screens; | 260 std::vector<ui::TouchscreenDevice> screens; |
| 261 screens.push_back( | 261 screens.push_back( |
| 262 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | 262 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
| 263 "Touchscreen", gfx::Size(1024, 768), 0)); | 263 "Touchscreen", gfx::Size(1024, 768), 0)); |
| 264 UpdateTouchscreenDevices(screens); | 264 UpdateTouchscreenDevices(screens); |
| 265 std::vector<ui::InputDevice> keyboard_devices; | 265 std::vector<ui::InputDevice> keyboard_devices; |
| 266 keyboard_devices.push_back(ui::InputDevice( | 266 keyboard_devices.push_back(ui::InputDevice( |
| 267 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 267 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 268 keyboard_devices.push_back(ui::InputDevice( | 268 keyboard_devices.push_back(ui::InputDevice( |
| 269 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard")); | 269 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard")); |
| 270 UpdateKeyboardDevices(keyboard_devices); | 270 UpdateKeyboardDevices(keyboard_devices); |
| 271 // Toggle maximized mode on. | 271 // Toggle maximized mode on. |
| 272 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 272 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 273 true); | 273 true); |
| 274 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 274 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 275 ASSERT_TRUE(notified()); | 275 ASSERT_TRUE(notified()); |
| 276 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 276 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
| 277 // Toggle show keyboard. Keyboard should be visible. | 277 // Toggle show keyboard. Keyboard should be visible. |
| 278 ResetObserver(); | 278 ResetObserver(); |
| 279 Shell::GetInstance() | 279 Shell::GetInstance() |
| 280 ->virtual_keyboard_controller() | 280 ->virtual_keyboard_controller() |
| 281 ->ToggleIgnoreExternalKeyboard(); | 281 ->ToggleIgnoreExternalKeyboard(); |
| 282 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 282 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 283 ASSERT_TRUE(notified()); | 283 ASSERT_TRUE(notified()); |
| 284 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 284 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
| 285 // Toggle show keyboard. Keyboard should be hidden. | 285 // Toggle show keyboard. Keyboard should be hidden. |
| 286 ResetObserver(); | 286 ResetObserver(); |
| 287 Shell::GetInstance() | 287 Shell::GetInstance() |
| 288 ->virtual_keyboard_controller() | 288 ->virtual_keyboard_controller() |
| 289 ->ToggleIgnoreExternalKeyboard(); | 289 ->ToggleIgnoreExternalKeyboard(); |
| 290 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 290 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 291 ASSERT_TRUE(notified()); | 291 ASSERT_TRUE(notified()); |
| 292 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); | 292 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); |
| 293 // Remove external keyboard. Should be notified that the keyboard is not | 293 // Remove external keyboard. Should be notified that the keyboard is not |
| 294 // suppressed. | 294 // suppressed. |
| 295 ResetObserver(); | 295 ResetObserver(); |
| 296 keyboard_devices.pop_back(); | 296 keyboard_devices.pop_back(); |
| 297 UpdateKeyboardDevices(keyboard_devices); | 297 UpdateKeyboardDevices(keyboard_devices); |
| 298 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 298 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 299 ASSERT_TRUE(notified()); | 299 ASSERT_TRUE(notified()); |
| 300 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); | 300 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); |
| 301 // Toggle maximized mode oFF. | 301 // Toggle maximized mode oFF. |
| 302 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 302 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 303 false); | 303 false); |
| 304 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 304 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
| 305 } | 305 } |
| 306 | 306 |
| 307 class VirtualKeyboardControllerAlwaysEnabledTest | 307 class VirtualKeyboardControllerAlwaysEnabledTest |
| 308 : public VirtualKeyboardControllerAutoTest { | 308 : public VirtualKeyboardControllerAutoTest { |
| 309 public: | 309 public: |
| 310 VirtualKeyboardControllerAlwaysEnabledTest() | 310 VirtualKeyboardControllerAlwaysEnabledTest() |
| 311 : VirtualKeyboardControllerAutoTest() {} | 311 : VirtualKeyboardControllerAutoTest() {} |
| 312 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} | 312 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} |
| (...skipping 18 matching lines...) Expand all Loading... |
| 331 UpdateTouchscreenDevices(screens); | 331 UpdateTouchscreenDevices(screens); |
| 332 std::vector<ui::InputDevice> keyboard_devices; | 332 std::vector<ui::InputDevice> keyboard_devices; |
| 333 keyboard_devices.push_back(ui::InputDevice( | 333 keyboard_devices.push_back(ui::InputDevice( |
| 334 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); | 334 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); |
| 335 UpdateKeyboardDevices(keyboard_devices); | 335 UpdateKeyboardDevices(keyboard_devices); |
| 336 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 336 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace test | 339 } // namespace test |
| 340 } // namespace ash | 340 } // namespace ash |
| OLD | NEW |