| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <linux/input.h> | 7 #include <linux/input.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 EXPECT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &devinfo)); | 46 EXPECT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &devinfo)); |
| 47 device->Initialize(devinfo); | 47 device->Initialize(devinfo); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { | 52 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { |
| 53 public: | 53 public: |
| 54 MockTouchEventConverterEvdev(int fd, | 54 MockTouchEventConverterEvdev(int fd, |
| 55 base::FilePath path, | 55 base::FilePath path, |
| 56 const EventDeviceInfo& devinfo, | |
| 57 DeviceEventDispatcherEvdev* dispatcher); | 56 DeviceEventDispatcherEvdev* dispatcher); |
| 58 ~MockTouchEventConverterEvdev() override {} | 57 ~MockTouchEventConverterEvdev() override {} |
| 59 | 58 |
| 60 void ConfigureReadMock(struct input_event* queue, | 59 void ConfigureReadMock(struct input_event* queue, |
| 61 long read_this_many, | 60 long read_this_many, |
| 62 long queue_index); | 61 long queue_index); |
| 63 | 62 |
| 64 // Actually dispatch the event reader code. | 63 // Actually dispatch the event reader code. |
| 65 void ReadNow() { | 64 void ReadNow() { |
| 66 OnFileCanReadWithoutBlocking(read_pipe_); | 65 OnFileCanReadWithoutBlocking(read_pipe_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void DispatchTouchpadDevicesUpdated( | 104 void DispatchTouchpadDevicesUpdated( |
| 106 const std::vector<InputDevice>& devices) override {} | 105 const std::vector<InputDevice>& devices) override {} |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 base::Callback<void(const TouchEventParams& params)> callback_; | 108 base::Callback<void(const TouchEventParams& params)> callback_; |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev( | 111 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev( |
| 113 int fd, | 112 int fd, |
| 114 base::FilePath path, | 113 base::FilePath path, |
| 115 const EventDeviceInfo& devinfo, | |
| 116 DeviceEventDispatcherEvdev* dispatcher) | 114 DeviceEventDispatcherEvdev* dispatcher) |
| 117 : TouchEventConverterEvdev(fd, | 115 : TouchEventConverterEvdev(fd, path, 1, INPUT_DEVICE_UNKNOWN, dispatcher) { |
| 118 path, | |
| 119 1, | |
| 120 INPUT_DEVICE_UNKNOWN, | |
| 121 devinfo, | |
| 122 dispatcher) { | |
| 123 int fds[2]; | 116 int fds[2]; |
| 124 | 117 |
| 125 if (pipe(fds)) | 118 if (pipe(fds)) |
| 126 PLOG(FATAL) << "failed pipe"; | 119 PLOG(FATAL) << "failed pipe"; |
| 127 | 120 |
| 128 EXPECT_FALSE(SetNonBlocking(fds[0]) || SetNonBlocking(fds[1])) | 121 EXPECT_FALSE(SetNonBlocking(fds[0]) || SetNonBlocking(fds[1])) |
| 129 << "failed to set non-blocking: " << strerror(errno); | 122 << "failed to set non-blocking: " << strerror(errno); |
| 130 | 123 |
| 131 read_pipe_ = fds[0]; | 124 read_pipe_ = fds[0]; |
| 132 write_pipe_ = fds[1]; | 125 write_pipe_ = fds[1]; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 157 // Set up pipe to satisfy message pump (unused). | 150 // Set up pipe to satisfy message pump (unused). |
| 158 int evdev_io[2]; | 151 int evdev_io[2]; |
| 159 if (pipe(evdev_io)) | 152 if (pipe(evdev_io)) |
| 160 PLOG(FATAL) << "failed pipe"; | 153 PLOG(FATAL) << "failed pipe"; |
| 161 events_in_ = evdev_io[0]; | 154 events_in_ = evdev_io[0]; |
| 162 events_out_ = evdev_io[1]; | 155 events_out_ = evdev_io[1]; |
| 163 | 156 |
| 164 // Device creation happens on a worker thread since it may involve blocking | 157 // Device creation happens on a worker thread since it may involve blocking |
| 165 // operations. Simulate that by creating it before creating a UI message | 158 // operations. Simulate that by creating it before creating a UI message |
| 166 // loop. | 159 // loop. |
| 167 EventDeviceInfo devinfo; | |
| 168 dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev( | 160 dispatcher_.reset(new ui::MockDeviceEventDispatcherEvdev( |
| 169 base::Bind(&TouchEventConverterEvdevTest::DispatchCallback, | 161 base::Bind(&TouchEventConverterEvdevTest::DispatchCallback, |
| 170 base::Unretained(this)))); | 162 base::Unretained(this)))); |
| 171 device_ = new ui::MockTouchEventConverterEvdev( | 163 device_ = new ui::MockTouchEventConverterEvdev( |
| 172 events_in_, base::FilePath(kTestDevicePath), devinfo, | 164 events_in_, base::FilePath(kTestDevicePath), dispatcher_.get()); |
| 173 dispatcher_.get()); | |
| 174 loop_ = new base::MessageLoopForUI; | 165 loop_ = new base::MessageLoopForUI; |
| 175 | 166 |
| 176 ui::DeviceDataManager::CreateInstance(); | 167 ui::DeviceDataManager::CreateInstance(); |
| 177 } | 168 } |
| 178 | 169 |
| 179 void TearDown() override { | 170 void TearDown() override { |
| 180 delete device_; | 171 delete device_; |
| 181 delete loop_; | 172 delete loop_; |
| 182 } | 173 } |
| 183 | 174 |
| 184 ui::MockTouchEventConverterEvdev* device() { return device_; } | 175 ui::MockTouchEventConverterEvdev* device() { return device_; } |
| 185 | 176 |
| 186 unsigned size() { return dispatched_events_.size(); } | 177 unsigned size() { return dispatched_events_.size(); } |
| 187 const ui::TouchEventParams& dispatched_event(unsigned index) { | 178 const ui::TouchEventParams& dispatched_event(unsigned index) { |
| 188 DCHECK_GT(dispatched_events_.size(), index); | 179 DCHECK_GT(dispatched_events_.size(), index); |
| 189 return dispatched_events_[index]; | 180 return dispatched_events_[index]; |
| 190 } | 181 } |
| 191 | 182 |
| 192 void ClearDispatchedEvents() { dispatched_events_.clear(); } | 183 void ClearDispatchedEvents() { |
| 184 dispatched_events_.clear(); |
| 185 } |
| 193 | 186 |
| 194 private: | 187 private: |
| 195 base::MessageLoop* loop_; | 188 base::MessageLoop* loop_; |
| 196 ui::MockTouchEventConverterEvdev* device_; | 189 ui::MockTouchEventConverterEvdev* device_; |
| 197 scoped_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; | 190 scoped_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; |
| 198 | 191 |
| 199 int events_out_; | 192 int events_out_; |
| 200 int events_in_; | 193 int events_in_; |
| 201 | 194 |
| 202 void DispatchCallback(const ui::TouchEventParams& params) { | 195 void DispatchCallback(const ui::TouchEventParams& params) { |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 ASSERT_EQ(0u, size()); | 722 ASSERT_EQ(0u, size()); |
| 730 | 723 |
| 731 EventTypeTouchNoiseFilter* filter = | 724 EventTypeTouchNoiseFilter* filter = |
| 732 static_cast<EventTypeTouchNoiseFilter*>(first_filter()); | 725 static_cast<EventTypeTouchNoiseFilter*>(first_filter()); |
| 733 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_PRESSED)); | 726 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_PRESSED)); |
| 734 EXPECT_EQ(2u, filter->num_events(ET_TOUCH_MOVED)); | 727 EXPECT_EQ(2u, filter->num_events(ET_TOUCH_MOVED)); |
| 735 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_RELEASED)); | 728 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_RELEASED)); |
| 736 } | 729 } |
| 737 | 730 |
| 738 } // namespace ui | 731 } // namespace ui |
| OLD | NEW |