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 | 46 |
47 unsigned size() { return dispatched_events_.size(); } | 47 unsigned size() { return dispatched_events_.size(); } |
48 TouchEvent* event(unsigned index) { return dispatched_events_[index]; } | 48 TouchEvent* event(unsigned index) { return dispatched_events_[index]; } |
49 | 49 |
50 // Actually dispatch the event reader code. | 50 // Actually dispatch the event reader code. |
51 void ReadNow() { | 51 void ReadNow() { |
52 OnFileCanReadWithoutBlocking(read_pipe_); | 52 OnFileCanReadWithoutBlocking(read_pipe_); |
53 base::RunLoop().RunUntilIdle(); | 53 base::RunLoop().RunUntilIdle(); |
54 } | 54 } |
55 | 55 |
56 void DispatchCallback(void* event) { | 56 void DispatchCallback(Event* event) { |
57 dispatched_events_.push_back( | 57 dispatched_events_.push_back( |
58 new TouchEvent(*static_cast<TouchEvent*>(event))); | 58 new TouchEvent(*static_cast<TouchEvent*>(event))); |
59 } | 59 } |
60 | 60 |
61 private: | 61 private: |
62 int read_pipe_; | 62 int read_pipe_; |
63 int write_pipe_; | 63 int write_pipe_; |
64 | 64 |
65 ScopedVector<TouchEvent> dispatched_events_; | 65 ScopedVector<TouchEvent> dispatched_events_; |
66 | 66 |
67 DISALLOW_COPY_AND_ASSIGN(MockTouchEventConverterEvdev); | 67 DISALLOW_COPY_AND_ASSIGN(MockTouchEventConverterEvdev); |
68 }; | 68 }; |
69 | 69 |
70 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd, | 70 MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd, |
71 base::FilePath path) | 71 base::FilePath path) |
72 : TouchEventConverterEvdev(fd, path, EventDeviceInfo()) { | 72 : TouchEventConverterEvdev( |
| 73 fd, |
| 74 path, |
| 75 EventDeviceInfo(), |
| 76 base::Bind(&MockTouchEventConverterEvdev::DispatchCallback, |
| 77 base::Unretained(this))) { |
73 pressure_min_ = 30; | 78 pressure_min_ = 30; |
74 pressure_max_ = 60; | 79 pressure_max_ = 60; |
75 | 80 |
76 // TODO(rjkroege): Check test axes. | 81 // TODO(rjkroege): Check test axes. |
77 x_min_ = 0; | 82 x_min_ = 0; |
78 x_max_ = std::numeric_limits<int>::max(); | 83 x_max_ = std::numeric_limits<int>::max(); |
79 y_min_ = 0; | 84 y_min_ = 0; |
80 y_max_ = std::numeric_limits<int>::max(); | 85 y_max_ = std::numeric_limits<int>::max(); |
81 | 86 |
82 int fds[2]; | 87 int fds[2]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // Set up pipe to satisfy message pump (unused). | 120 // Set up pipe to satisfy message pump (unused). |
116 int evdev_io[2]; | 121 int evdev_io[2]; |
117 if (pipe(evdev_io)) | 122 if (pipe(evdev_io)) |
118 PLOG(FATAL) << "failed pipe"; | 123 PLOG(FATAL) << "failed pipe"; |
119 events_in_ = evdev_io[0]; | 124 events_in_ = evdev_io[0]; |
120 events_out_ = evdev_io[1]; | 125 events_out_ = evdev_io[1]; |
121 | 126 |
122 loop_ = new base::MessageLoopForUI; | 127 loop_ = new base::MessageLoopForUI; |
123 device_ = new ui::MockTouchEventConverterEvdev( | 128 device_ = new ui::MockTouchEventConverterEvdev( |
124 events_in_, base::FilePath(kTestDevicePath)); | 129 events_in_, base::FilePath(kTestDevicePath)); |
125 device_->SetDispatchCallback( | |
126 base::Bind(&ui::MockTouchEventConverterEvdev::DispatchCallback, | |
127 base::Unretained(device_))); | |
128 } | 130 } |
129 | 131 |
130 virtual void TearDown() OVERRIDE { | 132 virtual void TearDown() OVERRIDE { |
131 delete device_; | 133 delete device_; |
132 delete loop_; | 134 delete loop_; |
133 } | 135 } |
134 | 136 |
135 ui::MockTouchEventConverterEvdev* device() { return device_; } | 137 ui::MockTouchEventConverterEvdev* device() { return device_; } |
136 | 138 |
137 private: | 139 private: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 ev1 = dev->event(8); | 412 ev1 = dev->event(8); |
411 | 413 |
412 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ev1->type()); | 414 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ev1->type()); |
413 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1->time_stamp()); | 415 EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1->time_stamp()); |
414 EXPECT_EQ(38, ev1->x()); | 416 EXPECT_EQ(38, ev1->x()); |
415 EXPECT_EQ(102, ev1->y()); | 417 EXPECT_EQ(102, ev1->y()); |
416 EXPECT_EQ(1, ev1->touch_id()); | 418 EXPECT_EQ(1, ev1->touch_id()); |
417 EXPECT_FLOAT_EQ(.5f, ev1->force()); | 419 EXPECT_FLOAT_EQ(.5f, ev1->force()); |
418 EXPECT_FLOAT_EQ(0.f, ev1->rotation_angle()); | 420 EXPECT_FLOAT_EQ(0.f, ev1->rotation_angle()); |
419 } | 421 } |
OLD | NEW |