| 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/ozone/evdev/touch_event_converter_evdev.h" | 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 MouseMoveEventParams mouse_move; | 73 MouseMoveEventParams mouse_move; |
| 74 MouseButtonEventParams mouse_button; | 74 MouseButtonEventParams mouse_button; |
| 75 TouchEventParams touch; | 75 TouchEventParams touch; |
| 76 }; | 76 }; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { | 81 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { |
| 82 public: | 82 public: |
| 83 MockTouchEventConverterEvdev(int fd, | 83 MockTouchEventConverterEvdev(ScopedInputDevice fd, |
| 84 base::FilePath path, | 84 base::FilePath path, |
| 85 const EventDeviceInfo& devinfo, | 85 const EventDeviceInfo& devinfo, |
| 86 DeviceEventDispatcherEvdev* dispatcher); | 86 DeviceEventDispatcherEvdev* dispatcher); |
| 87 ~MockTouchEventConverterEvdev() override; | 87 ~MockTouchEventConverterEvdev() override; |
| 88 | 88 |
| 89 void ConfigureReadMock(struct input_event* queue, | 89 void ConfigureReadMock(struct input_event* queue, |
| 90 long read_this_many, | 90 long read_this_many, |
| 91 long queue_index); | 91 long queue_index); |
| 92 | 92 |
| 93 // Actually dispatch the event reader code. | 93 // Actually dispatch the event reader code. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void DispatchTouchpadDevicesUpdated( | 151 void DispatchTouchpadDevicesUpdated( |
| 152 const std::vector<InputDevice>& devices) override {} | 152 const std::vector<InputDevice>& devices) override {} |
| 153 void DispatchDeviceListsComplete() override {} | 153 void DispatchDeviceListsComplete() override {} |
| 154 void DispatchStylusStateChanged(StylusState stylus_state) override {} | 154 void DispatchStylusStateChanged(StylusState stylus_state) override {} |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 base::Callback<void(const GenericEventParams& params)> callback_; | 157 base::Callback<void(const GenericEventParams& params)> callback_; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev( | 160 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev( |
| 161 int fd, | 161 ScopedInputDevice fd, |
| 162 base::FilePath path, | 162 base::FilePath path, |
| 163 const EventDeviceInfo& devinfo, | 163 const EventDeviceInfo& devinfo, |
| 164 DeviceEventDispatcherEvdev* dispatcher) | 164 DeviceEventDispatcherEvdev* dispatcher) |
| 165 : TouchEventConverterEvdev(fd, | 165 : TouchEventConverterEvdev(std::move(fd), path, 1, devinfo, dispatcher) { |
| 166 path, | |
| 167 1, | |
| 168 devinfo, | |
| 169 dispatcher) { | |
| 170 int fds[2]; | 166 int fds[2]; |
| 171 | 167 |
| 172 if (pipe(fds)) | 168 if (pipe(fds)) |
| 173 PLOG(FATAL) << "failed pipe"; | 169 PLOG(FATAL) << "failed pipe"; |
| 174 | 170 |
| 175 EXPECT_TRUE(base::SetNonBlocking(fds[0]) || base::SetNonBlocking(fds[1])) | 171 EXPECT_TRUE(base::SetNonBlocking(fds[0]) || base::SetNonBlocking(fds[1])) |
| 176 << "failed to set non-blocking: " << strerror(errno); | 172 << "failed to set non-blocking: " << strerror(errno); |
| 177 | 173 |
| 178 read_pipe_ = fds[0]; | 174 read_pipe_ = fds[0]; |
| 179 write_pipe_ = fds[1]; | 175 write_pipe_ = fds[1]; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 204 class TouchEventConverterEvdevTest : public testing::Test { | 200 class TouchEventConverterEvdevTest : public testing::Test { |
| 205 public: | 201 public: |
| 206 TouchEventConverterEvdevTest() {} | 202 TouchEventConverterEvdevTest() {} |
| 207 | 203 |
| 208 // Overridden from testing::Test: | 204 // Overridden from testing::Test: |
| 209 void SetUp() override { | 205 void SetUp() override { |
| 210 // Set up pipe to satisfy message pump (unused). | 206 // Set up pipe to satisfy message pump (unused). |
| 211 int evdev_io[2]; | 207 int evdev_io[2]; |
| 212 if (pipe(evdev_io)) | 208 if (pipe(evdev_io)) |
| 213 PLOG(FATAL) << "failed pipe"; | 209 PLOG(FATAL) << "failed pipe"; |
| 214 events_in_ = evdev_io[0]; | 210 ScopedInputDevice events_in(evdev_io[0]); |
| 215 events_out_ = evdev_io[1]; | 211 events_out_.reset(evdev_io[1]); |
| 216 | 212 |
| 217 // Device creation happens on a worker thread since it may involve blocking | 213 // Device creation happens on a worker thread since it may involve blocking |
| 218 // operations. Simulate that by creating it before creating a UI message | 214 // operations. Simulate that by creating it before creating a UI message |
| 219 // loop. | 215 // loop. |
| 220 EventDeviceInfo devinfo; | 216 EventDeviceInfo devinfo; |
| 221 dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev( | 217 dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev( |
| 222 base::Bind(&TouchEventConverterEvdevTest::DispatchCallback, | 218 base::Bind(&TouchEventConverterEvdevTest::DispatchCallback, |
| 223 base::Unretained(this)))); | 219 base::Unretained(this)))); |
| 224 device_.reset(new ui::MockTouchEventConverterEvdev( | 220 device_.reset(new ui::MockTouchEventConverterEvdev( |
| 225 events_in_, base::FilePath(kTestDevicePath), devinfo, | 221 std::move(events_in), base::FilePath(kTestDevicePath), devinfo, |
| 226 dispatcher_.get())); | 222 dispatcher_.get())); |
| 227 loop_ = new base::MessageLoopForUI; | 223 loop_ = new base::MessageLoopForUI; |
| 228 | 224 |
| 229 ui::DeviceDataManager::CreateInstance(); | 225 ui::DeviceDataManager::CreateInstance(); |
| 230 } | 226 } |
| 231 | 227 |
| 232 void TearDown() override { | 228 void TearDown() override { |
| 233 device_.reset(); | 229 device_.reset(); |
| 234 delete loop_; | 230 delete loop_; |
| 235 } | 231 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 257 } | 253 } |
| 258 void ClearDispatchedEvents() { dispatched_events_.clear(); } | 254 void ClearDispatchedEvents() { dispatched_events_.clear(); } |
| 259 | 255 |
| 260 void DestroyDevice() { device_.reset(); } | 256 void DestroyDevice() { device_.reset(); } |
| 261 | 257 |
| 262 private: | 258 private: |
| 263 base::MessageLoop* loop_; | 259 base::MessageLoop* loop_; |
| 264 std::unique_ptr<ui::MockTouchEventConverterEvdev> device_; | 260 std::unique_ptr<ui::MockTouchEventConverterEvdev> device_; |
| 265 std::unique_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; | 261 std::unique_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; |
| 266 | 262 |
| 267 int events_out_; | 263 ScopedInputDevice events_out_; |
| 268 int events_in_; | |
| 269 | 264 |
| 270 void DispatchCallback(const GenericEventParams& params) { | 265 void DispatchCallback(const GenericEventParams& params) { |
| 271 dispatched_events_.push_back(params); | 266 dispatched_events_.push_back(params); |
| 272 } | 267 } |
| 273 std::vector<GenericEventParams> dispatched_events_; | 268 std::vector<GenericEventParams> dispatched_events_; |
| 274 | 269 |
| 275 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdevTest); | 270 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdevTest); |
| 276 }; | 271 }; |
| 277 | 272 |
| 278 TEST_F(TouchEventConverterEvdevTest, NoEvents) { | 273 TEST_F(TouchEventConverterEvdevTest, NoEvents) { |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 event = dispatched_touch_event(3); | 1095 event = dispatched_touch_event(3); |
| 1101 EXPECT_EQ(ET_TOUCH_RELEASED, event.type); | 1096 EXPECT_EQ(ET_TOUCH_RELEASED, event.type); |
| 1102 EXPECT_EQ(8930, event.location.x()); | 1097 EXPECT_EQ(8930, event.location.x()); |
| 1103 EXPECT_EQ(980, event.location.y()); | 1098 EXPECT_EQ(980, event.location.y()); |
| 1104 EXPECT_EQ(EventPointerType::POINTER_TYPE_PEN, | 1099 EXPECT_EQ(EventPointerType::POINTER_TYPE_PEN, |
| 1105 event.pointer_details.pointer_type); | 1100 event.pointer_details.pointer_type); |
| 1106 EXPECT_EQ(0.f / 1024, event.pointer_details.force); | 1101 EXPECT_EQ(0.f / 1024, event.pointer_details.force); |
| 1107 } | 1102 } |
| 1108 | 1103 |
| 1109 } // namespace ui | 1104 } // namespace ui |
| OLD | NEW |