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

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: Add unittests. 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..57ecc0bc2554fe84a70e99e8711ca49272348071 100644
--- a/ash/virtual_keyboard_controller_unittest.cc
+++ b/ash/virtual_keyboard_controller_unittest.cc
@@ -4,15 +4,44 @@
#include "ash/virtual_keyboard_controller.h"
+#include <vector>
+
#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() {}
+
+ void EnableAutoVirtualKeyboard() {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ keyboard::switches::kAutoVirtualKeyboard);
+ }
+
+ void UpdateDevices(std::vector<ui::TouchscreenDevice> touchscreen_devices,
+ std::vector<ui::KeyboardDevice> keyboard_devices) {
+ ui::DeviceHotplugEventObserver* manager =
+ ui::DeviceDataManager::GetInstance();
+ manager->OnTouchscreenDevicesUpdated(touchscreen_devices);
+ manager->OnKeyboardDevicesUpdated(keyboard_devices);
+ }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest);
+};
// Tests that the onscreen keyboard becomes enabled when maximize mode is
// enabled.
@@ -24,6 +53,53 @@ TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
Shell::GetInstance()->maximize_mode_controller()->
EnableMaximizeModeWindowManager(false);
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
+
+ // Test that enabling the flag still causes this test to pass.
+ EnableAutoVirtualKeyboard();
+ std::vector<ui::TouchscreenDevice> devices;
+ devices.push_back(ui::TouchscreenDevice(1, ui::InputDeviceType::INTERNAL,
+ "Touchscreen", gfx::Size(1024, 768)));
+ ASSERT_FALSE(keyboard::IsKeyboardEnabled());
+ Shell::GetInstance()->maximize_mode_controller()->
+ EnableMaximizeModeWindowManager(true);
+ EXPECT_TRUE(keyboard::IsKeyboardEnabled());
+ Shell::GetInstance()->maximize_mode_controller()->
+ EnableMaximizeModeWindowManager(false);
+ EXPECT_FALSE(keyboard::IsKeyboardEnabled());
+}
+
+TEST_F(VirtualKeyboardControllerTest, DisabledIfNoInternalTouchScreen) {
+ EnableAutoVirtualKeyboard();
+ UpdateDevices({}, {});
+ ASSERT_FALSE(keyboard::IsKeyboardEnabled());
+ std::vector<ui::TouchscreenDevice> devices;
+ // Add external touchscreen device. Keyboard should not deploy.
+ devices.push_back(ui::TouchscreenDevice(1, ui::InputDeviceType::EXTERNAL,
+ "Touchscreen External", gfx::Size(800, 600)));
+ UpdateDevices(devices, {});
+ EXPECT_FALSE(keyboard::IsKeyboardEnabled());
+ // Add internal touchscreen device. Keyboard should deploy.
+ devices.push_back(ui::TouchscreenDevice(2, ui::InputDeviceType::INTERNAL,
+ "Touchscreen", gfx::Size(1024, 768)));
+ UpdateDevices(devices, {});
+ EXPECT_TRUE(keyboard::IsKeyboardEnabled());
+}
+
+TEST_F(VirtualKeyboardControllerTest, MaximizeModeIgnoresInternalKeyboard) {
+ EnableAutoVirtualKeyboard();
+ std::vector<ui::TouchscreenDevice> screens;
+ std::vector<ui::KeyboardDevice> keyboards;
+ // Mock a device with a touchscreen and internal keyboard.
+ screens.push_back(ui::TouchscreenDevice(2, ui::InputDeviceType::INTERNAL,
+ "Touchscreen", gfx::Size(1024, 768)));
+ keyboards.push_back(ui::KeyboardDevice(1, ui::InputDeviceType::INTERNAL,
+ "Keyboard"));
+ UpdateDevices(screens, keyboards);
+ EXPECT_FALSE(keyboard::IsKeyboardEnabled());
+ // Enable maximize mode. Should now ignore the internal keyboard.
+ Shell::GetInstance()->maximize_mode_controller()->
+ EnableMaximizeModeWindowManager(true);
+ EXPECT_TRUE(keyboard::IsKeyboardEnabled());
}
} // namespace test

Powered by Google App Engine
This is Rietveld 408576698