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 "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 9 #include "base/command_line.h" |
10 #include "ui/events/device_data_manager.h" | |
11 #include "ui/events/device_hotplug_event_observer.h" | |
12 #include "ui/events/input_device.h" | |
13 #include "ui/events/keyboard_device.h" | |
14 #include "ui/events/touchscreen_device.h" | |
15 #include "ui/keyboard/keyboard_export.h" | |
16 #include "ui/keyboard/keyboard_switches.h" | |
10 #include "ui/keyboard/keyboard_util.h" | 17 #include "ui/keyboard/keyboard_util.h" |
11 | 18 |
12 namespace ash { | 19 namespace ash { |
13 namespace test { | 20 namespace test { |
14 | 21 |
15 typedef AshTestBase VirtualKeyboardControllerTest; | 22 class VirtualKeyboardControllerTest : public AshTestBase { |
23 public: | |
24 VirtualKeyboardControllerTest() {} | |
25 virtual ~VirtualKeyboardControllerTest() {} | |
16 | 26 |
17 // Tests that the onscreen keyboard becomes enabled when maximize mode is | 27 void EnableAutoVirtualKeyboard() { |
18 // enabled. | 28 CommandLine::ForCurrentProcess()->AppendSwitch( |
19 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { | 29 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
| |
30 } | |
31 | |
32 void UpdateTouchscreenDevices( | |
33 std::vector<ui::TouchscreenDevice> touchscreen_devices) { | |
34 ui::DeviceHotplugEventObserver* manager = | |
35 ui::DeviceDataManager::GetInstance(); | |
36 manager->OnTouchscreenDevicesUpdated(touchscreen_devices); | |
37 } | |
38 | |
39 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) { | |
40 ui::DeviceHotplugEventObserver* manager = | |
41 ui::DeviceDataManager::GetInstance(); | |
42 manager->OnKeyboardDevicesUpdated(keyboard_devices); | |
43 } | |
44 | |
45 private: | |
46 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); | |
47 }; | |
48 | |
49 // Tests that the onscreen keyboard is disabled if an internal keyboard is | |
50 // present. | |
51 TEST_F(VirtualKeyboardControllerTest, DisabledIfInternalKeyboardPresent) { | |
52 // Set up environment with no touchscreens, and one internal keyboard. | |
53 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); | |
54 std::vector<ui::KeyboardDevice> keyboards; | |
55 keyboards.push_back(ui::KeyboardDevice( | |
56 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); | |
57 | |
58 UpdateKeyboardDevices(keyboards); | |
20 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | 59 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); |
21 Shell::GetInstance()->maximize_mode_controller()-> | 60 // Remove the internal keyboard. Virtual keyboard should now show. |
22 EnableMaximizeModeWindowManager(true); | 61 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); |
23 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | 62 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
24 Shell::GetInstance()->maximize_mode_controller()-> | 63 // Replug in the internal keyboard. Virtual keyboard should hide. |
25 EnableMaximizeModeWindowManager(false); | 64 UpdateKeyboardDevices(keyboards); |
65 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
66 | |
67 // Enable the auto detect flag. With a touchscreen present, the behaviour | |
68 // should be preserved. | |
69 EnableAutoVirtualKeyboard(); | |
70 std::vector<ui::TouchscreenDevice> screens; | |
71 screens.push_back( | |
72 ui::TouchscreenDevice(1, | |
73 ui::InputDeviceType::INPUT_DEVICE_INTERNAL, | |
74 "Touchscreen", | |
75 gfx::Size(1024, 768))); | |
76 UpdateTouchscreenDevices(screens); | |
77 | |
78 UpdateKeyboardDevices(keyboards); | |
79 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); | |
80 // Remove the internal keyboard. Virtual keyboard should now show. | |
81 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); | |
82 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | |
83 // Replug in the internal keyboard. Virtual keyboard should hide. | |
84 UpdateKeyboardDevices(keyboards); | |
26 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 85 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
27 } | 86 } |
28 | 87 |
88 TEST_F(VirtualKeyboardControllerTest, DisabledIfNoTouchScreen) { | |
89 EnableAutoVirtualKeyboard(); | |
90 std::vector<ui::TouchscreenDevice> devices; | |
91 // Add a touchscreen. Keyboard should deploy. | |
92 devices.push_back( | |
93 ui::TouchscreenDevice(1, | |
94 ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, | |
95 "Touchscreen", | |
96 gfx::Size(800, 600))); | |
97 UpdateTouchscreenDevices(devices); | |
98 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | |
99 // Remove touchscreen. Keyboard should hide. | |
100 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); | |
101 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
102 } | |
103 | |
29 } // namespace test | 104 } // namespace test |
30 } // namespace ash | 105 } // namespace ash |
OLD | NEW |