| 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 |
| 11 #undef None | 11 #undef None |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/events/devices/device_hotplug_event_observer.h" | 15 #include "ui/events/devices/device_hotplug_event_observer.h" |
| 16 #include "ui/events/devices/input_device.h" | 16 #include "ui/events/devices/input_device.h" |
| 17 #include "ui/events/devices/input_device_event_observer.h" | 17 #include "ui/events/devices/input_device_event_observer.h" |
| 18 #include "ui/events/devices/keyboard_device.h" | |
| 19 #include "ui/events/devices/touchscreen_device.h" | 18 #include "ui/events/devices/touchscreen_device.h" |
| 20 | 19 |
| 21 namespace ui { | 20 namespace ui { |
| 22 namespace test { | 21 namespace test { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class TestInputDeviceObserver : public InputDeviceEventObserver { | 24 class TestInputDeviceObserver : public InputDeviceEventObserver { |
| 26 public: | 25 public: |
| 27 explicit TestInputDeviceObserver(DeviceDataManagerX11* manager) | 26 explicit TestInputDeviceObserver(DeviceDataManagerX11* manager) |
| 28 : manager_(manager), change_notified_(false) { | 27 : manager_(manager), change_notified_(false) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 | 51 |
| 53 } // namespace | 52 } // namespace |
| 54 | 53 |
| 55 class DeviceDataManagerX11Test : public testing::Test { | 54 class DeviceDataManagerX11Test : public testing::Test { |
| 56 public: | 55 public: |
| 57 DeviceDataManagerX11Test() {} | 56 DeviceDataManagerX11Test() {} |
| 58 ~DeviceDataManagerX11Test() override {} | 57 ~DeviceDataManagerX11Test() override {} |
| 59 | 58 |
| 60 void SetUp() override { DeviceDataManagerX11::CreateInstance(); } | 59 void SetUp() override { DeviceDataManagerX11::CreateInstance(); } |
| 61 | 60 |
| 62 void TearDown() override { | 61 void TearDown() override { SetKeyboardDevices(std::vector<InputDevice>()); } |
| 63 SetKeyboardDevices(std::vector<KeyboardDevice>()); | |
| 64 } | |
| 65 | 62 |
| 66 virtual void SetKeyboardDevices(const std::vector<KeyboardDevice>& devices) { | 63 virtual void SetKeyboardDevices(const std::vector<InputDevice>& devices) { |
| 67 DeviceHotplugEventObserver* manager = DeviceDataManagerX11::GetInstance(); | 64 DeviceHotplugEventObserver* manager = DeviceDataManagerX11::GetInstance(); |
| 68 manager->OnKeyboardDevicesUpdated(devices); | 65 manager->OnKeyboardDevicesUpdated(devices); |
| 69 } | 66 } |
| 70 | 67 |
| 71 private: | 68 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test); | 69 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test); |
| 73 }; | 70 }; |
| 74 | 71 |
| 75 // Tests that the the device data manager notifies observers when a device is | 72 // Tests that the the device data manager notifies observers when a device is |
| 76 // disabled and re-enabled. | 73 // disabled and re-enabled. |
| 77 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) { | 74 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) { |
| 78 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 75 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
| 79 TestInputDeviceObserver observer(manager); | 76 TestInputDeviceObserver observer(manager); |
| 80 std::vector<ui::KeyboardDevice> keyboards; | 77 std::vector<ui::InputDevice> keyboards; |
| 81 keyboards.push_back(ui::KeyboardDevice( | 78 keyboards.push_back(ui::InputDevice( |
| 82 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 79 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 83 keyboards.push_back(ui::KeyboardDevice( | 80 keyboards.push_back(ui::InputDevice( |
| 84 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 81 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 85 SetKeyboardDevices(keyboards); | 82 SetKeyboardDevices(keyboards); |
| 86 EXPECT_TRUE(observer.change_notified()); | 83 EXPECT_TRUE(observer.change_notified()); |
| 87 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 84 std::vector<InputDevice> devices = manager->keyboard_devices(); |
| 88 EXPECT_EQ(keyboards.size(), devices.size()); | 85 EXPECT_EQ(keyboards.size(), devices.size()); |
| 89 observer.Reset(); | 86 observer.Reset(); |
| 90 // 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 |
| 91 // less device. | 88 // less device. |
| 92 manager->DisableDevice(2); | 89 manager->DisableDevice(2); |
| 93 EXPECT_TRUE(observer.change_notified()); | 90 EXPECT_TRUE(observer.change_notified()); |
| 94 devices = manager->keyboard_devices(); | 91 devices = manager->keyboard_devices(); |
| 95 EXPECT_EQ(1u, devices.size()); | 92 EXPECT_EQ(1u, devices.size()); |
| 96 KeyboardDevice device = devices.front(); | 93 InputDevice device = devices.front(); |
| 97 EXPECT_EQ(1, device.id); | 94 EXPECT_EQ(1, device.id); |
| 98 observer.Reset(); | 95 observer.Reset(); |
| 99 // 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 |
| 100 // more device. | 97 // more device. |
| 101 manager->EnableDevice(2); | 98 manager->EnableDevice(2); |
| 102 EXPECT_TRUE(observer.change_notified()); | 99 EXPECT_TRUE(observer.change_notified()); |
| 103 devices = manager->keyboard_devices(); | 100 devices = manager->keyboard_devices(); |
| 104 EXPECT_EQ(keyboards.size(), devices.size()); | 101 EXPECT_EQ(keyboards.size(), devices.size()); |
| 105 } | 102 } |
| 106 | 103 |
| 107 // Tests blocking multiple devices. | 104 // Tests blocking multiple devices. |
| 108 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) { | 105 TEST_F(DeviceDataManagerX11Test, TestMultipleDisable) { |
| 109 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 106 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
| 110 TestInputDeviceObserver observer(manager); | 107 TestInputDeviceObserver observer(manager); |
| 111 std::vector<ui::KeyboardDevice> keyboards; | 108 std::vector<ui::InputDevice> keyboards; |
| 112 keyboards.push_back(ui::KeyboardDevice( | 109 keyboards.push_back(ui::InputDevice( |
| 113 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 110 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 114 keyboards.push_back(ui::KeyboardDevice( | 111 keyboards.push_back(ui::InputDevice( |
| 115 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 112 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 116 SetKeyboardDevices(keyboards); | 113 SetKeyboardDevices(keyboards); |
| 117 EXPECT_TRUE(observer.change_notified()); | 114 EXPECT_TRUE(observer.change_notified()); |
| 118 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 115 std::vector<InputDevice> devices = manager->keyboard_devices(); |
| 119 EXPECT_EQ(keyboards.size(), devices.size()); | 116 EXPECT_EQ(keyboards.size(), devices.size()); |
| 120 observer.Reset(); | 117 observer.Reset(); |
| 121 // 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 |
| 122 // less device. | 119 // less device. |
| 123 manager->DisableDevice(1); | 120 manager->DisableDevice(1); |
| 124 EXPECT_TRUE(observer.change_notified()); | 121 EXPECT_TRUE(observer.change_notified()); |
| 125 devices = manager->keyboard_devices(); | 122 devices = manager->keyboard_devices(); |
| 126 EXPECT_EQ(1u, devices.size()); | 123 EXPECT_EQ(1u, devices.size()); |
| 127 observer.Reset(); | 124 observer.Reset(); |
| 128 // 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. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 // Enable the second device, should be notified that both devices present. | 137 // Enable the second device, should be notified that both devices present. |
| 141 manager->EnableDevice(2); | 138 manager->EnableDevice(2); |
| 142 EXPECT_TRUE(observer.change_notified()); | 139 EXPECT_TRUE(observer.change_notified()); |
| 143 devices = manager->keyboard_devices(); | 140 devices = manager->keyboard_devices(); |
| 144 EXPECT_EQ(2u, devices.size()); | 141 EXPECT_EQ(2u, devices.size()); |
| 145 } | 142 } |
| 146 | 143 |
| 147 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) { | 144 TEST_F(DeviceDataManagerX11Test, UnblockOnDeviceUnplugged) { |
| 148 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); | 145 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance(); |
| 149 TestInputDeviceObserver observer(manager); | 146 TestInputDeviceObserver observer(manager); |
| 150 std::vector<ui::KeyboardDevice> all_keyboards; | 147 std::vector<ui::InputDevice> all_keyboards; |
| 151 all_keyboards.push_back(ui::KeyboardDevice( | 148 all_keyboards.push_back(ui::InputDevice( |
| 152 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 149 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 153 all_keyboards.push_back(ui::KeyboardDevice( | 150 all_keyboards.push_back(ui::InputDevice( |
| 154 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 151 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 155 SetKeyboardDevices(all_keyboards); | 152 SetKeyboardDevices(all_keyboards); |
| 156 EXPECT_TRUE(observer.change_notified()); | 153 EXPECT_TRUE(observer.change_notified()); |
| 157 std::vector<KeyboardDevice> devices = manager->keyboard_devices(); | 154 std::vector<InputDevice> devices = manager->keyboard_devices(); |
| 158 EXPECT_EQ(all_keyboards.size(), devices.size()); | 155 EXPECT_EQ(all_keyboards.size(), devices.size()); |
| 159 observer.Reset(); | 156 observer.Reset(); |
| 160 // Expect to be notified that the device is no longer available. | 157 // Expect to be notified that the device is no longer available. |
| 161 manager->DisableDevice(2); | 158 manager->DisableDevice(2); |
| 162 EXPECT_TRUE(observer.change_notified()); | 159 EXPECT_TRUE(observer.change_notified()); |
| 163 devices = manager->keyboard_devices(); | 160 devices = manager->keyboard_devices(); |
| 164 EXPECT_EQ(1u, devices.size()); | 161 EXPECT_EQ(1u, devices.size()); |
| 165 observer.Reset(); | 162 observer.Reset(); |
| 166 // 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 |
| 167 // did not change. | 164 // did not change. |
| 168 std::vector<ui::KeyboardDevice> subset_keyboards; | 165 std::vector<ui::InputDevice> subset_keyboards; |
| 169 subset_keyboards.push_back(ui::KeyboardDevice( | 166 subset_keyboards.push_back(ui::InputDevice( |
| 170 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); | 167 1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard")); |
| 171 SetKeyboardDevices(subset_keyboards); | 168 SetKeyboardDevices(subset_keyboards); |
| 172 EXPECT_FALSE(observer.change_notified()); | 169 EXPECT_FALSE(observer.change_notified()); |
| 173 // 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. |
| 174 SetKeyboardDevices(all_keyboards); | 171 SetKeyboardDevices(all_keyboards); |
| 175 EXPECT_TRUE(observer.change_notified()); | 172 EXPECT_TRUE(observer.change_notified()); |
| 176 devices = manager->keyboard_devices(); | 173 devices = manager->keyboard_devices(); |
| 177 // Both devices now present. | 174 // Both devices now present. |
| 178 EXPECT_EQ(2u, devices.size()); | 175 EXPECT_EQ(2u, devices.size()); |
| 179 } | 176 } |
| 180 | 177 |
| 181 } // namespace test | 178 } // namespace test |
| 182 } // namespace ui | 179 } // namespace ui |
| OLD | NEW |