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

Side by Side Diff: ash/virtual_keyboard_controller_unittest.cc

Issue 2113053003: Moves Shell::maximize_mode_controller() to WmShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: order Created 4 years, 5 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/virtual_keyboard_controller.cc ('k') | ash/wm/lock_state_controller_unittest.cc » ('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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
(...skipping 30 matching lines...) Expand all
41 41
42 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) { 42 void UpdateKeyboardDevices(std::vector<ui::InputDevice> keyboard_devices) {
43 ui::DeviceHotplugEventObserver* manager = 43 ui::DeviceHotplugEventObserver* manager =
44 ui::DeviceDataManager::GetInstance(); 44 ui::DeviceDataManager::GetInstance();
45 manager->OnKeyboardDevicesUpdated(keyboard_devices); 45 manager->OnKeyboardDevicesUpdated(keyboard_devices);
46 } 46 }
47 47
48 // Sets the event blocker on the maximized window controller. 48 // Sets the event blocker on the maximized window controller.
49 void SetEventBlocker( 49 void SetEventBlocker(
50 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) { 50 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) {
51 Shell::GetInstance()->maximize_mode_controller()->event_blocker_ = 51 WmShell::Get()->maximize_mode_controller()->event_blocker_ =
52 std::move(blocker); 52 std::move(blocker);
53 } 53 }
54 54
55 void SetUp() override { 55 void SetUp() override {
56 base::CommandLine::ForCurrentProcess()->AppendSwitch( 56 base::CommandLine::ForCurrentProcess()->AppendSwitch(
57 keyboard::switches::kDisableSmartVirtualKeyboard); 57 keyboard::switches::kDisableSmartVirtualKeyboard);
58 AshTestBase::SetUp(); 58 AshTestBase::SetUp();
59 UpdateKeyboardDevices(std::vector<ui::InputDevice>()); 59 UpdateKeyboardDevices(std::vector<ui::InputDevice>());
60 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); 60 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
61 } 61 }
62 62
63 private: 63 private:
64 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); 64 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest);
65 }; 65 };
66 66
67 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { 67 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
68 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 68 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
69 // Toggle maximized mode on. 69 // Toggle maximized mode on.
70 Shell::GetInstance() 70 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
71 ->maximize_mode_controller() 71 true);
72 ->EnableMaximizeModeWindowManager(true);
73 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 72 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
74 // Toggle maximized mode off. 73 // Toggle maximized mode off.
75 Shell::GetInstance() 74 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
76 ->maximize_mode_controller() 75 false);
77 ->EnableMaximizeModeWindowManager(false);
78 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 76 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
79 } 77 }
80 78
81 // 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
82 // is called. 80 // is called.
83 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard { 81 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard {
84 public: 82 public:
85 MockEventBlocker() {} 83 MockEventBlocker() {}
86 ~MockEventBlocker() override { 84 ~MockEventBlocker() override {
87 std::vector<ui::InputDevice> keyboard_devices; 85 std::vector<ui::InputDevice> keyboard_devices;
88 keyboard_devices.push_back(ui::InputDevice( 86 keyboard_devices.push_back(ui::InputDevice(
89 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")); 87 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
90 ui::DeviceHotplugEventObserver* manager = 88 ui::DeviceHotplugEventObserver* manager =
91 ui::DeviceDataManager::GetInstance(); 89 ui::DeviceDataManager::GetInstance();
92 manager->OnKeyboardDevicesUpdated(keyboard_devices); 90 manager->OnKeyboardDevicesUpdated(keyboard_devices);
93 } 91 }
94 92
95 private: 93 private:
96 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker); 94 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker);
97 }; 95 };
98 96
99 // Tests that reenabling keyboard devices while shutting down does not 97 // Tests that reenabling keyboard devices while shutting down does not
100 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204. 98 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204.
101 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) { 99 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) {
102 // Toggle maximized mode on. 100 // Toggle maximized mode on.
103 Shell::GetInstance() 101 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
104 ->maximize_mode_controller() 102 true);
105 ->EnableMaximizeModeWindowManager(true);
106 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker( 103 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> blocker(
107 new MockEventBlocker); 104 new MockEventBlocker);
108 SetEventBlocker(std::move(blocker)); 105 SetEventBlocker(std::move(blocker));
109 } 106 }
110 107
111 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, 108 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest,
112 public VirtualKeyboardObserver { 109 public VirtualKeyboardObserver {
113 public: 110 public:
114 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} 111 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {}
115 ~VirtualKeyboardControllerAutoTest() override {} 112 ~VirtualKeyboardControllerAutoTest() override {}
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 screens.push_back( 240 screens.push_back(
244 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, 241 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
245 "Touchscreen", gfx::Size(1024, 768), 0)); 242 "Touchscreen", gfx::Size(1024, 768), 0));
246 UpdateTouchscreenDevices(screens); 243 UpdateTouchscreenDevices(screens);
247 std::vector<ui::InputDevice> keyboard_devices; 244 std::vector<ui::InputDevice> keyboard_devices;
248 keyboard_devices.push_back(ui::InputDevice( 245 keyboard_devices.push_back(ui::InputDevice(
249 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 246 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
250 UpdateKeyboardDevices(keyboard_devices); 247 UpdateKeyboardDevices(keyboard_devices);
251 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 248 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
252 // Toggle maximized mode on. 249 // Toggle maximized mode on.
253 Shell::GetInstance() 250 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
254 ->maximize_mode_controller() 251 true);
255 ->EnableMaximizeModeWindowManager(true);
256 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 252 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
257 // Toggle maximized mode off. 253 // Toggle maximized mode off.
258 Shell::GetInstance() 254 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
259 ->maximize_mode_controller() 255 false);
260 ->EnableMaximizeModeWindowManager(false);
261 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 256 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
262 } 257 }
263 258
264 // Tests that keyboard gets suppressed in maximized mode. 259 // Tests that keyboard gets suppressed in maximized mode.
265 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) { 260 TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) {
266 std::vector<ui::TouchscreenDevice> screens; 261 std::vector<ui::TouchscreenDevice> screens;
267 screens.push_back( 262 screens.push_back(
268 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, 263 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
269 "Touchscreen", gfx::Size(1024, 768), 0)); 264 "Touchscreen", gfx::Size(1024, 768), 0));
270 UpdateTouchscreenDevices(screens); 265 UpdateTouchscreenDevices(screens);
271 std::vector<ui::InputDevice> keyboard_devices; 266 std::vector<ui::InputDevice> keyboard_devices;
272 keyboard_devices.push_back(ui::InputDevice( 267 keyboard_devices.push_back(ui::InputDevice(
273 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 268 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
274 keyboard_devices.push_back(ui::InputDevice( 269 keyboard_devices.push_back(ui::InputDevice(
275 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard")); 270 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard"));
276 UpdateKeyboardDevices(keyboard_devices); 271 UpdateKeyboardDevices(keyboard_devices);
277 // Toggle maximized mode on. 272 // Toggle maximized mode on.
278 Shell::GetInstance() 273 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
279 ->maximize_mode_controller() 274 true);
280 ->EnableMaximizeModeWindowManager(true);
281 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 275 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
282 ASSERT_TRUE(notified()); 276 ASSERT_TRUE(notified());
283 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 277 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
284 // Toggle show keyboard. Keyboard should be visible. 278 // Toggle show keyboard. Keyboard should be visible.
285 ResetObserver(); 279 ResetObserver();
286 Shell::GetInstance() 280 Shell::GetInstance()
287 ->virtual_keyboard_controller() 281 ->virtual_keyboard_controller()
288 ->ToggleIgnoreExternalKeyboard(); 282 ->ToggleIgnoreExternalKeyboard();
289 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 283 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
290 ASSERT_TRUE(notified()); 284 ASSERT_TRUE(notified());
291 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 285 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
292 // Toggle show keyboard. Keyboard should be hidden. 286 // Toggle show keyboard. Keyboard should be hidden.
293 ResetObserver(); 287 ResetObserver();
294 Shell::GetInstance() 288 Shell::GetInstance()
295 ->virtual_keyboard_controller() 289 ->virtual_keyboard_controller()
296 ->ToggleIgnoreExternalKeyboard(); 290 ->ToggleIgnoreExternalKeyboard();
297 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 291 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
298 ASSERT_TRUE(notified()); 292 ASSERT_TRUE(notified());
299 ASSERT_TRUE(IsVirtualKeyboardSuppressed()); 293 ASSERT_TRUE(IsVirtualKeyboardSuppressed());
300 // Remove external keyboard. Should be notified that the keyboard is not 294 // Remove external keyboard. Should be notified that the keyboard is not
301 // suppressed. 295 // suppressed.
302 ResetObserver(); 296 ResetObserver();
303 keyboard_devices.pop_back(); 297 keyboard_devices.pop_back();
304 UpdateKeyboardDevices(keyboard_devices); 298 UpdateKeyboardDevices(keyboard_devices);
305 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 299 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
306 ASSERT_TRUE(notified()); 300 ASSERT_TRUE(notified());
307 ASSERT_FALSE(IsVirtualKeyboardSuppressed()); 301 ASSERT_FALSE(IsVirtualKeyboardSuppressed());
308 // Toggle maximized mode oFF. 302 // Toggle maximized mode oFF.
309 Shell::GetInstance() 303 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
310 ->maximize_mode_controller() 304 false);
311 ->EnableMaximizeModeWindowManager(false);
312 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 305 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
313 } 306 }
314 307
315 class VirtualKeyboardControllerAlwaysEnabledTest 308 class VirtualKeyboardControllerAlwaysEnabledTest
316 : public VirtualKeyboardControllerAutoTest { 309 : public VirtualKeyboardControllerAutoTest {
317 public: 310 public:
318 VirtualKeyboardControllerAlwaysEnabledTest() 311 VirtualKeyboardControllerAlwaysEnabledTest()
319 : VirtualKeyboardControllerAutoTest() {} 312 : VirtualKeyboardControllerAutoTest() {}
320 ~VirtualKeyboardControllerAlwaysEnabledTest() override {} 313 ~VirtualKeyboardControllerAlwaysEnabledTest() override {}
321 314
(...skipping 17 matching lines...) Expand all
339 UpdateTouchscreenDevices(screens); 332 UpdateTouchscreenDevices(screens);
340 std::vector<ui::InputDevice> keyboard_devices; 333 std::vector<ui::InputDevice> keyboard_devices;
341 keyboard_devices.push_back(ui::InputDevice( 334 keyboard_devices.push_back(ui::InputDevice(
342 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 335 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
343 UpdateKeyboardDevices(keyboard_devices); 336 UpdateKeyboardDevices(keyboard_devices);
344 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 337 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
345 } 338 }
346 339
347 } // namespace test 340 } // namespace test
348 } // namespace ash 341 } // namespace ash
OLDNEW
« no previous file with comments | « ash/virtual_keyboard_controller.cc ('k') | ash/wm/lock_state_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698