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