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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
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 EnableAutoVirtualKeyboard() {
18 // enabled. 29 CommandLine::ForCurrentProcess()->AppendSwitch(
30 keyboard::switches::kAutoVirtualKeyboard);
flackr 2014/10/27 15:33:13 Since flags often affect initialization logic it w
rsadam 2014/10/27 15:51:19 Done.
31 }
32
33 void UpdateTouchscreenDevices(
34 std::vector<ui::TouchscreenDevice> touchscreen_devices) {
35 ui::DeviceHotplugEventObserver* manager =
36 ui::DeviceDataManager::GetInstance();
37 manager->OnTouchscreenDevicesUpdated(touchscreen_devices);
38 }
39
40 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) {
41 ui::DeviceHotplugEventObserver* manager =
42 ui::DeviceDataManager::GetInstance();
43 manager->OnKeyboardDevicesUpdated(keyboard_devices);
44 }
45
46 void SetUp() override {
47 AshTestBase::SetUp();
48 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
49 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
50 }
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest);
54 };
55
19 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { 56 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
20 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 57 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
21 Shell::GetInstance()->maximize_mode_controller()-> 58 // Toggle maximized mode on.
22 EnableMaximizeModeWindowManager(true); 59 Shell::GetInstance()
60 ->maximize_mode_controller()
61 ->EnableMaximizeModeWindowManager(true);
23 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 62 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
24 Shell::GetInstance()->maximize_mode_controller()-> 63 // Toggle maximized mode off.
25 EnableMaximizeModeWindowManager(false); 64 Shell::GetInstance()
65 ->maximize_mode_controller()
66 ->EnableMaximizeModeWindowManager(false);
26 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 67 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
27 } 68 }
28 69
70 // Tests that the onscreen keyboard is disabled if an internal keyboard is
71 // present.
72 TEST_F(VirtualKeyboardControllerTest, DisabledIfInternalKeyboardPresent) {
73 EnableAutoVirtualKeyboard();
74 std::vector<ui::TouchscreenDevice> screens;
75 screens.push_back(
76 ui::TouchscreenDevice(1,
77 ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
78 "Touchscreen",
79 gfx::Size(1024, 768)));
80 UpdateTouchscreenDevices(screens);
81 std::vector<ui::KeyboardDevice> keyboards;
82 keyboards.push_back(ui::KeyboardDevice(
83 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
84 UpdateKeyboardDevices(keyboards);
85 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
86 // Remove the internal keyboard. Virtual keyboard should now show.
87 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
88 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
89 // Replug in the internal keyboard. Virtual keyboard should hide.
90 UpdateKeyboardDevices(keyboards);
91 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
92 }
93
94 TEST_F(VirtualKeyboardControllerTest, DisabledIfNoTouchScreen) {
95 EnableAutoVirtualKeyboard();
96 std::vector<ui::TouchscreenDevice> devices;
97 // Add a touchscreen. Keyboard should deploy.
98 devices.push_back(
99 ui::TouchscreenDevice(1,
100 ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
101 "Touchscreen",
102 gfx::Size(800, 600)));
103 UpdateTouchscreenDevices(devices);
104 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
105 // Remove touchscreen. Keyboard should hide.
106 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
107 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
108 }
109
29 } // namespace test 110 } // namespace test
30 } // namespace ash 111 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698