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

Side by Side Diff: ash/virtual_keyboard_controller_unittest.cc

Issue 1073573002: Ozone support for device special cases in keyboard event rewriting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: white space Created 5 years, 8 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> 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 28 matching lines...) Expand all
39 39
40 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) { 40 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) {
41 ui::DeviceHotplugEventObserver* manager = 41 ui::DeviceHotplugEventObserver* manager =
42 ui::DeviceDataManager::GetInstance(); 42 ui::DeviceDataManager::GetInstance();
43 manager->OnKeyboardDevicesUpdated(keyboard_devices); 43 manager->OnKeyboardDevicesUpdated(keyboard_devices);
44 } 44 }
45 45
46 // Sets the event blocker on the maximized window controller. 46 // Sets the event blocker on the maximized window controller.
47 void SetEventBlocker( 47 void SetEventBlocker(
48 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { 48 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) {
49 Shell::GetInstance() 49 Shell::GetInstance()->maximize_mode_controller()->event_blocker_ =
50 ->maximize_mode_controller() 50 blocker.Pass();
51 ->event_blocker_ = blocker.Pass();
52 } 51 }
53 52
54 void SetUp() override { 53 void SetUp() override {
55 base::CommandLine::ForCurrentProcess()->AppendSwitch( 54 base::CommandLine::ForCurrentProcess()->AppendSwitch(
56 keyboard::switches::kDisableSmartVirtualKeyboard); 55 keyboard::switches::kDisableSmartVirtualKeyboard);
57 AshTestBase::SetUp(); 56 AshTestBase::SetUp();
58 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 57 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
59 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); 58 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
60 } 59 }
61 60
(...skipping 15 matching lines...) Expand all
77 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 76 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
78 } 77 }
79 78
80 // Mock event blocker that enables the internal keyboard when it's destructor 79 // Mock event blocker that enables the internal keyboard when it's destructor
81 // is called. 80 // is called.
82 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard { 81 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard {
83 public: 82 public:
84 MockEventBlocker() {} 83 MockEventBlocker() {}
85 ~MockEventBlocker() override { 84 ~MockEventBlocker() override {
86 std::vector<ui::KeyboardDevice> keyboards; 85 std::vector<ui::KeyboardDevice> keyboards;
87 keyboards.push_back( 86 keyboards.push_back(ui::KeyboardDevice(
88 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); 87 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
89 ui::DeviceHotplugEventObserver* manager = 88 ui::DeviceHotplugEventObserver* manager =
90 ui::DeviceDataManager::GetInstance(); 89 ui::DeviceDataManager::GetInstance();
91 manager->OnKeyboardDevicesUpdated(keyboards); 90 manager->OnKeyboardDevicesUpdated(keyboards);
92 } 91 }
93 92
94 private: 93 private:
95 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); 94 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker);
96 }; 95 };
97 96
98 // Tests that reenabling keyboard devices while shutting down does not 97 // Tests that reenabling keyboard devices while shutting down does not
99 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. 98 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204.
100 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { 99 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) {
101 // Toggle maximized mode on. 100 // Toggle maximized mode on.
102 Shell::GetInstance() 101 Shell::GetInstance()
103 ->maximize_mode_controller() 102 ->maximize_mode_controller()
104 ->EnableMaximizeModeWindowManager(true); 103 ->EnableMaximizeModeWindowManager(true);
105 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> 104 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker(
106 blocker(new MockEventBlocker); 105 new MockEventBlocker);
107 SetEventBlocker(blocker.Pass()); 106 SetEventBlocker(blocker.Pass());
108 } 107 }
109 108
110 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, 109 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest,
111 public VirtualKeyboardObserver { 110 public VirtualKeyboardObserver {
112 public: 111 public:
113 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} 112 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {}
114 ~VirtualKeyboardControllerAutoTest() override {} 113 ~VirtualKeyboardControllerAutoTest() override {}
115 114
116 void SetUp() override { 115 void SetUp() override {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Whether the keeyboard is suppressed. 149 // Whether the keeyboard is suppressed.
151 bool suppressed_; 150 bool suppressed_;
152 151
153 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest); 152 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAutoTest);
154 }; 153 };
155 154
156 // Tests that the onscreen keyboard is disabled if an internal keyboard is 155 // Tests that the onscreen keyboard is disabled if an internal keyboard is
157 // present and maximized mode is disabled. 156 // present and maximized mode is disabled.
158 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) { 157 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) {
159 std::vector<ui::TouchscreenDevice> screens; 158 std::vector<ui::TouchscreenDevice> screens;
160 screens.push_back(ui::TouchscreenDevice( 159 screens.push_back(
161 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0)); 160 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
161 "Touchscreen", gfx::Size(1024, 768), 0));
162 UpdateTouchscreenDevices(screens); 162 UpdateTouchscreenDevices(screens);
163 std::vector<ui::KeyboardDevice> keyboards; 163 std::vector<ui::KeyboardDevice> keyboards;
164 keyboards.push_back( 164 keyboards.push_back(ui::KeyboardDevice(
165 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); 165 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
166 UpdateKeyboardDevices(keyboards); 166 UpdateKeyboardDevices(keyboards);
167 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 167 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
168 // Remove the internal keyboard. Virtual keyboard should now show. 168 // Remove the internal keyboard. Virtual keyboard should now show.
169 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 169 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
170 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 170 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
171 // Replug in the internal keyboard. Virtual keyboard should hide. 171 // Replug in the internal keyboard. Virtual keyboard should hide.
172 UpdateKeyboardDevices(keyboards); 172 UpdateKeyboardDevices(keyboards);
173 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 173 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
174 } 174 }
175 175
176 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) { 176 TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) {
177 std::vector<ui::TouchscreenDevice> devices; 177 std::vector<ui::TouchscreenDevice> devices;
178 // Add a touchscreen. Keyboard should deploy. 178 // Add a touchscreen. Keyboard should deploy.
179 devices.push_back(ui::TouchscreenDevice( 179 devices.push_back(
180 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(800, 600), 0)); 180 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
181 "Touchscreen", gfx::Size(800, 600), 0));
181 UpdateTouchscreenDevices(devices); 182 UpdateTouchscreenDevices(devices);
182 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 183 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
183 // Remove touchscreen. Keyboard should hide. 184 // Remove touchscreen. Keyboard should hide.
184 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); 185 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
185 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 186 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
186 } 187 }
187 188
188 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) { 189 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) {
189 std::vector<ui::TouchscreenDevice> screens; 190 std::vector<ui::TouchscreenDevice> screens;
190 screens.push_back(ui::TouchscreenDevice( 191 screens.push_back(
191 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0)); 192 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
193 "Touchscreen", gfx::Size(1024, 768), 0));
192 UpdateTouchscreenDevices(screens); 194 UpdateTouchscreenDevices(screens);
193 std::vector<ui::KeyboardDevice> keyboards; 195 std::vector<ui::KeyboardDevice> keyboards;
194 keyboards.push_back( 196 keyboards.push_back(ui::KeyboardDevice(
195 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)); 197 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
196 UpdateKeyboardDevices(keyboards); 198 UpdateKeyboardDevices(keyboards);
197 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 199 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
198 ASSERT_TRUE(notified()); 200 ASSERT_TRUE(notified());
199 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 201 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
200 // Toggle show keyboard. Keyboard should be visible. 202 // Toggle show keyboard. Keyboard should be visible.
201 ResetObserver(); 203 ResetObserver();
202 Shell::GetInstance() 204 Shell::GetInstance()
203 ->virtual_keyboard_controller() 205 ->virtual_keyboard_controller()
204 ->ToggleIgnoreExternalKeyboard(); 206 ->ToggleIgnoreExternalKeyboard();
205 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 207 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
(...skipping 12 matching lines...) Expand all
218 ResetObserver(); 220 ResetObserver();
219 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 221 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
220 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 222 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
221 ASSERT_TRUE(notified()); 223 ASSERT_TRUE(notified());
222 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); 224 ASSERT_FALSE(IsVirtualKeyboardSuppressed());
223 } 225 }
224 226
225 // Tests handling multiple keyboards. Catches crbug.com/430252 227 // Tests handling multiple keyboards. Catches crbug.com/430252
226 TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) { 228 TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) {
227 std::vector<ui::KeyboardDevice> keyboards; 229 std::vector<ui::KeyboardDevice> keyboards;
228 keyboards.push_back( 230 keyboards.push_back(ui::KeyboardDevice(
229 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); 231 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
230 keyboards.push_back( 232 keyboards.push_back(ui::KeyboardDevice(
231 ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)); 233 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
232 keyboards.push_back( 234 keyboards.push_back(ui::KeyboardDevice(
233 ui::KeyboardDevice(3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)); 235 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
234 UpdateKeyboardDevices(keyboards); 236 UpdateKeyboardDevices(keyboards);
235 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 237 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
236 } 238 }
237 239
238 // Tests maximized mode interaction without disabling the internal keyboard. 240 // Tests maximized mode interaction without disabling the internal keyboard.
239 TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringMaximizeMode) { 241 TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringMaximizeMode) {
240 std::vector<ui::TouchscreenDevice> screens; 242 std::vector<ui::TouchscreenDevice> screens;
241 screens.push_back(ui::TouchscreenDevice( 243 screens.push_back(
242 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0)); 244 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
245 "Touchscreen", gfx::Size(1024, 768), 0));
243 UpdateTouchscreenDevices(screens); 246 UpdateTouchscreenDevices(screens);
244 std::vector<ui::KeyboardDevice> keyboards; 247 std::vector<ui::KeyboardDevice> keyboards;
245 keyboards.push_back( 248 keyboards.push_back(ui::KeyboardDevice(
246 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); 249 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
247 UpdateKeyboardDevices(keyboards); 250 UpdateKeyboardDevices(keyboards);
248 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 251 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
249 // Toggle maximized mode on. 252 // Toggle maximized mode on.
250 Shell::GetInstance() 253 Shell::GetInstance()
251 ->maximize_mode_controller() 254 ->maximize_mode_controller()
252 ->EnableMaximizeModeWindowManager(true); 255 ->EnableMaximizeModeWindowManager(true);
253 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 256 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
254 // Toggle maximized mode off. 257 // Toggle maximized mode off.
255 Shell::GetInstance() 258 Shell::GetInstance()
256 ->maximize_mode_controller() 259 ->maximize_mode_controller()
257 ->EnableMaximizeModeWindowManager(false); 260 ->EnableMaximizeModeWindowManager(false);
258 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 261 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
259 } 262 }
260 263
261 // Tests that keyboard gets suppressed in maximized mode. 264 // Tests that keyboard gets suppressed in maximized mode.
262 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { 265 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) {
263 std::vector<ui::TouchscreenDevice> screens; 266 std::vector<ui::TouchscreenDevice> screens;
264 screens.push_back(ui::TouchscreenDevice( 267 screens.push_back(
265 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0)); 268 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
269 "Touchscreen", gfx::Size(1024, 768), 0));
266 UpdateTouchscreenDevices(screens); 270 UpdateTouchscreenDevices(screens);
267 std::vector<ui::KeyboardDevice> keyboards; 271 std::vector<ui::KeyboardDevice> keyboards;
268 keyboards.push_back( 272 keyboards.push_back(ui::KeyboardDevice(
269 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); 273 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
270 keyboards.push_back( 274 keyboards.push_back(ui::KeyboardDevice(
271 ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)); 275 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard"));
272 UpdateKeyboardDevices(keyboards); 276 UpdateKeyboardDevices(keyboards);
273 // Toggle maximized mode on. 277 // Toggle maximized mode on.
274 Shell::GetInstance() 278 Shell::GetInstance()
275 ->maximize_mode_controller() 279 ->maximize_mode_controller()
276 ->EnableMaximizeModeWindowManager(true); 280 ->EnableMaximizeModeWindowManager(true);
277 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 281 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
278 ASSERT_TRUE(notified()); 282 ASSERT_TRUE(notified());
279 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 283 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
280 // Toggle show keyboard. Keyboard should be visible. 284 // Toggle show keyboard. Keyboard should be visible.
281 ResetObserver(); 285 ResetObserver();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 326 }
323 327
324 private: 328 private:
325 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAlwaysEnabledTest); 329 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerAlwaysEnabledTest);
326 }; 330 };
327 331
328 // Tests that the controller cannot suppress the keyboard if the virtual 332 // Tests that the controller cannot suppress the keyboard if the virtual
329 // keyboard always enabled flag is active. 333 // keyboard always enabled flag is active.
330 TEST_F(VirtualKeyboardControllerAlwaysEnabledTest, DoesNotSuppressKeyboard) { 334 TEST_F(VirtualKeyboardControllerAlwaysEnabledTest, DoesNotSuppressKeyboard) {
331 std::vector<ui::TouchscreenDevice> screens; 335 std::vector<ui::TouchscreenDevice> screens;
332 screens.push_back(ui::TouchscreenDevice( 336 screens.push_back(
333 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0)); 337 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
338 "Touchscreen", gfx::Size(1024, 768), 0));
334 UpdateTouchscreenDevices(screens); 339 UpdateTouchscreenDevices(screens);
335 std::vector<ui::KeyboardDevice> keyboards; 340 std::vector<ui::KeyboardDevice> keyboards;
336 keyboards.push_back( 341 keyboards.push_back(ui::KeyboardDevice(
337 ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)); 342 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
338 UpdateKeyboardDevices(keyboards); 343 UpdateKeyboardDevices(keyboards);
339 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 344 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
340 } 345 }
341 346
342 } // namespace test 347 } // namespace test
343 } // namespace ash 348 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698