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

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: 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 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 <vector>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 11 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
12 #include "base/command_line.h"
13 #include "ui/events/device_data_manager.h"
14 #include "ui/events/device_hotplug_event_observer.h"
15 #include "ui/events/input_device.h"
16 #include "ui/events/keyboard_device.h"
17 #include "ui/events/touchscreen_device.h"
18 #include "ui/keyboard/keyboard_export.h"
19 #include "ui/keyboard/keyboard_switches.h"
10 #include "ui/keyboard/keyboard_util.h" 20 #include "ui/keyboard/keyboard_util.h"
11 21
12 namespace ash { 22 namespace ash {
13 namespace test { 23 namespace test {
14 24
15 typedef AshTestBase VirtualKeyboardControllerTest; 25 class VirtualKeyboardControllerTest: public AshTestBase {
26 public:
27 VirtualKeyboardControllerTest() {}
28 virtual ~VirtualKeyboardControllerTest() {}
29
30 void EnableAutoVirtualKeyboard() {
31 CommandLine::ForCurrentProcess()->AppendSwitch(
32 keyboard::switches::kAutoVirtualKeyboard);
33 }
34
35 void UpdateDevices(std::vector<ui::TouchscreenDevice> touchscreen_devices,
36 std::vector<ui::KeyboardDevice> keyboard_devices) {
37 ui::DeviceHotplugEventObserver* manager =
38 ui::DeviceDataManager::GetInstance();
39 manager->OnTouchscreenDevicesUpdated(touchscreen_devices);
40 manager->OnKeyboardDevicesUpdated(keyboard_devices);
41 }
42 private:
43 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest);
44 };
16 45
17 // Tests that the onscreen keyboard becomes enabled when maximize mode is 46 // Tests that the onscreen keyboard becomes enabled when maximize mode is
18 // enabled. 47 // enabled.
19 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { 48 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
20 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 49 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
21 Shell::GetInstance()->maximize_mode_controller()-> 50 Shell::GetInstance()->maximize_mode_controller()->
22 EnableMaximizeModeWindowManager(true); 51 EnableMaximizeModeWindowManager(true);
23 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 52 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
24 Shell::GetInstance()->maximize_mode_controller()-> 53 Shell::GetInstance()->maximize_mode_controller()->
25 EnableMaximizeModeWindowManager(false); 54 EnableMaximizeModeWindowManager(false);
26 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 55 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
56
57 // Test that enabling the flag still causes this test to pass.
58 EnableAutoVirtualKeyboard();
59 std::vector<ui::TouchscreenDevice> devices;
60 devices.push_back(ui::TouchscreenDevice(1, ui::InputDeviceType::INTERNAL,
61 "Touchscreen", gfx::Size(1024, 768)));
62 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
63 Shell::GetInstance()->maximize_mode_controller()->
64 EnableMaximizeModeWindowManager(true);
65 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
66 Shell::GetInstance()->maximize_mode_controller()->
67 EnableMaximizeModeWindowManager(false);
68 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
27 } 69 }
28 70
71 TEST_F(VirtualKeyboardControllerTest, DisabledIfNoInternalTouchScreen) {
72 EnableAutoVirtualKeyboard();
73 UpdateDevices({}, {});
74 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
75 std::vector<ui::TouchscreenDevice> devices;
76 // Add external touchscreen device. Keyboard should not deploy.
77 devices.push_back(ui::TouchscreenDevice(1, ui::InputDeviceType::EXTERNAL,
78 "Touchscreen External", gfx::Size(800, 600)));
79 UpdateDevices(devices, {});
80 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
81 // Add internal touchscreen device. Keyboard should deploy.
82 devices.push_back(ui::TouchscreenDevice(2, ui::InputDeviceType::INTERNAL,
83 "Touchscreen", gfx::Size(1024, 768)));
84 UpdateDevices(devices, {});
85 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
86 }
87
88 TEST_F(VirtualKeyboardControllerTest, MaximizeModeIgnoresInternalKeyboard) {
89 EnableAutoVirtualKeyboard();
90 std::vector<ui::TouchscreenDevice> screens;
91 std::vector<ui::KeyboardDevice> keyboards;
92 // Mock a device with a touchscreen and internal keyboard.
93 screens.push_back(ui::TouchscreenDevice(2, ui::InputDeviceType::INTERNAL,
94 "Touchscreen", gfx::Size(1024, 768)));
95 keyboards.push_back(ui::KeyboardDevice(1, ui::InputDeviceType::INTERNAL,
96 "Keyboard"));
97 UpdateDevices(screens, keyboards);
98 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
99 // Enable maximize mode. Should now ignore the internal keyboard.
100 Shell::GetInstance()->maximize_mode_controller()->
101 EnableMaximizeModeWindowManager(true);
102 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
103 }
104
29 } // namespace test 105 } // namespace test
30 } // namespace ash 106 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698