OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 private: | 73 private: |
74 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test); | 74 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test); |
75 }; | 75 }; |
76 | 76 |
77 // Tests that the the device data manager notifies observers when a device is | 77 // Tests that the the device data manager notifies observers when a device is |
78 // disabled and re-enabled. | 78 // disabled and re-enabled. |
79 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) { | 79 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) { |
80 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 80 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
81 TestInputDeviceObserver observer(manager); | 81 TestInputDeviceObserver observer(manager); |
82 std::vector<ui::KeyboardDevice> keyboards; | 82 std::vector<ui::KeyboardDevice> keyboards; |
83 keyboards.push_back(ui::KeyboardDevice( | 83 keyboards.push_back( |
84 1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 84 ui::KeyboardDevice(1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
85 keyboards.push_back(ui::KeyboardDevice( | 85 keyboards.push_back( |
86 2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 86 ui::KeyboardDevice(2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
87 SetKeyboardDevices(keyboards); | 87 SetKeyboardDevices(keyboards); |
88 EXPECT_TRUE(observer.change_notified()); | 88 EXPECT_TRUE(observer.change_notified()); |
89 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 89 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); |
90 EXPECT_EQ(keyboards.size(), devices.size()); | 90 EXPECT_EQ(keyboards.size(), devices.size()); |
91 observer.Reset(); | 91 observer.Reset(); |
92 // Disable the device, should be notified that the device list contains one | 92 // Disable the device, should be notified that the device list contains one |
93 // less device. | 93 // less device. |
94 manager->DisableDevice(2u); | 94 manager->DisableDevice(2u); |
95 EXPECT_TRUE(observer.change_notified()); | 95 EXPECT_TRUE(observer.change_notified()); |
96 devices = manager->keyboard_devices(); | 96 devices = manager->keyboard_devices(); |
97 EXPECT_EQ(1u, devices.size()); | 97 EXPECT_EQ(1u, devices.size()); |
98 KeyboardDevice device = devices.front(); | 98 KeyboardDevice device = devices.front(); |
99 EXPECT_EQ(1u, device.id); | 99 EXPECT_EQ(1u, device.id); |
100 observer.Reset(); | 100 observer.Reset(); |
101 // Reenable the device, should be notified that the device list contains one | 101 // Reenable the device, should be notified that the device list contains one |
102 // more device. | 102 // more device. |
103 manager->EnableDevice(2u); | 103 manager->EnableDevice(2u); |
104 EXPECT_TRUE(observer.change_notified()); | 104 EXPECT_TRUE(observer.change_notified()); |
105 devices = manager->keyboard_devices(); | 105 devices = manager->keyboard_devices(); |
106 EXPECT_EQ(keyboards.size(), devices.size()); | 106 EXPECT_EQ(keyboards.size(), devices.size()); |
107 } | 107 } |
108 | 108 |
109 // Tests blocking multiple devices. | 109 // Tests blocking multiple devices. |
110 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) { | 110 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) { |
111 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 111 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
112 TestInputDeviceObserver observer(manager); | 112 TestInputDeviceObserver observer(manager); |
113 std::vector<ui::KeyboardDevice> keyboards; | 113 std::vector<ui::KeyboardDevice> keyboards; |
114 keyboards.push_back(ui::KeyboardDevice( | 114 keyboards.push_back( |
115 1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 115 ui::KeyboardDevice(1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
116 keyboards.push_back(ui::KeyboardDevice( | 116 keyboards.push_back( |
117 2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 117 ui::KeyboardDevice(2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
118 SetKeyboardDevices(keyboards); | 118 SetKeyboardDevices(keyboards); |
119 EXPECT_TRUE(observer.change_notified()); | 119 EXPECT_TRUE(observer.change_notified()); |
120 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 120 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); |
121 EXPECT_EQ(keyboards.size(), devices.size()); | 121 EXPECT_EQ(keyboards.size(), devices.size()); |
122 observer.Reset(); | 122 observer.Reset(); |
123 // Disable the device, should be notified that the device list contains one | 123 // Disable the device, should be notified that the device list contains one |
124 // less device. | 124 // less device. |
125 manager->DisableDevice(1u); | 125 manager->DisableDevice(1u); |
126 EXPECT_TRUE(observer.change_notified()); | 126 EXPECT_TRUE(observer.change_notified()); |
127 devices = manager->keyboard_devices(); | 127 devices = manager->keyboard_devices(); |
(...skipping 15 matching lines...) Expand all Loading... |
143 manager->EnableDevice(2u); | 143 manager->EnableDevice(2u); |
144 EXPECT_TRUE(observer.change_notified()); | 144 EXPECT_TRUE(observer.change_notified()); |
145 devices = manager->keyboard_devices(); | 145 devices = manager->keyboard_devices(); |
146 EXPECT_EQ(2u, devices.size()); | 146 EXPECT_EQ(2u, devices.size()); |
147 } | 147 } |
148 | 148 |
149 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) { | 149 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) { |
150 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 150 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
151 TestInputDeviceObserver observer(manager); | 151 TestInputDeviceObserver observer(manager); |
152 std::vector<ui::KeyboardDevice> all_keyboards; | 152 std::vector<ui::KeyboardDevice> all_keyboards; |
153 all_keyboards.push_back(ui::KeyboardDevice( | 153 all_keyboards.push_back( |
154 1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 154 ui::KeyboardDevice(1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
155 all_keyboards.push_back(ui::KeyboardDevice( | 155 all_keyboards.push_back( |
156 2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 156 ui::KeyboardDevice(2u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
157 SetKeyboardDevices(all_keyboards); | 157 SetKeyboardDevices(all_keyboards); |
158 EXPECT_TRUE(observer.change_notified()); | 158 EXPECT_TRUE(observer.change_notified()); |
159 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 159 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); |
160 EXPECT_EQ(all_keyboards.size(), devices.size()); | 160 EXPECT_EQ(all_keyboards.size(), devices.size()); |
161 observer.Reset(); | 161 observer.Reset(); |
162 // Expect to be notified that the device is no longer available. | 162 // Expect to be notified that the device is no longer available. |
163 manager->DisableDevice(2u); | 163 manager->DisableDevice(2u); |
164 EXPECT_TRUE(observer.change_notified()); | 164 EXPECT_TRUE(observer.change_notified()); |
165 devices = manager->keyboard_devices(); | 165 devices = manager->keyboard_devices(); |
166 EXPECT_EQ(1u, devices.size()); | 166 EXPECT_EQ(1u, devices.size()); |
167 observer.Reset(); | 167 observer.Reset(); |
168 // Unplug the disabled device. Should not be notified, since the active list | 168 // Unplug the disabled device. Should not be notified, since the active list |
169 // did not change. | 169 // did not change. |
170 std::vector<ui::KeyboardDevice> subset_keyboards; | 170 std::vector<ui::KeyboardDevice> subset_keyboards; |
171 subset_keyboards.push_back(ui::KeyboardDevice( | 171 subset_keyboards.push_back( |
172 1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 172 ui::KeyboardDevice(1u, ui::InputDeviceType::INPUT_DEVICE_INTERNAL)); |
173 SetKeyboardDevices(subset_keyboards); | 173 SetKeyboardDevices(subset_keyboards); |
174 EXPECT_FALSE(observer.change_notified()); | 174 EXPECT_FALSE(observer.change_notified()); |
175 // Replug in the first device. Should be notified of the new device. | 175 // Replug in the first device. Should be notified of the new device. |
176 SetKeyboardDevices(all_keyboards); | 176 SetKeyboardDevices(all_keyboards); |
177 EXPECT_TRUE(observer.change_notified()); | 177 EXPECT_TRUE(observer.change_notified()); |
178 devices = manager->keyboard_devices(); | 178 devices = manager->keyboard_devices(); |
179 // Both devices now present. | 179 // Both devices now present. |
180 EXPECT_EQ(2u, devices.size()); | 180 EXPECT_EQ(2u, devices.size()); |
181 } | 181 } |
182 | 182 |
183 } // namespace test | 183 } // namespace test |
184 } // namespace ui | 184 } // namespace ui |
OLD | NEW |