Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2991)

Unified Diff: ash/virtual_keyboard_controller_unittest.cc

Issue 613343005: Automatic deployment of the virtual keyboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not display the keyboard while testing on desktop. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
}

Powered by Google App Engine
This is Rietveld 408576698