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