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

Side by Side Diff: ash/virtual_keyboard_controller_unittest.cc

Issue 904733002: Remove useless InputDevice::name field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « ash/touch/touchscreen_util_unittest.cc ('k') | ui/events/devices/input_device.h » ('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 <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_observer.h" 10 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_observer.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 77 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
78 } 78 }
79 79
80 // Mock event blocker that enables the internal keyboard when it's destructor 80 // Mock event blocker that enables the internal keyboard when it's destructor
81 // is called. 81 // is called.
82 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard { 82 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard {
83 public: 83 public:
84 MockEventBlocker() {} 84 MockEventBlocker() {}
85 ~MockEventBlocker() override { 85 ~MockEventBlocker() override {
86 std::vector<ui::KeyboardDevice> keyboards; 86 std::vector<ui::KeyboardDevice> keyboards;
87 keyboards.push_back(ui::KeyboardDevice( 87 keyboards.push_back(
88 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); 88 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
89 ui::DeviceHotplugEventObserver* manager = 89 ui::DeviceHotplugEventObserver* manager =
90 ui::DeviceDataManager::GetInstance(); 90 ui::DeviceDataManager::GetInstance();
91 manager->OnKeyboardDevicesUpdated(keyboards); 91 manager->OnKeyboardDevicesUpdated(keyboards);
92 } 92 }
93 93
94 private: 94 private:
95 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); 95 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker);
96 }; 96 };
97 97
98 // Tests that reenabling keyboard devices while shutting down does not 98 // Tests that reenabling keyboard devices while shutting down does not
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Whether the keeyboard is suppressed. 150 // Whether the keeyboard is suppressed.
151 bool suppressed_; 151 bool suppressed_;
152 152
153 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest); 153 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest);
154 }; 154 };
155 155
156 // Tests that the onscreen keyboard is disabled if an internal keyboard is 156 // Tests that the onscreen keyboard is disabled if an internal keyboard is
157 // present. 157 // present.
158 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) { 158 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) {
159 std::vector<ui::TouchscreenDevice> screens; 159 std::vector<ui::TouchscreenDevice> screens;
160 screens.push_back( 160 screens.push_back(ui::TouchscreenDevice(
161 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, 161 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
162 "Touchscreen", gfx::Size(1024, 768), 0));
163 UpdateTouchscreenDevices(screens); 162 UpdateTouchscreenDevices(screens);
164 std::vector<ui::KeyboardDevice> keyboards; 163 std::vector<ui::KeyboardDevice> keyboards;
165 keyboards.push_back(ui::KeyboardDevice( 164 keyboards.push_back(
166 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); 165 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
167 UpdateKeyboardDevices(keyboards); 166 UpdateKeyboardDevices(keyboards);
168 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 167 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
169 // Remove the internal keyboard. Virtual keyboard should now show. 168 // Remove the internal keyboard. Virtual keyboard should now show.
170 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 169 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
171 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 170 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
172 // Replug in the internal keyboard. Virtual keyboard should hide. 171 // Replug in the internal keyboard. Virtual keyboard should hide.
173 UpdateKeyboardDevices(keyboards); 172 UpdateKeyboardDevices(keyboards);
174 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 173 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
175 } 174 }
176 175
177 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) { 176 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) {
178 std::vector<ui::TouchscreenDevice> devices; 177 std::vector<ui::TouchscreenDevice> devices;
179 // Add a touchscreen. Keyboard should deploy. 178 // Add a touchscreen. Keyboard should deploy.
180 devices.push_back( 179 devices.push_back(ui::TouchscreenDevice(
181 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, 180 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(800, 600), 0));
182 "Touchscreen", gfx::Size(800, 600), 0));
183 UpdateTouchscreenDevices(devices); 181 UpdateTouchscreenDevices(devices);
184 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 182 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
185 // Remove touchscreen. Keyboard should hide. 183 // Remove touchscreen. Keyboard should hide.
186 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); 184 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
187 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 185 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
188 } 186 }
189 187
190 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) { 188 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) {
191 std::vector<ui::TouchscreenDevice> screens; 189 std::vector<ui::TouchscreenDevice> screens;
192 screens.push_back( 190 screens.push_back(ui::TouchscreenDevice(
193 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, 191 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
194 "Touchscreen", gfx::Size(1024, 768), 0));
195 UpdateTouchscreenDevices(screens); 192 UpdateTouchscreenDevices(screens);
196 std::vector<ui::KeyboardDevice> keyboards; 193 std::vector<ui::KeyboardDevice> keyboards;
197 keyboards.push_back(ui::KeyboardDevice( 194 keyboards.push_back(
198 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 195 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
199 UpdateKeyboardDevices(keyboards); 196 UpdateKeyboardDevices(keyboards);
200 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 197 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
201 ASSERT_TRUE(notified()); 198 ASSERT_TRUE(notified());
202 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 199 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
203 // Toggle show keyboard. Keyboard should be visible. 200 // Toggle show keyboard. Keyboard should be visible.
204 ResetObserver(); 201 ResetObserver();
205 Shell::GetInstance() 202 Shell::GetInstance()
206 ->virtual_keyboard_controller() 203 ->virtual_keyboard_controller()
207 ->ToggleIgnoreExternalKeyboard(); 204 ->ToggleIgnoreExternalKeyboard();
208 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 205 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
(...skipping 12 matching lines...) Expand all
221 ResetObserver(); 218 ResetObserver();
222 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 219 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
223 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 220 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
224 ASSERT_TRUE(notified()); 221 ASSERT_TRUE(notified());
225 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); 222 ASSERT_FALSE(IsVirtualKeyboardSuppressed());
226 } 223 }
227 224
228 // Tests handling multiple keyboards. Catches crbug.com/430252 225 // Tests handling multiple keyboards. Catches crbug.com/430252
229 TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) { 226 TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) {
230 std::vector<ui::KeyboardDevice> keyboards; 227 std::vector<ui::KeyboardDevice> keyboards;
231 keyboards.push_back(ui::KeyboardDevice( 228 keyboards.push_back(
232 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); 229 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
233 keyboards.push_back(ui::KeyboardDevice( 230 keyboards.push_back(
234 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 231 ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
235 keyboards.push_back(ui::KeyboardDevice( 232 keyboards.push_back(
236 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 233 ui::KeyboardDevice(3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
237 UpdateKeyboardDevices(keyboards); 234 UpdateKeyboardDevices(keyboards);
238 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 235 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
239 } 236 }
240 237
241 class VirtualKeyboardControllerAlwaysEnabledTest 238 class VirtualKeyboardControllerAlwaysEnabledTest
242 : public VirtualKeyboardControllerAutoTest { 239 : public VirtualKeyboardControllerAutoTest {
243 public: 240 public:
244 VirtualKeyboardControllerAlwaysEnabledTest() 241 VirtualKeyboardControllerAlwaysEnabledTest()
245 : VirtualKeyboardControllerAutoTest() {} 242 : VirtualKeyboardControllerAutoTest() {}
246 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} 243 ~VirtualKeyboardControllerAlwaysEnabledTest() override {}
247 244
248 void SetUp() override { 245 void SetUp() override {
249 base::CommandLine::ForCurrentProcess()->AppendSwitch( 246 base::CommandLine::ForCurrentProcess()->AppendSwitch(
250 keyboard::switches::kEnableVirtualKeyboard); 247 keyboard::switches::kEnableVirtualKeyboard);
251 VirtualKeyboardControllerAutoTest::SetUp(); 248 VirtualKeyboardControllerAutoTest::SetUp();
252 } 249 }
253 250
254 private: 251 private:
255 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAlwaysEnabledTest); 252 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAlwaysEnabledTest);
256 }; 253 };
257 254
258 // Tests that the controller cannot suppress the keyboard if the virtual 255 // Tests that the controller cannot suppress the keyboard if the virtual
259 // keyboard always enabled flag is active. 256 // keyboard always enabled flag is active.
260 TEST_F(VirtualKeyboardControllerAlwaysEnabledTest, DoesNotSuppressKeyboard) { 257 TEST_F(VirtualKeyboardControllerAlwaysEnabledTest, DoesNotSuppressKeyboard) {
261 std::vector<ui::TouchscreenDevice> screens; 258 std::vector<ui::TouchscreenDevice> screens;
262 screens.push_back( 259 screens.push_back(ui::TouchscreenDevice(
263 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, 260 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
264 "Touchscreen", gfx::Size(1024, 768), 0));
265 UpdateTouchscreenDevices(screens); 261 UpdateTouchscreenDevices(screens);
266 std::vector<ui::KeyboardDevice> keyboards; 262 std::vector<ui::KeyboardDevice> keyboards;
267 keyboards.push_back(ui::KeyboardDevice( 263 keyboards.push_back(
268 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 264 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
269 UpdateKeyboardDevices(keyboards); 265 UpdateKeyboardDevices(keyboards);
270 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 266 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
271 } 267 }
272 268
273 } // namespace test 269 } // namespace test
274 } // namespace ash 270 } // namespace ash
OLDNEW
« no previous file with comments | « ash/touch/touchscreen_util_unittest.cc ('k') | ui/events/devices/input_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698