| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 static int SetNonBlocking(int fd) { | 24 static int SetNonBlocking(int fd) { |
| 25 int flags = fcntl(fd, F_GETFL, 0); | 25 int flags = fcntl(fd, F_GETFL, 0); |
| 26 if (flags == -1) | 26 if (flags == -1) |
| 27 flags = 0; | 27 flags = 0; |
| 28 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); | 28 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
| 29 } | 29 } |
| 30 | 30 |
| 31 const int kInvalidFileDescriptor = -1; | |
| 32 const char kTestDevicePath[] = "/dev/input/test-device"; | 31 const char kTestDevicePath[] = "/dev/input/test-device"; |
| 33 | 32 |
| 34 } // namespace | 33 } // namespace |
| 35 | 34 |
| 36 namespace ui { | 35 namespace ui { |
| 37 | 36 |
| 38 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev, | 37 class MockTouchEventConverterEvdev : public TouchEventConverterEvdev, |
| 39 public base::MessagePumpDispatcher { | 38 public base::MessagePumpDispatcher { |
| 40 public: | 39 public: |
| 41 MockTouchEventConverterEvdev(int fd, base::FilePath path); | 40 MockTouchEventConverterEvdev(int fd, base::FilePath path); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 102 |
| 104 } // namespace ui | 103 } // namespace ui |
| 105 | 104 |
| 106 // Test fixture. | 105 // Test fixture. |
| 107 class TouchEventConverterEvdevTest : public testing::Test { | 106 class TouchEventConverterEvdevTest : public testing::Test { |
| 108 public: | 107 public: |
| 109 TouchEventConverterEvdevTest() {} | 108 TouchEventConverterEvdevTest() {} |
| 110 | 109 |
| 111 // Overridden from testing::Test: | 110 // Overridden from testing::Test: |
| 112 virtual void SetUp() OVERRIDE { | 111 virtual void SetUp() OVERRIDE { |
| 112 // Set up pipe to satisfy message pump (unused). |
| 113 int evdev_io[2]; |
| 114 if (pipe(evdev_io)) |
| 115 PLOG(FATAL) << "failed pipe"; |
| 116 events_in_ = evdev_io[0]; |
| 117 events_out_ = evdev_io[1]; |
| 118 |
| 113 loop_ = new base::MessageLoopForUI; | 119 loop_ = new base::MessageLoopForUI; |
| 114 device_ = new ui::MockTouchEventConverterEvdev( | 120 device_ = new ui::MockTouchEventConverterEvdev( |
| 115 kInvalidFileDescriptor, base::FilePath(kTestDevicePath)); | 121 events_in_, base::FilePath(kTestDevicePath)); |
| 116 base::MessagePumpOzone::Current()->AddDispatcherForRootWindow(device_); | 122 base::MessagePumpOzone::Current()->AddDispatcherForRootWindow(device_); |
| 117 } | 123 } |
| 118 virtual void TearDown() OVERRIDE { | 124 virtual void TearDown() OVERRIDE { |
| 119 delete device_; | 125 delete device_; |
| 120 delete loop_; | 126 delete loop_; |
| 121 } | 127 } |
| 122 | 128 |
| 123 ui::MockTouchEventConverterEvdev* device() { return device_; } | 129 ui::MockTouchEventConverterEvdev* device() { return device_; } |
| 124 | 130 |
| 125 private: | 131 private: |
| 126 base::MessageLoop* loop_; | 132 base::MessageLoop* loop_; |
| 127 ui::MockTouchEventConverterEvdev* device_; | 133 ui::MockTouchEventConverterEvdev* device_; |
| 134 |
| 135 int events_out_; |
| 136 int events_in_; |
| 137 |
| 128 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdevTest); | 138 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdevTest); |
| 129 }; | 139 }; |
| 130 | 140 |
| 131 // TODO(rjkroege): Test for valid handling of time stamps. | 141 // TODO(rjkroege): Test for valid handling of time stamps. |
| 132 TEST_F(TouchEventConverterEvdevTest, TouchDown) { | 142 TEST_F(TouchEventConverterEvdevTest, TouchDown) { |
| 133 ui::MockTouchEventConverterEvdev* dev = device(); | 143 ui::MockTouchEventConverterEvdev* dev = device(); |
| 134 | 144 |
| 135 struct input_event mock_kernel_queue[] = { | 145 struct input_event mock_kernel_queue[] = { |
| 136 {{0, 0}, EV_ABS, ABS_MT_TRACKING_ID, 684}, | 146 {{0, 0}, EV_ABS, ABS_MT_TRACKING_ID, 684}, |
| 137 {{0, 0}, EV_ABS, ABS_MT_TOUCH_MAJOR, 3}, | 147 {{0, 0}, EV_ABS, ABS_MT_TOUCH_MAJOR, 3}, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 ev1 = dev->event(8); | 404 ev1 = dev->event(8); |
| 395 | 405 |
| 396 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ev1->type()); | 406 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ev1->type()); |
| 397 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1->time_stamp()); | 407 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1->time_stamp()); |
| 398 EXPECT_EQ(38, ev1->x()); | 408 EXPECT_EQ(38, ev1->x()); |
| 399 EXPECT_EQ(102, ev1->y()); | 409 EXPECT_EQ(102, ev1->y()); |
| 400 EXPECT_EQ(1, ev1->touch_id()); | 410 EXPECT_EQ(1, ev1->touch_id()); |
| 401 EXPECT_FLOAT_EQ(.5f, ev1->force()); | 411 EXPECT_FLOAT_EQ(.5f, ev1->force()); |
| 402 EXPECT_FLOAT_EQ(0.f, ev1->rotation_angle()); | 412 EXPECT_FLOAT_EQ(0.f, ev1->rotation_angle()); |
| 403 } | 413 } |
| OLD | NEW |