Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc

Issue 2639043002: Fix double-close in EventConverterEvdevImpl (Closed)
Patch Set: remove base::debug::Alias Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/tablet_event_converter_evdev.h" 5 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 kWacomIntuos5SPenAbsAxes, 71 kWacomIntuos5SPenAbsAxes,
72 arraysize(kWacomIntuos5SPenAbsAxes), 72 arraysize(kWacomIntuos5SPenAbsAxes),
73 }; 73 };
74 74
75 } // namespace 75 } // namespace
76 76
77 namespace ui { 77 namespace ui {
78 78
79 class MockTabletEventConverterEvdev : public TabletEventConverterEvdev { 79 class MockTabletEventConverterEvdev : public TabletEventConverterEvdev {
80 public: 80 public:
81 MockTabletEventConverterEvdev(int fd, 81 MockTabletEventConverterEvdev(ScopedInputDevice fd,
82 base::FilePath path, 82 base::FilePath path,
83 CursorDelegateEvdev* cursor, 83 CursorDelegateEvdev* cursor,
84 const EventDeviceInfo& devinfo, 84 const EventDeviceInfo& devinfo,
85 DeviceEventDispatcherEvdev* dispatcher); 85 DeviceEventDispatcherEvdev* dispatcher);
86 ~MockTabletEventConverterEvdev() override {}; 86 ~MockTabletEventConverterEvdev() override {};
87 87
88 void ConfigureReadMock(struct input_event* queue, 88 void ConfigureReadMock(struct input_event* queue,
89 long read_this_many, 89 long read_this_many,
90 long queue_index); 90 long queue_index);
91 91
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return cursor_confined_bounds_; 124 return cursor_confined_bounds_;
125 } 125 }
126 void InitializeOnEvdev() override {} 126 void InitializeOnEvdev() override {}
127 private: 127 private:
128 gfx::PointF cursor_location_; 128 gfx::PointF cursor_location_;
129 gfx::Rect cursor_confined_bounds_; 129 gfx::Rect cursor_confined_bounds_;
130 DISALLOW_COPY_AND_ASSIGN(MockTabletCursorEvdev); 130 DISALLOW_COPY_AND_ASSIGN(MockTabletCursorEvdev);
131 }; 131 };
132 132
133 MockTabletEventConverterEvdev::MockTabletEventConverterEvdev( 133 MockTabletEventConverterEvdev::MockTabletEventConverterEvdev(
134 int fd, 134 ScopedInputDevice fd,
135 base::FilePath path, 135 base::FilePath path,
136 CursorDelegateEvdev* cursor, 136 CursorDelegateEvdev* cursor,
137 const EventDeviceInfo& devinfo, 137 const EventDeviceInfo& devinfo,
138 DeviceEventDispatcherEvdev* dispatcher) 138 DeviceEventDispatcherEvdev* dispatcher)
139 : TabletEventConverterEvdev(fd, 139 : TabletEventConverterEvdev(std::move(fd),
140 path, 140 path,
141 1, 141 1,
142 cursor, 142 cursor,
143 devinfo, 143 devinfo,
144 dispatcher) { 144 dispatcher) {
145 int fds[2]; 145 int fds[2];
146 146
147 if (pipe(fds)) 147 if (pipe(fds))
148 PLOG(FATAL) << "failed pipe"; 148 PLOG(FATAL) << "failed pipe";
149 149
(...skipping 16 matching lines...) Expand all
166 166
167 } // namespace ui 167 } // namespace ui
168 168
169 // Test fixture. 169 // Test fixture.
170 class TabletEventConverterEvdevTest : public testing::Test { 170 class TabletEventConverterEvdevTest : public testing::Test {
171 public: 171 public:
172 TabletEventConverterEvdevTest() {} 172 TabletEventConverterEvdevTest() {}
173 173
174 // Overridden from testing::Test: 174 // Overridden from testing::Test:
175 void SetUp() override { 175 void SetUp() override {
176 // Set up pipe to satisfy message pump (unused).
177 int evdev_io[2];
178 if (pipe(evdev_io))
179 PLOG(FATAL) << "failed pipe";
180 events_in_ = evdev_io[0];
181 events_out_ = evdev_io[1];
182
183 cursor_.reset(new ui::MockTabletCursorEvdev()); 176 cursor_.reset(new ui::MockTabletCursorEvdev());
184 device_manager_ = ui::CreateDeviceManagerForTest(); 177 device_manager_ = ui::CreateDeviceManagerForTest();
185 event_factory_ = ui::CreateEventFactoryEvdevForTest( 178 event_factory_ = ui::CreateEventFactoryEvdevForTest(
186 cursor_.get(), device_manager_.get(), 179 cursor_.get(), device_manager_.get(),
187 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), 180 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
188 base::Bind(&TabletEventConverterEvdevTest::DispatchEventForTest, 181 base::Bind(&TabletEventConverterEvdevTest::DispatchEventForTest,
189 base::Unretained(this))); 182 base::Unretained(this)));
190 dispatcher_ = 183 dispatcher_ =
191 ui::CreateDeviceEventDispatcherEvdevForTest(event_factory_.get()); 184 ui::CreateDeviceEventDispatcherEvdevForTest(event_factory_.get());
192 } 185 }
193 186
194 void TearDown() override { 187 void TearDown() override {
195 cursor_.reset(); 188 cursor_.reset();
196 } 189 }
197 190
198 ui::MockTabletEventConverterEvdev* CreateDevice( 191 ui::MockTabletEventConverterEvdev* CreateDevice(
199 const ui::DeviceCapabilities& caps) { 192 const ui::DeviceCapabilities& caps) {
193 // Set up pipe to satisfy message pump (unused).
194 int evdev_io[2];
195 if (pipe(evdev_io))
196 PLOG(FATAL) << "failed pipe";
197 ui::ScopedInputDevice events_in(evdev_io[0]);
198 events_out_.reset(evdev_io[1]);
199
200 ui::EventDeviceInfo devinfo; 200 ui::EventDeviceInfo devinfo;
201 CapabilitiesToDeviceInfo(caps, &devinfo); 201 CapabilitiesToDeviceInfo(caps, &devinfo);
202 return new ui::MockTabletEventConverterEvdev( 202 return new ui::MockTabletEventConverterEvdev(
203 events_in_, base::FilePath(kTestDevicePath), cursor_.get(), devinfo, 203 std::move(events_in), base::FilePath(kTestDevicePath), cursor_.get(),
204 dispatcher_.get()); 204 devinfo, dispatcher_.get());
205 } 205 }
206 206
207 ui::CursorDelegateEvdev* cursor() { return cursor_.get(); } 207 ui::CursorDelegateEvdev* cursor() { return cursor_.get(); }
208 208
209 unsigned size() { return dispatched_events_.size(); } 209 unsigned size() { return dispatched_events_.size(); }
210 ui::MouseEvent* dispatched_event(unsigned index) { 210 ui::MouseEvent* dispatched_event(unsigned index) {
211 DCHECK_GT(dispatched_events_.size(), index); 211 DCHECK_GT(dispatched_events_.size(), index);
212 ui::Event* ev = dispatched_events_[index].get(); 212 ui::Event* ev = dispatched_events_[index].get();
213 DCHECK(ev->IsMouseEvent()); 213 DCHECK(ev->IsMouseEvent());
214 return ev->AsMouseEvent(); 214 return ev->AsMouseEvent();
215 } 215 }
216 216
217 void DispatchEventForTest(ui::Event* event) { 217 void DispatchEventForTest(ui::Event* event) {
218 std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(*event); 218 std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(*event);
219 dispatched_events_.push_back(std::move(cloned_event)); 219 dispatched_events_.push_back(std::move(cloned_event));
220 } 220 }
221 221
222 private: 222 private:
223 std::unique_ptr<ui::MockTabletCursorEvdev> cursor_; 223 std::unique_ptr<ui::MockTabletCursorEvdev> cursor_;
224 std::unique_ptr<ui::DeviceManager> device_manager_; 224 std::unique_ptr<ui::DeviceManager> device_manager_;
225 std::unique_ptr<ui::EventFactoryEvdev> event_factory_; 225 std::unique_ptr<ui::EventFactoryEvdev> event_factory_;
226 std::unique_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_; 226 std::unique_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_;
227 227
228 std::vector<std::unique_ptr<ui::Event>> dispatched_events_; 228 std::vector<std::unique_ptr<ui::Event>> dispatched_events_;
229 229
230 int events_out_; 230 ui::ScopedInputDevice events_out_;
231 int events_in_;
232 231
233 DISALLOW_COPY_AND_ASSIGN(TabletEventConverterEvdevTest); 232 DISALLOW_COPY_AND_ASSIGN(TabletEventConverterEvdevTest);
234 }; 233 };
235 234
236 #define EPSILON 20 235 #define EPSILON 20
237 236
238 // Uses real data captured from Wacom Intuos 5 Pen 237 // Uses real data captured from Wacom Intuos 5 Pen
239 TEST_F(TabletEventConverterEvdevTest, MoveTopLeft) { 238 TEST_F(TabletEventConverterEvdevTest, MoveTopLeft) {
240 std::unique_ptr<ui::MockTabletEventConverterEvdev> dev = 239 std::unique_ptr<ui::MockTabletEventConverterEvdev> dev =
241 base::WrapUnique(CreateDevice(kWacomIntuos5SPen)); 240 base::WrapUnique(CreateDevice(kWacomIntuos5SPen));
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 495
497 struct input_event mock_kernel_queue[] = { 496 struct input_event mock_kernel_queue[] = {
498 {{0, 0}, EV_ABS, ABS_X, 0}, 497 {{0, 0}, EV_ABS, ABS_X, 0},
499 {{0, 0}, EV_ABS, ABS_Y, 0}, 498 {{0, 0}, EV_ABS, ABS_Y, 0},
500 {{0, 0}, EV_SYN, SYN_REPORT, 0}, 499 {{0, 0}, EV_SYN, SYN_REPORT, 0},
501 }; 500 };
502 501
503 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); 502 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
504 EXPECT_EQ(0u, size()); 503 EXPECT_EQ(0u, size());
505 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698