| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/events/ozone/device/device_manager.h" |
| 21 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 20 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 22 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| 23 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 21 #include "ui/events/platform/platform_event_dispatcher.h" | 24 #include "ui/events/platform/platform_event_dispatcher.h" |
| 22 #include "ui/events/platform/platform_event_source.h" | 25 #include "ui/events/platform/platform_event_source.h" |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 static int SetNonBlocking(int fd) { | 29 static int SetNonBlocking(int fd) { |
| 27 int flags = fcntl(fd, F_GETFL, 0); | 30 int flags = fcntl(fd, F_GETFL, 0); |
| 28 if (flags == -1) | 31 if (flags == -1) |
| 29 flags = 0; | 32 flags = 0; |
| 30 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); | 33 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
| 31 } | 34 } |
| 32 | 35 |
| 33 const char kTestDevicePath[] = "/dev/input/test-device"; | 36 const char kTestDevicePath[] = "/dev/input/test-device"; |
| 34 | 37 |
| 35 } // namespace | 38 } // namespace |
| 36 | 39 |
| 37 namespace ui { | 40 namespace ui { |
| 38 | 41 |
| 39 class MockTabletEventConverterEvdev : public TabletEventConverterEvdev { | 42 class MockTabletEventConverterEvdev : public TabletEventConverterEvdev { |
| 40 public: | 43 public: |
| 41 MockTabletEventConverterEvdev(int fd, | 44 MockTabletEventConverterEvdev( |
| 42 base::FilePath path, | 45 int fd, |
| 43 EventModifiersEvdev* modifiers, | 46 base::FilePath path, |
| 44 CursorDelegateEvdev* cursor); | 47 CursorDelegateEvdev* cursor, |
| 48 const MouseMoveEventDispatchCallback& mouse_move_callback, |
| 49 const MouseButtonEventDispatchCallback& mouse_button_callback); |
| 45 ~MockTabletEventConverterEvdev() override {}; | 50 ~MockTabletEventConverterEvdev() override {}; |
| 46 | 51 |
| 47 void ConfigureReadMock(struct input_event* queue, | 52 void ConfigureReadMock(struct input_event* queue, |
| 48 long read_this_many, | 53 long read_this_many, |
| 49 long queue_index); | 54 long queue_index); |
| 50 | 55 |
| 51 unsigned size() { return dispatched_events_.size(); } | |
| 52 MouseEvent* event(unsigned index) { | |
| 53 DCHECK_GT(dispatched_events_.size(), index); | |
| 54 Event* ev = dispatched_events_[index]; | |
| 55 DCHECK(ev->IsMouseEvent()); | |
| 56 return static_cast<MouseEvent*>(ev); | |
| 57 } | |
| 58 | |
| 59 // Actually dispatch the event reader code. | 56 // Actually dispatch the event reader code. |
| 60 void ReadNow() { | 57 void ReadNow() { |
| 61 OnFileCanReadWithoutBlocking(read_pipe_); | 58 OnFileCanReadWithoutBlocking(read_pipe_); |
| 62 base::RunLoop().RunUntilIdle(); | 59 base::RunLoop().RunUntilIdle(); |
| 63 } | 60 } |
| 64 | 61 |
| 65 void DispatchCallback(scoped_ptr<Event> event) { | |
| 66 dispatched_events_.push_back(event.release()); | |
| 67 } | |
| 68 | |
| 69 private: | 62 private: |
| 70 int read_pipe_; | 63 int read_pipe_; |
| 71 int write_pipe_; | 64 int write_pipe_; |
| 72 | 65 |
| 73 ScopedVector<Event> dispatched_events_; | 66 ScopedVector<Event> dispatched_events_; |
| 74 | 67 |
| 75 DISALLOW_COPY_AND_ASSIGN(MockTabletEventConverterEvdev); | 68 DISALLOW_COPY_AND_ASSIGN(MockTabletEventConverterEvdev); |
| 76 }; | 69 }; |
| 77 | 70 |
| 78 class MockTabletCursorEvdev : public CursorDelegateEvdev { | 71 class MockTabletCursorEvdev : public CursorDelegateEvdev { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 | 88 |
| 96 private: | 89 private: |
| 97 gfx::PointF cursor_location_; | 90 gfx::PointF cursor_location_; |
| 98 gfx::Rect cursor_display_bounds_; | 91 gfx::Rect cursor_display_bounds_; |
| 99 DISALLOW_COPY_AND_ASSIGN(MockTabletCursorEvdev); | 92 DISALLOW_COPY_AND_ASSIGN(MockTabletCursorEvdev); |
| 100 }; | 93 }; |
| 101 | 94 |
| 102 MockTabletEventConverterEvdev::MockTabletEventConverterEvdev( | 95 MockTabletEventConverterEvdev::MockTabletEventConverterEvdev( |
| 103 int fd, | 96 int fd, |
| 104 base::FilePath path, | 97 base::FilePath path, |
| 105 EventModifiersEvdev* modifiers, | 98 CursorDelegateEvdev* cursor, |
| 106 CursorDelegateEvdev* cursor) | 99 const MouseMoveEventDispatchCallback& mouse_move_callback, |
| 107 : TabletEventConverterEvdev( | 100 const MouseButtonEventDispatchCallback& mouse_button_callback) |
| 108 fd, | 101 : TabletEventConverterEvdev(fd, |
| 109 path, | 102 path, |
| 110 1, | 103 1, |
| 111 INPUT_DEVICE_UNKNOWN, | 104 INPUT_DEVICE_UNKNOWN, |
| 112 modifiers, | 105 cursor, |
| 113 cursor, | 106 EventDeviceInfo(), |
| 114 EventDeviceInfo(), | 107 mouse_move_callback, |
| 115 base::Bind(&MockTabletEventConverterEvdev::DispatchCallback, | 108 mouse_button_callback) { |
| 116 base::Unretained(this))) { | |
| 117 // Real values taken from Wacom Intuos 4 | 109 // Real values taken from Wacom Intuos 4 |
| 118 x_abs_min_ = 0; | 110 x_abs_min_ = 0; |
| 119 x_abs_range_ = 65024; | 111 x_abs_range_ = 65024; |
| 120 y_abs_min_ = 0; | 112 y_abs_min_ = 0; |
| 121 y_abs_range_ = 40640; | 113 y_abs_range_ = 40640; |
| 122 | 114 |
| 123 int fds[2]; | 115 int fds[2]; |
| 124 | 116 |
| 125 if (pipe(fds)) | 117 if (pipe(fds)) |
| 126 PLOG(FATAL) << "failed pipe"; | 118 PLOG(FATAL) << "failed pipe"; |
| 127 | 119 |
| 128 DCHECK(SetNonBlocking(fds[0]) == 0) | 120 DCHECK(SetNonBlocking(fds[0]) == 0) |
| 129 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; | 121 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; |
| 130 DCHECK(SetNonBlocking(fds[1]) == 0) | 122 DCHECK(SetNonBlocking(fds[1]) == 0) |
| 131 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; | 123 << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; |
| 132 read_pipe_ = fds[0]; | 124 read_pipe_ = fds[0]; |
| 133 write_pipe_ = fds[1]; | 125 write_pipe_ = fds[1]; |
| 134 } | 126 } |
| 135 | 127 |
| 136 void MockTabletEventConverterEvdev::ConfigureReadMock(struct input_event* queue, | 128 void MockTabletEventConverterEvdev::ConfigureReadMock(struct input_event* queue, |
| 137 long read_this_many, | 129 long read_this_many, |
| 138 long queue_index) { | 130 long queue_index) { |
| 139 int nwrite = HANDLE_EINTR(write(write_pipe_, queue + queue_index, | 131 int nwrite = HANDLE_EINTR(write(write_pipe_, queue + queue_index, |
| 140 sizeof(struct input_event) * read_this_many)); | 132 sizeof(struct input_event) * read_this_many)); |
| 141 DCHECK(nwrite == | 133 DCHECK(nwrite == |
| 142 static_cast<int>(sizeof(struct input_event) * read_this_many)) | 134 static_cast<int>(sizeof(struct input_event) * read_this_many)) |
| 143 << "write() failed, errno: " << errno; | 135 << "write() failed, errno: " << errno; |
| 144 } | 136 } |
| 145 | 137 |
| 138 class MockDeviceManager : public ui::DeviceManager { |
| 139 public: |
| 140 MockDeviceManager() {} |
| 141 ~MockDeviceManager() override {} |
| 142 |
| 143 // DeviceManager: |
| 144 void ScanDevices(DeviceEventObserver* observer) override {} |
| 145 void AddObserver(DeviceEventObserver* observer) override {} |
| 146 void RemoveObserver(DeviceEventObserver* observer) override {} |
| 147 }; |
| 148 |
| 149 class TestEventFactoryEvdev : public EventFactoryEvdev { |
| 150 public: |
| 151 TestEventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 152 DeviceManager* device_manager, |
| 153 KeyboardLayoutEngine* keyboard_layout_engine, |
| 154 const EventDispatchCallback& callback) |
| 155 : EventFactoryEvdev(cursor, device_manager, keyboard_layout_engine), |
| 156 callback_(callback) {} |
| 157 ~TestEventFactoryEvdev() override {} |
| 158 |
| 159 private: |
| 160 void PostUiEvent(scoped_ptr<Event> event) override { |
| 161 callback_.Run(event.Pass()); |
| 162 } |
| 163 |
| 164 EventDispatchCallback callback_; |
| 165 }; |
| 166 |
| 146 } // namespace ui | 167 } // namespace ui |
| 147 | 168 |
| 148 // Test fixture. | 169 // Test fixture. |
| 149 class TabletEventConverterEvdevTest : public testing::Test { | 170 class TabletEventConverterEvdevTest : public testing::Test { |
| 150 public: | 171 public: |
| 151 TabletEventConverterEvdevTest() {} | 172 TabletEventConverterEvdevTest() {} |
| 152 | 173 |
| 153 // Overridden from testing::Test: | 174 // Overridden from testing::Test: |
| 154 void SetUp() override { | 175 void SetUp() override { |
| 155 // Set up pipe to satisfy message pump (unused). | 176 // Set up pipe to satisfy message pump (unused). |
| 156 int evdev_io[2]; | 177 int evdev_io[2]; |
| 157 if (pipe(evdev_io)) | 178 if (pipe(evdev_io)) |
| 158 PLOG(FATAL) << "failed pipe"; | 179 PLOG(FATAL) << "failed pipe"; |
| 159 events_in_ = evdev_io[0]; | 180 events_in_ = evdev_io[0]; |
| 160 events_out_ = evdev_io[1]; | 181 events_out_ = evdev_io[1]; |
| 161 | 182 |
| 162 cursor_.reset(new ui::MockTabletCursorEvdev()); | 183 cursor_.reset(new ui::MockTabletCursorEvdev()); |
| 163 modifiers_.reset(new ui::EventModifiersEvdev()); | 184 device_manager_.reset(new ui::MockDeviceManager); |
| 185 event_factory_.reset(new ui::TestEventFactoryEvdev( |
| 186 cursor_.get(), device_manager_.get(), |
| 187 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), |
| 188 base::Bind(&TabletEventConverterEvdevTest::DispatchEventForTest, |
| 189 base::Unretained(this)))); |
| 164 device_.reset(new ui::MockTabletEventConverterEvdev( | 190 device_.reset(new ui::MockTabletEventConverterEvdev( |
| 165 events_in_, base::FilePath(kTestDevicePath), modifiers_.get(), | 191 events_in_, base::FilePath(kTestDevicePath), cursor_.get(), |
| 166 cursor_.get())); | 192 base::Bind(&ui::EventFactoryEvdev::PostMouseMoveEvent, |
| 193 base::Unretained(event_factory_.get())), |
| 194 base::Bind(&ui::EventFactoryEvdev::PostMouseButtonEvent, |
| 195 base::Unretained(event_factory_.get())))); |
| 167 } | 196 } |
| 168 | 197 |
| 169 void TearDown() override { | 198 void TearDown() override { |
| 170 modifiers_.reset(); | |
| 171 cursor_.reset(); | 199 cursor_.reset(); |
| 172 device_.reset(); | 200 device_.reset(); |
| 173 } | 201 } |
| 174 | 202 |
| 175 ui::MockTabletEventConverterEvdev* device() { return device_.get(); } | 203 ui::MockTabletEventConverterEvdev* device() { return device_.get(); } |
| 176 ui::CursorDelegateEvdev* cursor() { return cursor_.get(); } | 204 ui::CursorDelegateEvdev* cursor() { return cursor_.get(); } |
| 177 ui::EventModifiersEvdev* modifiers() { return modifiers_.get(); } | 205 |
| 206 unsigned size() { return dispatched_events_.size(); } |
| 207 ui::MouseEvent* dispatched_event(unsigned index) { |
| 208 DCHECK_GT(dispatched_events_.size(), index); |
| 209 ui::Event* ev = dispatched_events_[index]; |
| 210 DCHECK(ev->IsMouseEvent()); |
| 211 return static_cast<ui::MouseEvent*>(ev); |
| 212 } |
| 213 |
| 214 void DispatchEventForTest(scoped_ptr<ui::Event> event) { |
| 215 dispatched_events_.push_back(event.release()); |
| 216 } |
| 178 | 217 |
| 179 private: | 218 private: |
| 219 scoped_ptr<ui::MockTabletCursorEvdev> cursor_; |
| 220 scoped_ptr<ui::DeviceManager> device_manager_; |
| 221 scoped_ptr<ui::EventFactoryEvdev> event_factory_; |
| 180 scoped_ptr<ui::MockTabletEventConverterEvdev> device_; | 222 scoped_ptr<ui::MockTabletEventConverterEvdev> device_; |
| 181 scoped_ptr<ui::MockTabletCursorEvdev> cursor_; | 223 |
| 182 scoped_ptr<ui::EventModifiersEvdev> modifiers_; | 224 ScopedVector<ui::Event> dispatched_events_; |
| 183 | 225 |
| 184 int events_out_; | 226 int events_out_; |
| 185 int events_in_; | 227 int events_in_; |
| 186 | 228 |
| 187 DISALLOW_COPY_AND_ASSIGN(TabletEventConverterEvdevTest); | 229 DISALLOW_COPY_AND_ASSIGN(TabletEventConverterEvdevTest); |
| 188 }; | 230 }; |
| 189 | 231 |
| 190 #define EPSILON 20 | 232 #define EPSILON 20 |
| 191 | 233 |
| 192 // Uses real data captured from Wacom Intuos 4 | 234 // Uses real data captured from Wacom Intuos 4 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 205 {{0, 0}, EV_ABS, ABS_Y, 0}, | 247 {{0, 0}, EV_ABS, ABS_Y, 0}, |
| 206 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 248 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 207 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 249 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 208 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 250 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 209 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 251 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 210 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 252 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 211 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 253 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 212 }; | 254 }; |
| 213 | 255 |
| 214 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 256 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 215 EXPECT_EQ(1u, dev->size()); | 257 EXPECT_EQ(1u, size()); |
| 216 | 258 |
| 217 ui::MouseEvent* event = dev->event(0); | 259 ui::MouseEvent* event = dispatched_event(0); |
| 218 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 260 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 219 | 261 |
| 220 EXPECT_LT(cursor()->GetLocation().x(), EPSILON); | 262 EXPECT_LT(cursor()->GetLocation().x(), EPSILON); |
| 221 EXPECT_LT(cursor()->GetLocation().y(), EPSILON); | 263 EXPECT_LT(cursor()->GetLocation().y(), EPSILON); |
| 222 } | 264 } |
| 223 | 265 |
| 224 TEST_F(TabletEventConverterEvdevTest, MoveTopRight) { | 266 TEST_F(TabletEventConverterEvdevTest, MoveTopRight) { |
| 225 ui::MockTabletEventConverterEvdev* dev = device(); | 267 ui::MockTabletEventConverterEvdev* dev = device(); |
| 226 | 268 |
| 227 struct input_event mock_kernel_queue[] = { | 269 struct input_event mock_kernel_queue[] = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 238 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 280 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 239 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 281 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 240 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, | 282 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, |
| 241 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 283 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 242 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 284 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 243 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 285 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 244 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 286 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 245 }; | 287 }; |
| 246 | 288 |
| 247 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 289 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 248 EXPECT_EQ(1u, dev->size()); | 290 EXPECT_EQ(1u, size()); |
| 249 | 291 |
| 250 ui::MouseEvent* event = dev->event(0); | 292 ui::MouseEvent* event = dispatched_event(0); |
| 251 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 293 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 252 | 294 |
| 253 EXPECT_GT(cursor()->GetLocation().x(), | 295 EXPECT_GT(cursor()->GetLocation().x(), |
| 254 cursor()->GetCursorDisplayBounds().width() - EPSILON); | 296 cursor()->GetCursorDisplayBounds().width() - EPSILON); |
| 255 EXPECT_LT(cursor()->GetLocation().y(), EPSILON); | 297 EXPECT_LT(cursor()->GetLocation().y(), EPSILON); |
| 256 } | 298 } |
| 257 | 299 |
| 258 TEST_F(TabletEventConverterEvdevTest, MoveBottomLeft) { | 300 TEST_F(TabletEventConverterEvdevTest, MoveBottomLeft) { |
| 259 ui::MockTabletEventConverterEvdev* dev = device(); | 301 ui::MockTabletEventConverterEvdev* dev = device(); |
| 260 | 302 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 271 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 313 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 272 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 314 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 273 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, | 315 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, |
| 274 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 316 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 275 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 317 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 276 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 318 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 277 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 319 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 278 }; | 320 }; |
| 279 | 321 |
| 280 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 322 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 281 EXPECT_EQ(1u, dev->size()); | 323 EXPECT_EQ(1u, size()); |
| 282 | 324 |
| 283 ui::MouseEvent* event = dev->event(0); | 325 ui::MouseEvent* event = dispatched_event(0); |
| 284 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 326 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 285 | 327 |
| 286 EXPECT_LT(cursor()->GetLocation().x(), EPSILON); | 328 EXPECT_LT(cursor()->GetLocation().x(), EPSILON); |
| 287 EXPECT_GT(cursor()->GetLocation().y(), | 329 EXPECT_GT(cursor()->GetLocation().y(), |
| 288 cursor()->GetCursorDisplayBounds().height() - EPSILON); | 330 cursor()->GetCursorDisplayBounds().height() - EPSILON); |
| 289 } | 331 } |
| 290 | 332 |
| 291 TEST_F(TabletEventConverterEvdevTest, MoveBottomRight) { | 333 TEST_F(TabletEventConverterEvdevTest, MoveBottomRight) { |
| 292 ui::MockTabletEventConverterEvdev* dev = device(); | 334 ui::MockTabletEventConverterEvdev* dev = device(); |
| 293 | 335 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 306 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 348 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 307 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 349 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 308 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, | 350 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, |
| 309 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 351 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 310 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 352 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 311 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 353 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 312 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 354 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 313 }; | 355 }; |
| 314 | 356 |
| 315 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 357 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 316 EXPECT_EQ(1u, dev->size()); | 358 EXPECT_EQ(1u, size()); |
| 317 | 359 |
| 318 ui::MouseEvent* event = dev->event(0); | 360 ui::MouseEvent* event = dispatched_event(0); |
| 319 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 361 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 320 | 362 |
| 321 EXPECT_GT(cursor()->GetLocation().x(), | 363 EXPECT_GT(cursor()->GetLocation().x(), |
| 322 cursor()->GetCursorDisplayBounds().height() - EPSILON); | 364 cursor()->GetCursorDisplayBounds().height() - EPSILON); |
| 323 EXPECT_GT(cursor()->GetLocation().y(), | 365 EXPECT_GT(cursor()->GetLocation().y(), |
| 324 cursor()->GetCursorDisplayBounds().height() - EPSILON); | 366 cursor()->GetCursorDisplayBounds().height() - EPSILON); |
| 325 } | 367 } |
| 326 | 368 |
| 327 TEST_F(TabletEventConverterEvdevTest, Tap) { | 369 TEST_F(TabletEventConverterEvdevTest, Tap) { |
| 328 ui::MockTabletEventConverterEvdev* dev = device(); | 370 ui::MockTabletEventConverterEvdev* dev = device(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 356 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 398 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 357 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 399 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 358 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, | 400 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, |
| 359 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 401 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 360 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 402 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 361 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 403 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 362 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 404 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 363 }; | 405 }; |
| 364 | 406 |
| 365 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 407 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 366 EXPECT_EQ(3u, dev->size()); | 408 EXPECT_EQ(3u, size()); |
| 367 | 409 |
| 368 ui::MouseEvent* event = dev->event(0); | 410 ui::MouseEvent* event = dispatched_event(0); |
| 369 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 411 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 370 event = dev->event(1); | 412 event = dispatched_event(1); |
| 371 EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type()); | 413 EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type()); |
| 372 EXPECT_EQ(true, event->IsLeftMouseButton()); | 414 EXPECT_EQ(true, event->IsLeftMouseButton()); |
| 373 event = dev->event(2); | 415 event = dispatched_event(2); |
| 374 EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type()); | 416 EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type()); |
| 375 EXPECT_EQ(true, event->IsLeftMouseButton()); | 417 EXPECT_EQ(true, event->IsLeftMouseButton()); |
| 376 } | 418 } |
| 377 | 419 |
| 378 TEST_F(TabletEventConverterEvdevTest, StylusButtonPress) { | 420 TEST_F(TabletEventConverterEvdevTest, StylusButtonPress) { |
| 379 ui::MockTabletEventConverterEvdev* dev = device(); | 421 ui::MockTabletEventConverterEvdev* dev = device(); |
| 380 | 422 |
| 381 struct input_event mock_kernel_queue[] = { | 423 struct input_event mock_kernel_queue[] = { |
| 382 {{0, 0}, EV_ABS, ABS_X, 30055}, | 424 {{0, 0}, EV_ABS, ABS_X, 30055}, |
| 383 {{0, 0}, EV_ABS, ABS_Y, 18094}, | 425 {{0, 0}, EV_ABS, ABS_Y, 18094}, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 403 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, | 445 {{0, 0}, EV_ABS, ABS_DISTANCE, 0}, |
| 404 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, | 446 {{0, 0}, EV_ABS, ABS_TILT_X, 0}, |
| 405 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, | 447 {{0, 0}, EV_ABS, ABS_TILT_Y, 0}, |
| 406 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, | 448 {{0, 0}, EV_KEY, BTN_TOOL_PEN, 0}, |
| 407 {{0, 0}, EV_ABS, ABS_MISC, 0}, | 449 {{0, 0}, EV_ABS, ABS_MISC, 0}, |
| 408 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, | 450 {{0, 0}, EV_MSC, MSC_SERIAL, 159403517}, |
| 409 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 451 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 410 }; | 452 }; |
| 411 | 453 |
| 412 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 454 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 413 EXPECT_EQ(3u, dev->size()); | 455 EXPECT_EQ(3u, size()); |
| 414 | 456 |
| 415 ui::MouseEvent* event = dev->event(0); | 457 ui::MouseEvent* event = dispatched_event(0); |
| 416 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); | 458 EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type()); |
| 417 event = dev->event(1); | 459 event = dispatched_event(1); |
| 418 EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type()); | 460 EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type()); |
| 419 EXPECT_EQ(true, event->IsRightMouseButton()); | 461 EXPECT_EQ(true, event->IsRightMouseButton()); |
| 420 event = dev->event(2); | 462 event = dispatched_event(2); |
| 421 EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type()); | 463 EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type()); |
| 422 EXPECT_EQ(true, event->IsRightMouseButton()); | 464 EXPECT_EQ(true, event->IsRightMouseButton()); |
| 423 } | 465 } |
| 424 | 466 |
| 425 // Should only get an event if BTN_TOOL received | 467 // Should only get an event if BTN_TOOL received |
| 426 TEST_F(TabletEventConverterEvdevTest, CheckStylusFiltering) { | 468 TEST_F(TabletEventConverterEvdevTest, CheckStylusFiltering) { |
| 427 ui::MockTabletEventConverterEvdev* dev = device(); | 469 ui::MockTabletEventConverterEvdev* dev = device(); |
| 428 | 470 |
| 429 struct input_event mock_kernel_queue[] = { | 471 struct input_event mock_kernel_queue[] = { |
| 430 {{0, 0}, EV_ABS, ABS_X, 0}, | 472 {{0, 0}, EV_ABS, ABS_X, 0}, |
| 431 {{0, 0}, EV_ABS, ABS_Y, 0}, | 473 {{0, 0}, EV_ABS, ABS_Y, 0}, |
| 432 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 474 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 433 }; | 475 }; |
| 434 | 476 |
| 435 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 477 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 436 EXPECT_EQ(0u, dev->size()); | 478 EXPECT_EQ(0u, size()); |
| 437 } | 479 } |
| OLD | NEW |