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

Side by Side Diff: ui/events/devices/x11/device_data_manager_x11_unittest.cc

Issue 2028593004: Add new InputDeviceManager interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_keyboard
Patch Set: Fix windows compile error. Created 4 years, 6 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 "ui/events/devices/x11/device_data_manager_x11.h" 5 #include "ui/events/devices/x11/device_data_manager_x11.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 // Generically-named #defines from Xlib that conflict with symbols in GTest. 9 // Generically-named #defines from Xlib that conflict with symbols in GTest.
10 #undef Bool 10 #undef Bool
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) { 74 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) {
75 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); 75 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance();
76 TestInputDeviceObserver observer(manager); 76 TestInputDeviceObserver observer(manager);
77 std::vector<ui::InputDevice> keyboards; 77 std::vector<ui::InputDevice> keyboards;
78 keyboards.push_back(ui::InputDevice( 78 keyboards.push_back(ui::InputDevice(
79 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 79 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
80 keyboards.push_back(ui::InputDevice( 80 keyboards.push_back(ui::InputDevice(
81 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 81 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
82 SetKeyboardDevices(keyboards); 82 SetKeyboardDevices(keyboards);
83 EXPECT_TRUE(observer.change_notified()); 83 EXPECT_TRUE(observer.change_notified());
84 std::vector<InputDevice> devices = manager->keyboard_devices(); 84 std::vector<InputDevice> devices = manager->GetKeyboardDevices();
85 EXPECT_EQ(keyboards.size(), devices.size()); 85 EXPECT_EQ(keyboards.size(), devices.size());
86 observer.Reset(); 86 observer.Reset();
87 // Disable the device, should be notified that the device list contains one 87 // Disable the device, should be notified that the device list contains one
88 // less device. 88 // less device.
89 manager->DisableDevice(2); 89 manager->DisableDevice(2);
90 EXPECT_TRUE(observer.change_notified()); 90 EXPECT_TRUE(observer.change_notified());
91 devices = manager->keyboard_devices(); 91 devices = manager->GetKeyboardDevices();
92 EXPECT_EQ(1u, devices.size()); 92 EXPECT_EQ(1u, devices.size());
93 InputDevice device = devices.front(); 93 InputDevice device = devices.front();
94 EXPECT_EQ(1, device.id); 94 EXPECT_EQ(1, device.id);
95 observer.Reset(); 95 observer.Reset();
96 // Reenable the device, should be notified that the device list contains one 96 // Reenable the device, should be notified that the device list contains one
97 // more device. 97 // more device.
98 manager->EnableDevice(2); 98 manager->EnableDevice(2);
99 EXPECT_TRUE(observer.change_notified()); 99 EXPECT_TRUE(observer.change_notified());
100 devices = manager->keyboard_devices(); 100 devices = manager->GetKeyboardDevices();
101 EXPECT_EQ(keyboards.size(), devices.size()); 101 EXPECT_EQ(keyboards.size(), devices.size());
102 } 102 }
103 103
104 // Tests blocking multiple devices. 104 // Tests blocking multiple devices.
105 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) { 105 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) {
106 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); 106 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance();
107 TestInputDeviceObserver observer(manager); 107 TestInputDeviceObserver observer(manager);
108 std::vector<ui::InputDevice> keyboards; 108 std::vector<ui::InputDevice> keyboards;
109 keyboards.push_back(ui::InputDevice( 109 keyboards.push_back(ui::InputDevice(
110 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 110 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
111 keyboards.push_back(ui::InputDevice( 111 keyboards.push_back(ui::InputDevice(
112 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 112 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
113 SetKeyboardDevices(keyboards); 113 SetKeyboardDevices(keyboards);
114 EXPECT_TRUE(observer.change_notified()); 114 EXPECT_TRUE(observer.change_notified());
115 std::vector<InputDevice> devices = manager->keyboard_devices(); 115 std::vector<InputDevice> devices = manager->GetKeyboardDevices();
116 EXPECT_EQ(keyboards.size(), devices.size()); 116 EXPECT_EQ(keyboards.size(), devices.size());
117 observer.Reset(); 117 observer.Reset();
118 // Disable the device, should be notified that the device list contains one 118 // Disable the device, should be notified that the device list contains one
119 // less device. 119 // less device.
120 manager->DisableDevice(1); 120 manager->DisableDevice(1);
121 EXPECT_TRUE(observer.change_notified()); 121 EXPECT_TRUE(observer.change_notified());
122 devices = manager->keyboard_devices(); 122 devices = manager->GetKeyboardDevices();
123 EXPECT_EQ(1u, devices.size()); 123 EXPECT_EQ(1u, devices.size());
124 observer.Reset(); 124 observer.Reset();
125 // Disable the second device, should be notified that the device list empty. 125 // Disable the second device, should be notified that the device list empty.
126 manager->DisableDevice(2); 126 manager->DisableDevice(2);
127 EXPECT_TRUE(observer.change_notified()); 127 EXPECT_TRUE(observer.change_notified());
128 devices = manager->keyboard_devices(); 128 devices = manager->GetKeyboardDevices();
129 EXPECT_EQ(0u, devices.size()); 129 EXPECT_EQ(0u, devices.size());
130 observer.Reset(); 130 observer.Reset();
131 // Enable the first device, should be notified that one device present. 131 // Enable the first device, should be notified that one device present.
132 manager->EnableDevice(1); 132 manager->EnableDevice(1);
133 EXPECT_TRUE(observer.change_notified()); 133 EXPECT_TRUE(observer.change_notified());
134 devices = manager->keyboard_devices(); 134 devices = manager->GetKeyboardDevices();
135 EXPECT_EQ(1u, devices.size()); 135 EXPECT_EQ(1u, devices.size());
136 observer.Reset(); 136 observer.Reset();
137 // Enable the second device, should be notified that both devices present. 137 // Enable the second device, should be notified that both devices present.
138 manager->EnableDevice(2); 138 manager->EnableDevice(2);
139 EXPECT_TRUE(observer.change_notified()); 139 EXPECT_TRUE(observer.change_notified());
140 devices = manager->keyboard_devices(); 140 devices = manager->GetKeyboardDevices();
141 EXPECT_EQ(2u, devices.size()); 141 EXPECT_EQ(2u, devices.size());
142 } 142 }
143 143
144 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) { 144 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) {
145 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); 145 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance();
146 TestInputDeviceObserver observer(manager); 146 TestInputDeviceObserver observer(manager);
147 std::vector<ui::InputDevice> all_keyboards; 147 std::vector<ui::InputDevice> all_keyboards;
148 all_keyboards.push_back(ui::InputDevice( 148 all_keyboards.push_back(ui::InputDevice(
149 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 149 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
150 all_keyboards.push_back(ui::InputDevice( 150 all_keyboards.push_back(ui::InputDevice(
151 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 151 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
152 SetKeyboardDevices(all_keyboards); 152 SetKeyboardDevices(all_keyboards);
153 EXPECT_TRUE(observer.change_notified()); 153 EXPECT_TRUE(observer.change_notified());
154 std::vector<InputDevice> devices = manager->keyboard_devices(); 154 std::vector<InputDevice> devices = manager->GetKeyboardDevices();
155 EXPECT_EQ(all_keyboards.size(), devices.size()); 155 EXPECT_EQ(all_keyboards.size(), devices.size());
156 observer.Reset(); 156 observer.Reset();
157 // Expect to be notified that the device is no longer available. 157 // Expect to be notified that the device is no longer available.
158 manager->DisableDevice(2); 158 manager->DisableDevice(2);
159 EXPECT_TRUE(observer.change_notified()); 159 EXPECT_TRUE(observer.change_notified());
160 devices = manager->keyboard_devices(); 160 devices = manager->GetKeyboardDevices();
161 EXPECT_EQ(1u, devices.size()); 161 EXPECT_EQ(1u, devices.size());
162 observer.Reset(); 162 observer.Reset();
163 // Unplug the disabled device. Should not be notified, since the active list 163 // Unplug the disabled device. Should not be notified, since the active list
164 // did not change. 164 // did not change.
165 std::vector<ui::InputDevice> subset_keyboards; 165 std::vector<ui::InputDevice> subset_keyboards;
166 subset_keyboards.push_back(ui::InputDevice( 166 subset_keyboards.push_back(ui::InputDevice(
167 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); 167 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
168 SetKeyboardDevices(subset_keyboards); 168 SetKeyboardDevices(subset_keyboards);
169 EXPECT_FALSE(observer.change_notified()); 169 EXPECT_FALSE(observer.change_notified());
170 // Replug in the first device. Should be notified of the new device. 170 // Replug in the first device. Should be notified of the new device.
171 SetKeyboardDevices(all_keyboards); 171 SetKeyboardDevices(all_keyboards);
172 EXPECT_TRUE(observer.change_notified()); 172 EXPECT_TRUE(observer.change_notified());
173 devices = manager->keyboard_devices(); 173 devices = manager->GetKeyboardDevices();
174 // Both devices now present. 174 // Both devices now present.
175 EXPECT_EQ(2u, devices.size()); 175 EXPECT_EQ(2u, devices.size());
176 } 176 }
177 177
178 } // namespace test 178 } // namespace test
179 } // namespace ui 179 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/devices/x11/device_data_manager_x11.cc ('k') | ui/events/devices/x11/touch_factory_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698