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
3 // found in the LICENSE file.
7 #include <linux/input.h>
12 #include "base/bind.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/posix/eintr_wrapper.h"
16 #include "base/run_loop.h"
17 #include "base/time/time.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/events/devices/device_data_manager.h"
20 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
22 #include "ui/events/platform/platform_event_dispatcher.h"
23 #include "ui/events/platform/platform_event_source.h"
27 static int SetNonBlocking(int fd
) {
28 int flags
= fcntl(fd
, F_GETFL
, 0);
31 return fcntl(fd
, F_SETFL
, flags
| O_NONBLOCK
);
34 const char kTestDevicePath
[] = "/dev/input/test-device";
40 class MockTouchEventConverterEvdev
: public TouchEventConverterEvdev
{
42 MockTouchEventConverterEvdev(int fd
,
44 DeviceEventDispatcherEvdev
* dispatcher
);
45 ~MockTouchEventConverterEvdev() override
{}
47 void ConfigureReadMock(struct input_event
* queue
,
51 // Actually dispatch the event reader code.
53 OnFileCanReadWithoutBlocking(read_pipe_
);
54 base::RunLoop().RunUntilIdle();
57 void Initialize(const EventDeviceInfo
& device_info
) override
{}
58 bool Reinitialize() override
{ return true; }
64 DISALLOW_COPY_AND_ASSIGN(MockTouchEventConverterEvdev
);
67 class MockDeviceEventDispatcherEvdev
: public DeviceEventDispatcherEvdev
{
69 MockDeviceEventDispatcherEvdev(
70 const base::Callback
<void(const TouchEventParams
& params
)>& callback
)
71 : callback_(callback
) {}
72 ~MockDeviceEventDispatcherEvdev() override
{}
74 // DeviceEventDispatcherEvdev:
75 void DispatchKeyEvent(const KeyEventParams
& params
) override
{}
76 void DispatchMouseMoveEvent(const MouseMoveEventParams
& params
) override
{}
77 void DispatchMouseButtonEvent(const MouseButtonEventParams
& params
) override
{
79 void DispatchMouseWheelEvent(const MouseWheelEventParams
& params
) override
{}
80 void DispatchScrollEvent(const ScrollEventParams
& params
) override
{}
81 void DispatchTouchEvent(const TouchEventParams
& params
) override
{
82 callback_
.Run(params
);
85 void DispatchKeyboardDevicesUpdated(
86 const std::vector
<KeyboardDevice
>& devices
) override
{}
87 void DispatchTouchscreenDevicesUpdated(
88 const std::vector
<TouchscreenDevice
>& devices
) override
{}
89 void DispatchMouseDevicesUpdated(
90 const std::vector
<InputDevice
>& devices
) override
{}
91 void DispatchTouchpadDevicesUpdated(
92 const std::vector
<InputDevice
>& devices
) override
{}
95 base::Callback
<void(const TouchEventParams
& params
)> callback_
;
98 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(
101 DeviceEventDispatcherEvdev
* dispatcher
)
102 : TouchEventConverterEvdev(fd
, path
, 1, INPUT_DEVICE_UNKNOWN
, dispatcher
) {
106 // TODO(rjkroege): Check test axes.
108 x_num_tuxels_
= std::numeric_limits
<int>::max();
110 y_num_tuxels_
= std::numeric_limits
<int>::max();
115 PLOG(FATAL
) << "failed pipe";
117 DCHECK(SetNonBlocking(fds
[0]) == 0)
118 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno
;
119 DCHECK(SetNonBlocking(fds
[1]) == 0)
120 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno
;
122 write_pipe_
= fds
[1];
124 events_
.resize(MAX_FINGERS
);
127 void MockTouchEventConverterEvdev::ConfigureReadMock(struct input_event
* queue
,
130 int nwrite
= HANDLE_EINTR(write(write_pipe_
,
132 sizeof(struct input_event
) * read_this_many
));
134 static_cast<int>(sizeof(struct input_event
) * read_this_many
))
135 << "write() failed, errno: " << errno
;
141 class TouchEventConverterEvdevTest
: public testing::Test
{
143 TouchEventConverterEvdevTest() {}
145 // Overridden from testing::Test:
146 void SetUp() override
{
147 // Set up pipe to satisfy message pump (unused).
150 PLOG(FATAL
) << "failed pipe";
151 events_in_
= evdev_io
[0];
152 events_out_
= evdev_io
[1];
154 // Device creation happens on a worker thread since it may involve blocking
155 // operations. Simulate that by creating it before creating a UI message
157 dispatcher_
.reset(new ui::MockDeviceEventDispatcherEvdev(
158 base::Bind(&TouchEventConverterEvdevTest::DispatchCallback
,
159 base::Unretained(this))));
160 device_
= new ui::MockTouchEventConverterEvdev(
161 events_in_
, base::FilePath(kTestDevicePath
), dispatcher_
.get());
162 loop_
= new base::MessageLoopForUI
;
164 ui::DeviceDataManager::CreateInstance();
167 void TearDown() override
{
172 ui::MockTouchEventConverterEvdev
* device() { return device_
; }
174 unsigned size() { return dispatched_events_
.size(); }
175 const ui::TouchEventParams
& dispatched_event(unsigned index
) {
176 DCHECK_GT(dispatched_events_
.size(), index
);
177 return dispatched_events_
[index
];
181 base::MessageLoop
* loop_
;
182 ui::MockTouchEventConverterEvdev
* device_
;
183 scoped_ptr
<ui::MockDeviceEventDispatcherEvdev
> dispatcher_
;
188 void DispatchCallback(const ui::TouchEventParams
& params
) {
189 dispatched_events_
.push_back(params
);
191 std::vector
<ui::TouchEventParams
> dispatched_events_
;
193 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdevTest
);
196 // TODO(rjkroege): Test for valid handling of time stamps.
197 TEST_F(TouchEventConverterEvdevTest
, TouchDown
) {
198 ui::MockTouchEventConverterEvdev
* dev
= device();
200 struct input_event mock_kernel_queue
[] = {
201 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 684},
202 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
203 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
204 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
205 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
208 dev
->ConfigureReadMock(mock_kernel_queue
, 1, 0);
210 EXPECT_EQ(0u, size());
212 dev
->ConfigureReadMock(mock_kernel_queue
, 2, 1);
214 EXPECT_EQ(0u, size());
216 dev
->ConfigureReadMock(mock_kernel_queue
, 3, 3);
218 EXPECT_EQ(1u, size());
220 ui::TouchEventParams event
= dispatched_event(0);
222 EXPECT_EQ(ui::ET_TOUCH_PRESSED
, event
.type
);
223 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), event
.timestamp
);
224 EXPECT_EQ(42, event
.location
.x());
225 EXPECT_EQ(51, event
.location
.y());
226 EXPECT_EQ(0, event
.touch_id
);
227 EXPECT_FLOAT_EQ(1.5f
, event
.radii
.x());
228 EXPECT_FLOAT_EQ(.5f
, event
.pressure
);
231 TEST_F(TouchEventConverterEvdevTest
, NoEvents
) {
232 ui::MockTouchEventConverterEvdev
* dev
= device();
233 dev
->ConfigureReadMock(NULL
, 0, 0);
234 EXPECT_EQ(0u, size());
237 TEST_F(TouchEventConverterEvdevTest
, TouchMove
) {
238 ui::MockTouchEventConverterEvdev
* dev
= device();
240 struct input_event mock_kernel_queue_press
[] = {
241 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 684},
242 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
243 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
244 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
245 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
248 struct input_event mock_kernel_queue_move1
[] = {
249 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 50},
250 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
251 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 43}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
254 struct input_event mock_kernel_queue_move2
[] = {
255 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 42}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
258 // Setup and discard a press.
259 dev
->ConfigureReadMock(mock_kernel_queue_press
, 6, 0);
261 EXPECT_EQ(1u, size());
263 dev
->ConfigureReadMock(mock_kernel_queue_move1
, 4, 0);
265 EXPECT_EQ(2u, size());
266 ui::TouchEventParams event
= dispatched_event(1);
268 EXPECT_EQ(ui::ET_TOUCH_MOVED
, event
.type
);
269 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), event
.timestamp
);
270 EXPECT_EQ(42, event
.location
.x());
271 EXPECT_EQ(43, event
.location
.y());
272 EXPECT_EQ(0, event
.touch_id
);
273 EXPECT_FLOAT_EQ(2.f
/ 3.f
, event
.pressure
);
275 dev
->ConfigureReadMock(mock_kernel_queue_move2
, 2, 0);
277 EXPECT_EQ(3u, size());
278 event
= dispatched_event(2);
280 EXPECT_EQ(ui::ET_TOUCH_MOVED
, event
.type
);
281 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), event
.timestamp
);
282 EXPECT_EQ(42, event
.location
.x());
283 EXPECT_EQ(42, event
.location
.y());
284 EXPECT_EQ(0, event
.touch_id
);
285 EXPECT_FLOAT_EQ(2.f
/ 3.f
, event
.pressure
);
288 TEST_F(TouchEventConverterEvdevTest
, TouchRelease
) {
289 ui::MockTouchEventConverterEvdev
* dev
= device();
291 struct input_event mock_kernel_queue_press
[] = {
292 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 684},
293 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
294 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
295 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
296 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
299 struct input_event mock_kernel_queue_release
[] = {
300 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, -1}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
303 // Setup and discard a press.
304 dev
->ConfigureReadMock(mock_kernel_queue_press
, 6, 0);
306 EXPECT_EQ(1u, size());
307 ui::TouchEventParams event
= dispatched_event(0);
309 dev
->ConfigureReadMock(mock_kernel_queue_release
, 2, 0);
311 EXPECT_EQ(2u, size());
312 event
= dispatched_event(1);
314 EXPECT_EQ(ui::ET_TOUCH_RELEASED
, event
.type
);
315 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), event
.timestamp
);
316 EXPECT_EQ(42, event
.location
.x());
317 EXPECT_EQ(51, event
.location
.y());
318 EXPECT_EQ(0, event
.touch_id
);
319 EXPECT_FLOAT_EQ(.5f
, event
.pressure
);
322 TEST_F(TouchEventConverterEvdevTest
, TwoFingerGesture
) {
323 ui::MockTouchEventConverterEvdev
* dev
= device();
325 struct input_event mock_kernel_queue_press0
[] = {
326 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 684},
327 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
328 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
329 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
330 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
332 // Setup and discard a press.
333 dev
->ConfigureReadMock(mock_kernel_queue_press0
, 6, 0);
335 EXPECT_EQ(1u, size());
337 struct input_event mock_kernel_queue_move0
[] = {
338 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 40}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
340 // Setup and discard a move.
341 dev
->ConfigureReadMock(mock_kernel_queue_move0
, 2, 0);
343 EXPECT_EQ(2u, size());
345 struct input_event mock_kernel_queue_move0press1
[] = {
346 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 40}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0},
347 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 1}, {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 686},
348 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
349 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
350 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 101},
351 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 102}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
353 // Move on 0, press on 1.
354 dev
->ConfigureReadMock(mock_kernel_queue_move0press1
, 9, 0);
356 EXPECT_EQ(4u, size());
357 ui::TouchEventParams ev0
= dispatched_event(2);
358 ui::TouchEventParams ev1
= dispatched_event(3);
361 EXPECT_EQ(ui::ET_TOUCH_MOVED
, ev0
.type
);
362 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0
.timestamp
);
363 EXPECT_EQ(40, ev0
.location
.x());
364 EXPECT_EQ(51, ev0
.location
.y());
365 EXPECT_EQ(0, ev0
.touch_id
);
366 EXPECT_FLOAT_EQ(.5f
, ev0
.pressure
);
369 EXPECT_EQ(ui::ET_TOUCH_PRESSED
, ev1
.type
);
370 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1
.timestamp
);
371 EXPECT_EQ(101, ev1
.location
.x());
372 EXPECT_EQ(102, ev1
.location
.y());
373 EXPECT_EQ(1, ev1
.touch_id
);
374 EXPECT_FLOAT_EQ(.5f
, ev1
.pressure
);
376 // Stationary 0, Moves 1.
377 struct input_event mock_kernel_queue_stationary0_move1
[] = {
378 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 40}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
380 dev
->ConfigureReadMock(mock_kernel_queue_stationary0_move1
, 2, 0);
382 EXPECT_EQ(5u, size());
383 ev1
= dispatched_event(4);
385 EXPECT_EQ(ui::ET_TOUCH_MOVED
, ev1
.type
);
386 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1
.timestamp
);
387 EXPECT_EQ(40, ev1
.location
.x());
388 EXPECT_EQ(102, ev1
.location
.y());
389 EXPECT_EQ(1, ev1
.touch_id
);
391 EXPECT_FLOAT_EQ(.5f
, ev1
.pressure
);
393 // Move 0, stationary 1.
394 struct input_event mock_kernel_queue_move0_stationary1
[] = {
395 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 0}, {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 39},
396 {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
398 dev
->ConfigureReadMock(mock_kernel_queue_move0_stationary1
, 3, 0);
400 EXPECT_EQ(6u, size());
401 ev0
= dispatched_event(5);
403 EXPECT_EQ(ui::ET_TOUCH_MOVED
, ev0
.type
);
404 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0
.timestamp
);
405 EXPECT_EQ(39, ev0
.location
.x());
406 EXPECT_EQ(51, ev0
.location
.y());
407 EXPECT_EQ(0, ev0
.touch_id
);
408 EXPECT_FLOAT_EQ(.5f
, ev0
.pressure
);
410 // Release 0, move 1.
411 struct input_event mock_kernel_queue_release0_move1
[] = {
412 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, -1}, {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 1},
413 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 38}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
415 dev
->ConfigureReadMock(mock_kernel_queue_release0_move1
, 4, 0);
417 EXPECT_EQ(8u, size());
418 ev0
= dispatched_event(6);
419 ev1
= dispatched_event(7);
421 EXPECT_EQ(ui::ET_TOUCH_RELEASED
, ev0
.type
);
422 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0
.timestamp
);
423 EXPECT_EQ(39, ev0
.location
.x());
424 EXPECT_EQ(51, ev0
.location
.y());
425 EXPECT_EQ(0, ev0
.touch_id
);
426 EXPECT_FLOAT_EQ(.5f
, ev0
.pressure
);
428 EXPECT_EQ(ui::ET_TOUCH_MOVED
, ev1
.type
);
429 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1
.timestamp
);
430 EXPECT_EQ(38, ev1
.location
.x());
431 EXPECT_EQ(102, ev1
.location
.y());
432 EXPECT_EQ(1, ev1
.touch_id
);
433 EXPECT_FLOAT_EQ(.5f
, ev1
.pressure
);
436 struct input_event mock_kernel_queue_release1
[] = {
437 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, -1}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0},
439 dev
->ConfigureReadMock(mock_kernel_queue_release1
, 2, 0);
441 EXPECT_EQ(9u, size());
442 ev1
= dispatched_event(8);
444 EXPECT_EQ(ui::ET_TOUCH_RELEASED
, ev1
.type
);
445 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1
.timestamp
);
446 EXPECT_EQ(38, ev1
.location
.x());
447 EXPECT_EQ(102, ev1
.location
.y());
448 EXPECT_EQ(1, ev1
.touch_id
);
449 EXPECT_FLOAT_EQ(.5f
, ev1
.pressure
);
452 TEST_F(TouchEventConverterEvdevTest
, TypeA
) {
453 ui::MockTouchEventConverterEvdev
* dev
= device();
455 struct input_event mock_kernel_queue_press0
[] = {
456 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
457 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
458 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
459 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51},
460 {{0, 0}, EV_SYN
, SYN_MT_REPORT
, 0},
461 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
462 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 61},
463 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 71},
464 {{0, 0}, EV_SYN
, SYN_MT_REPORT
, 0},
465 {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
468 // Check that two events are generated.
469 dev
->ConfigureReadMock(mock_kernel_queue_press0
, 10, 0);
471 EXPECT_EQ(2u, size());
474 TEST_F(TouchEventConverterEvdevTest
, Unsync
) {
475 ui::MockTouchEventConverterEvdev
* dev
= device();
477 struct input_event mock_kernel_queue_press0
[] = {
478 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 684},
479 {{0, 0}, EV_ABS
, ABS_MT_TOUCH_MAJOR
, 3},
480 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 45},
481 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 42},
482 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 51}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
485 dev
->ConfigureReadMock(mock_kernel_queue_press0
, 6, 0);
487 EXPECT_EQ(1u, size());
489 // Prepare a move with a drop.
490 struct input_event mock_kernel_queue_move0
[] = {
491 {{0, 0}, EV_SYN
, SYN_DROPPED
, 0},
492 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 40}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
495 // Verify that we didn't receive it/
496 dev
->ConfigureReadMock(mock_kernel_queue_move0
, 3, 0);
498 EXPECT_EQ(1u, size());
500 struct input_event mock_kernel_queue_move1
[] = {
501 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 40}, {{0, 0}, EV_SYN
, SYN_REPORT
, 0}
504 // Verify that it re-syncs after a SYN_REPORT.
505 dev
->ConfigureReadMock(mock_kernel_queue_move1
, 2, 0);
507 EXPECT_EQ(2u, size());
511 TEST_F(TouchEventConverterEvdevTest
,
512 DontChangeMultitouchPositionFromLegacyAxes
) {
513 ui::MockTouchEventConverterEvdev
* dev
= device();
515 struct input_event mock_kernel_queue
[] = {
516 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 0},
517 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 100},
518 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 999},
519 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 888},
520 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 55},
521 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 1},
522 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 200},
523 {{0, 0}, EV_ABS
, ABS_MT_PRESSURE
, 44},
524 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 777},
525 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 666},
526 {{0, 0}, EV_ABS
, ABS_X
, 999},
527 {{0, 0}, EV_ABS
, ABS_Y
, 888},
528 {{0, 0}, EV_ABS
, ABS_PRESSURE
, 55},
529 {{0, 0}, EV_SYN
, SYN_REPORT
, 0},
532 // Check that two events are generated.
533 dev
->ConfigureReadMock(mock_kernel_queue
, arraysize(mock_kernel_queue
), 0);
536 const unsigned int kExpectedEventCount
= 2;
537 EXPECT_EQ(kExpectedEventCount
, size());
538 if (kExpectedEventCount
!= size())
541 ui::TouchEventParams ev0
= dispatched_event(0);
542 ui::TouchEventParams ev1
= dispatched_event(1);
544 EXPECT_EQ(0, ev0
.touch_id
);
545 EXPECT_EQ(999, ev0
.location
.x());
546 EXPECT_EQ(888, ev0
.location
.y());
547 EXPECT_FLOAT_EQ(0.8333333f
, ev0
.pressure
);
549 EXPECT_EQ(1, ev1
.touch_id
);
550 EXPECT_EQ(777, ev1
.location
.x());
551 EXPECT_EQ(666, ev1
.location
.y());
552 EXPECT_FLOAT_EQ(0.4666666f
, ev1
.pressure
);
556 TEST_F(TouchEventConverterEvdevTest
, CheckSlotLimit
) {
557 ui::MockTouchEventConverterEvdev
* dev
= device();
559 struct input_event mock_kernel_queue
[] = {
560 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, 0},
561 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 100},
562 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 999},
563 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 888},
564 {{0, 0}, EV_ABS
, ABS_MT_SLOT
, ui::TouchEventConverterEvdev::MAX_FINGERS
},
565 {{0, 0}, EV_ABS
, ABS_MT_TRACKING_ID
, 200},
566 {{0, 0}, EV_ABS
, ABS_MT_POSITION_X
, 777},
567 {{0, 0}, EV_ABS
, ABS_MT_POSITION_Y
, 666},
568 {{0, 0}, EV_SYN
, SYN_REPORT
, 0},
571 // Check that one 1 event is generated
572 dev
->ConfigureReadMock(mock_kernel_queue
, arraysize(mock_kernel_queue
), 0);
574 EXPECT_EQ(1u, size());