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

Side by Side Diff: ash/virtual_keyboard_controller_unittest.cc

Issue 834163002: Fixes smart deploy causing crash on shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove InstallEventBlockerForTest method. Created 5 years, 11 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/shell.cc ('k') | ash/wm/maximize_mode/maximize_mode_controller.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>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_observer.h" 10 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_observer.h"
9 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
13 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h"
11 #include "base/command_line.h" 14 #include "base/command_line.h"
12 #include "ui/events/devices/device_data_manager.h" 15 #include "ui/events/devices/device_data_manager.h"
13 #include "ui/events/devices/device_hotplug_event_observer.h" 16 #include "ui/events/devices/device_hotplug_event_observer.h"
14 #include "ui/events/devices/input_device.h" 17 #include "ui/events/devices/input_device.h"
15 #include "ui/events/devices/keyboard_device.h" 18 #include "ui/events/devices/keyboard_device.h"
16 #include "ui/events/devices/touchscreen_device.h" 19 #include "ui/events/devices/touchscreen_device.h"
17 #include "ui/keyboard/keyboard_export.h" 20 #include "ui/keyboard/keyboard_export.h"
18 #include "ui/keyboard/keyboard_switches.h" 21 #include "ui/keyboard/keyboard_switches.h"
19 #include "ui/keyboard/keyboard_util.h" 22 #include "ui/keyboard/keyboard_util.h"
20 23
(...skipping 11 matching lines...) Expand all
32 ui::DeviceDataManager::GetInstance(); 35 ui::DeviceDataManager::GetInstance();
33 manager->OnTouchscreenDevicesUpdated(touchscreen_devices); 36 manager->OnTouchscreenDevicesUpdated(touchscreen_devices);
34 } 37 }
35 38
36 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) { 39 void UpdateKeyboardDevices(std::vector<ui::KeyboardDevice> keyboard_devices) {
37 ui::DeviceHotplugEventObserver* manager = 40 ui::DeviceHotplugEventObserver* manager =
38 ui::DeviceDataManager::GetInstance(); 41 ui::DeviceDataManager::GetInstance();
39 manager->OnKeyboardDevicesUpdated(keyboard_devices); 42 manager->OnKeyboardDevicesUpdated(keyboard_devices);
40 } 43 }
41 44
45 // Sets the event blocker on the maximized window controller.
46 void SetEventBlocker(
47 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) {
48 Shell::GetInstance()
49 ->maximize_mode_controller()
50 ->event_blocker_ = blocker.Pass();
51 }
52
42 void SetUp() override { 53 void SetUp() override {
43 base::CommandLine::ForCurrentProcess()->AppendSwitch( 54 base::CommandLine::ForCurrentProcess()->AppendSwitch(
44 keyboard::switches::kDisableSmartVirtualKeyboard); 55 keyboard::switches::kDisableSmartVirtualKeyboard);
45 AshTestBase::SetUp(); 56 AshTestBase::SetUp();
46 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>()); 57 UpdateKeyboardDevices(std::vector<ui::KeyboardDevice>());
47 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>()); 58 UpdateTouchscreenDevices(std::vector<ui::TouchscreenDevice>());
48 } 59 }
49 60
50 private: 61 private:
51 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest); 62 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardControllerTest);
52 }; 63 };
53 64
54 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) { 65 TEST_F(VirtualKeyboardControllerTest, EnabledDuringMaximizeMode) {
55 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 66 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
56 // Toggle maximized mode on. 67 // Toggle maximized mode on.
57 Shell::GetInstance() 68 Shell::GetInstance()
58 ->maximize_mode_controller() 69 ->maximize_mode_controller()
59 ->EnableMaximizeModeWindowManager(true); 70 ->EnableMaximizeModeWindowManager(true);
60 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 71 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
61 // Toggle maximized mode off. 72 // Toggle maximized mode off.
62 Shell::GetInstance() 73 Shell::GetInstance()
63 ->maximize_mode_controller() 74 ->maximize_mode_controller()
64 ->EnableMaximizeModeWindowManager(false); 75 ->EnableMaximizeModeWindowManager(false);
65 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 76 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
66 } 77 }
67 78
79 // Mock event blocker that enables the internal keyboard when it's destructor
80 // is called.
81 class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard {
82 public:
83 MockEventBlocker() {}
84 ~MockEventBlocker() override {
85 std::vector<ui::KeyboardDevice> keyboards;
86 keyboards.push_back(ui::KeyboardDevice(
87 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
88 ui::DeviceHotplugEventObserver* manager =
89 ui::DeviceDataManager::GetInstance();
90 manager->OnKeyboardDevicesUpdated(keyboards);
91 }
92
93 private:
94 DISALLOW_COPY_AND_ASSIGN(MockEventBlocker);
95 };
96
97 // Tests that reenabling keyboard devices while shutting down does not
98 // cause the Virtual Keyboard Controller to crash. See crbug.com/446204.
99 TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) {
100 // Toggle maximized mode on.
101 Shell::GetInstance()
102 ->maximize_mode_controller()
103 ->EnableMaximizeModeWindowManager(true);
104 scoped_ptr<ScopedDisableInternalMouseAndKeyboard>
105 blocker(new MockEventBlocker);
106 SetEventBlocker(blocker.Pass());
107 }
108
68 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest, 109 class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest,
69 public VirtualKeyboardObserver { 110 public VirtualKeyboardObserver {
70 public: 111 public:
71 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {} 112 VirtualKeyboardControllerAutoTest() : notified_(false), suppressed_(false) {}
72 ~VirtualKeyboardControllerAutoTest() override {} 113 ~VirtualKeyboardControllerAutoTest() override {}
73 114
74 void SetUp() override { 115 void SetUp() override {
75 AshTestBase::SetUp(); 116 AshTestBase::SetUp();
76 // Set the current list of devices to empty so that they don't interfere 117 // Set the current list of devices to empty so that they don't interfere
77 // with the test. 118 // with the test.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 keyboards.push_back(ui::KeyboardDevice( 238 keyboards.push_back(ui::KeyboardDevice(
198 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 239 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
199 keyboards.push_back(ui::KeyboardDevice( 240 keyboards.push_back(ui::KeyboardDevice(
200 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard")); 241 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
201 UpdateKeyboardDevices(keyboards); 242 UpdateKeyboardDevices(keyboards);
202 ASSERT_FALSE(keyboard::IsKeyboardEnabled()); 243 ASSERT_FALSE(keyboard::IsKeyboardEnabled());
203 } 244 }
204 245
205 } // namespace test 246 } // namespace test
206 } // namespace ash 247 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell.cc ('k') | ash/wm/maximize_mode/maximize_mode_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698