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

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: Fix typo. Created 6 years, 1 month 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
« no previous file with comments | « ash/virtual_keyboard_controller.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
19 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { 51 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
20 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 52 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
21 Shell::GetInstance()->maximize_mode_controller()-> 53 // Toggle maximized mode on.
22 EnableMaximizeModeWindowManager(true); 54 Shell::GetInstance()
55 ->maximize_mode_controller()
56 ->EnableMaximizeModeWindowManager(true);
23 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 57 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
24 Shell::GetInstance()->maximize_mode_controller()-> 58 // Toggle maximized mode off.
25 EnableMaximizeModeWindowManager(false); 59 Shell::GetInstance()
60 ->maximize_mode_controller()
61 ->EnableMaximizeModeWindowManager(false);
26 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 62 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
27 } 63 }
28 64
65 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest {
66 public:
67 void SetUp() override {
68 CommandLine::ForCurrentProcess()->AppendSwitch(
69 keyboard::switches::kAutoVirtualKeyboard);
70 VirtualKeyboardControllerTest::SetUp();
71 }
72 };
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
OLDNEW
« no previous file with comments | « ash/virtual_keyboard_controller.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698