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_.reset(new ui::MockTouchEventConverterEvdev( | 163 device_.reset(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 device_.reset(); | 171 device_.reset(); |
181 delete loop_; | 172 delete loop_; |
182 } | 173 } |
183 | 174 |
184 ui::MockTouchEventConverterEvdev* device() { return device_.get(); } | 175 ui::MockTouchEventConverterEvdev* device() { return device_.get(); } |
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 void DestroyDevice() { device_.reset(); } | 187 void DestroyDevice() { device_.reset(); } |
195 | 188 |
196 private: | 189 private: |
197 base::MessageLoop* loop_; | 190 base::MessageLoop* loop_; |
198 scoped_ptr<ui::MockTouchEventConverterEvdev> device_; | 191 scoped_ptr<ui::MockTouchEventConverterEvdev> device_; |
199 scoped_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; | 192 scoped_ptr<ui::MockDeviceEventDispatcherEvdev> dispatcher_; |
200 | 193 |
201 int events_out_; | 194 int events_out_; |
202 int events_in_; | 195 int events_in_; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 ASSERT_EQ(0u, size()); | 762 ASSERT_EQ(0u, size()); |
770 | 763 |
771 EventTypeTouchNoiseFilter* filter = | 764 EventTypeTouchNoiseFilter* filter = |
772 static_cast<EventTypeTouchNoiseFilter*>(first_filter()); | 765 static_cast<EventTypeTouchNoiseFilter*>(first_filter()); |
773 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_PRESSED)); | 766 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_PRESSED)); |
774 EXPECT_EQ(2u, filter->num_events(ET_TOUCH_MOVED)); | 767 EXPECT_EQ(2u, filter->num_events(ET_TOUCH_MOVED)); |
775 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_RELEASED)); | 768 EXPECT_EQ(1u, filter->num_events(ET_TOUCH_RELEASED)); |
776 } | 769 } |
777 | 770 |
778 } // namespace ui | 771 } // namespace ui |
OLD | NEW |