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