Index: ash/virtual_keyboard_controller_unittest.cc |
diff --git a/ash/virtual_keyboard_controller_unittest.cc b/ash/virtual_keyboard_controller_unittest.cc |
index 8072b84acfa897bc518af0bacbd45125fa3dbcb5..b57a4f5b71ac07b8e47ad7cb20513d398a6a2cd4 100644 |
--- a/ash/virtual_keyboard_controller_unittest.cc |
+++ b/ash/virtual_keyboard_controller_unittest.cc |
@@ -6,23 +6,98 @@ |
#include "ash/shell.h" |
#include "ash/test/ash_test_base.h" |
-#include "ash/wm/maximize_mode/maximize_mode_controller.h" |
+#include "base/command_line.h" |
+#include "ui/events/device_data_manager.h" |
+#include "ui/events/device_hotplug_event_observer.h" |
+#include "ui/events/input_device.h" |
+#include "ui/events/keyboard_device.h" |
+#include "ui/events/touchscreen_device.h" |
+#include "ui/keyboard/keyboard_export.h" |
+#include "ui/keyboard/keyboard_switches.h" |
#include "ui/keyboard/keyboard_util.h" |
namespace ash { |
namespace test { |
-typedef AshTestBase VirtualKeyboardControllerTest; |
+class VirtualKeyboardControllerTest : public AshTestBase { |
+ public: |
+ VirtualKeyboardControllerTest() {} |
+ virtual ~VirtualKeyboardControllerTest() {} |
-// Tests that the onscreen keyboard becomes enabled when maximize mode is |
-// enabled. |
-TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { |
+ void EnableAutoVirtualKeyboard() { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ keyboard::switches::kAutoVirtualKeyboard); |
flackr
2014/10/24 14:54:23
It's probably worth keeping a test of the current
rsadam
2014/10/24 15:32:32
My intention was for DisabledIfInternalKeyboardPre
|
+ } |
+ |
+ void UpdateTouchscreenDevices( |
+ std::vector<ui::TouchscreenDevice> touchscreen_devices) { |
+ ui::DeviceHotplugEventObserver* manager = |
+ ui::DeviceDataManager::GetInstance(); |
+ manager->OnTouchscreenDevicesUpdated(touchscreen_devices); |
+ } |
+ |
+ void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) { |
+ ui::DeviceHotplugEventObserver* manager = |
+ ui::DeviceDataManager::GetInstance(); |
+ manager->OnKeyboardDevicesUpdated(keyboard_devices); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); |
+}; |
+ |
+// Tests that the onscreen keyboard is disabled if an internal keyboard is |
+// present. |
+TEST_F(VirtualKeyboardControllerTest, DisabledIfInternalKeyboardPresent) { |
+ // Set up environment with no touchscreens, and one internal keyboard. |
+ UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); |
+ std::vector<ui::KeyboardDevice> keyboards; |
+ keyboards.push_back(ui::KeyboardDevice( |
+ 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); |
+ |
+ UpdateKeyboardDevices(keyboards); |
+ ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
+ // Remove the internal keyboard. Virtual keyboard should now show. |
+ UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); |
+ EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
+ // Replug in the internal keyboard. Virtual keyboard should hide. |
+ UpdateKeyboardDevices(keyboards); |
+ EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
+ |
+ // Enable the auto detect flag. With a touchscreen present, the behaviour |
+ // should be preserved. |
+ EnableAutoVirtualKeyboard(); |
+ std::vector<ui::TouchscreenDevice> screens; |
+ screens.push_back( |
+ ui::TouchscreenDevice(1, |
+ ui::InputDeviceType::INPUT_DEVICE_INTERNAL, |
+ "Touchscreen", |
+ gfx::Size(1024, 768))); |
+ UpdateTouchscreenDevices(screens); |
+ |
+ UpdateKeyboardDevices(keyboards); |
ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
- Shell::GetInstance()->maximize_mode_controller()-> |
- EnableMaximizeModeWindowManager(true); |
+ // Remove the internal keyboard. Virtual keyboard should now show. |
+ UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); |
+ EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
+ // Replug in the internal keyboard. Virtual keyboard should hide. |
+ UpdateKeyboardDevices(keyboards); |
+ EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
+} |
+ |
+TEST_F(VirtualKeyboardControllerTest, DisabledIfNoTouchScreen) { |
+ EnableAutoVirtualKeyboard(); |
+ std::vector<ui::TouchscreenDevice> devices; |
+ // Add a touchscreen. Keyboard should deploy. |
+ devices.push_back( |
+ ui::TouchscreenDevice(1, |
+ ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, |
+ "Touchscreen", |
+ gfx::Size(800, 600))); |
+ UpdateTouchscreenDevices(devices); |
EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
- Shell::GetInstance()->maximize_mode_controller()-> |
- EnableMaximizeModeWindowManager(false); |
+ // Remove touchscreen. Keyboard should hide. |
+ UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); |
EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
} |