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

Side by Side Diff: ash/virtual_keyboard_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698