| 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 <linux/input.h> | 5 #include <linux/input.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 #include "ui/events/keycodes/keyboard_codes.h" | 13 #include "ui/events/keycodes/keyboard_codes.h" |
| 14 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 14 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 15 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 15 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 16 #include "ui/events/ozone/evdev/keyboard_evdev.h" | 16 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
| 17 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 17 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
| 18 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 18 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 21 | 21 |
| 22 const char kTestDevicePath[] = "/dev/input/test-device"; | 22 const char kTestDevicePath[] = "/dev/input/test-device"; |
| 23 | 23 |
| 24 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl { | 24 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl { |
| 25 public: | 25 public: |
| 26 MockEventConverterEvdevImpl(int fd, | 26 MockEventConverterEvdevImpl(int fd, |
| 27 EventModifiersEvdev* modifiers, | 27 EventModifiersEvdev* modifiers, |
| 28 MouseButtonMapEvdev* button_map, | 28 MouseButtonMapEvdev* button_map, |
| 29 CursorDelegateEvdev* cursor, | 29 CursorDelegateEvdev* cursor, |
| 30 KeyboardEvdev* keyboard, | 30 const KeyEventDispatchCallback& key_callback, |
| 31 const EventDispatchCallback& callback) | 31 const EventDispatchCallback& callback) |
| 32 : EventConverterEvdevImpl(fd, | 32 : EventConverterEvdevImpl(fd, |
| 33 base::FilePath(kTestDevicePath), | 33 base::FilePath(kTestDevicePath), |
| 34 1, | 34 1, |
| 35 INPUT_DEVICE_UNKNOWN, | 35 INPUT_DEVICE_UNKNOWN, |
| 36 EventDeviceInfo(), | 36 EventDeviceInfo(), |
| 37 modifiers, | 37 modifiers, |
| 38 button_map, | 38 button_map, |
| 39 cursor, | 39 cursor, |
| 40 keyboard, | 40 key_callback, |
| 41 callback) { | 41 callback) { |
| 42 Start(); | 42 Start(); |
| 43 } | 43 } |
| 44 ~MockEventConverterEvdevImpl() override {} | 44 ~MockEventConverterEvdevImpl() override {} |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(MockEventConverterEvdevImpl); | 47 DISALLOW_COPY_AND_ASSIGN(MockEventConverterEvdevImpl); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class MockCursorEvdev : public CursorDelegateEvdev { | 50 class MockCursorEvdev : public CursorDelegateEvdev { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 events_in_ = evdev_io[0]; | 93 events_in_ = evdev_io[0]; |
| 94 events_out_ = evdev_io[1]; | 94 events_out_ = evdev_io[1]; |
| 95 | 95 |
| 96 cursor_.reset(new ui::MockCursorEvdev()); | 96 cursor_.reset(new ui::MockCursorEvdev()); |
| 97 modifiers_.reset(new ui::EventModifiersEvdev()); | 97 modifiers_.reset(new ui::EventModifiersEvdev()); |
| 98 button_map_.reset(new ui::MouseButtonMapEvdev()); | 98 button_map_.reset(new ui::MouseButtonMapEvdev()); |
| 99 | 99 |
| 100 const ui::EventDispatchCallback callback = | 100 const ui::EventDispatchCallback callback = |
| 101 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest, | 101 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest, |
| 102 base::Unretained(this)); | 102 base::Unretained(this)); |
| 103 const ui::KeyEventDispatchCallback key_callback = |
| 104 base::Bind(&EventConverterEvdevImplTest::DispatchKeyEventForTest, |
| 105 base::Unretained(this)); |
| 103 keyboard_.reset(new ui::KeyboardEvdev( | 106 keyboard_.reset(new ui::KeyboardEvdev( |
| 104 modifiers_.get(), | 107 modifiers_.get(), |
| 105 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), callback)); | 108 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), callback)); |
| 106 device_.reset(new ui::MockEventConverterEvdevImpl( | 109 device_.reset(new ui::MockEventConverterEvdevImpl( |
| 107 events_in_, modifiers_.get(), button_map_.get(), cursor_.get(), | 110 events_in_, modifiers_.get(), button_map_.get(), cursor_.get(), |
| 108 keyboard_.get(), callback)); | 111 key_callback, callback)); |
| 109 } | 112 } |
| 110 void TearDown() override { | 113 void TearDown() override { |
| 111 device_.reset(); | 114 device_.reset(); |
| 112 keyboard_.reset(); | 115 keyboard_.reset(); |
| 113 modifiers_.reset(); | 116 modifiers_.reset(); |
| 114 button_map_.reset(); | 117 button_map_.reset(); |
| 115 cursor_.reset(); | 118 cursor_.reset(); |
| 116 close(events_in_); | 119 close(events_in_); |
| 117 close(events_out_); | 120 close(events_out_); |
| 118 } | 121 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 134 ui::Event* ev = dispatched_events_[index]; | 137 ui::Event* ev = dispatched_events_[index]; |
| 135 DCHECK(ev->IsMouseEvent()); | 138 DCHECK(ev->IsMouseEvent()); |
| 136 return static_cast<ui::MouseEvent*>(ev); | 139 return static_cast<ui::MouseEvent*>(ev); |
| 137 } | 140 } |
| 138 | 141 |
| 139 private: | 142 private: |
| 140 void DispatchEventForTest(scoped_ptr<ui::Event> event) { | 143 void DispatchEventForTest(scoped_ptr<ui::Event> event) { |
| 141 dispatched_events_.push_back(event.release()); | 144 dispatched_events_.push_back(event.release()); |
| 142 } | 145 } |
| 143 | 146 |
| 147 void DispatchKeyEventForTest(const ui::KeyEventParams& params) { |
| 148 keyboard_->OnKeyChange(params.code, params.down); |
| 149 } |
| 150 |
| 144 base::MessageLoopForUI ui_loop_; | 151 base::MessageLoopForUI ui_loop_; |
| 145 | 152 |
| 146 scoped_ptr<ui::MockCursorEvdev> cursor_; | 153 scoped_ptr<ui::MockCursorEvdev> cursor_; |
| 147 scoped_ptr<ui::EventModifiersEvdev> modifiers_; | 154 scoped_ptr<ui::EventModifiersEvdev> modifiers_; |
| 148 scoped_ptr<ui::MouseButtonMapEvdev> button_map_; | 155 scoped_ptr<ui::MouseButtonMapEvdev> button_map_; |
| 149 scoped_ptr<ui::KeyboardEvdev> keyboard_; | 156 scoped_ptr<ui::KeyboardEvdev> keyboard_; |
| 150 scoped_ptr<ui::MockEventConverterEvdevImpl> device_; | 157 scoped_ptr<ui::MockEventConverterEvdevImpl> device_; |
| 151 | 158 |
| 152 ScopedVector<ui::Event> dispatched_events_; | 159 ScopedVector<ui::Event> dispatched_events_; |
| 153 | 160 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 {{0, 0}, EV_KEY, BTN_TOUCH, 1}, | 464 {{0, 0}, EV_KEY, BTN_TOUCH, 1}, |
| 458 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 465 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 459 | 466 |
| 460 {{0, 0}, EV_KEY, BTN_TOUCH, 0}, | 467 {{0, 0}, EV_KEY, BTN_TOUCH, 0}, |
| 461 {{0, 0}, EV_SYN, SYN_REPORT, 0}, | 468 {{0, 0}, EV_SYN, SYN_REPORT, 0}, |
| 462 }; | 469 }; |
| 463 | 470 |
| 464 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); | 471 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); |
| 465 EXPECT_EQ(0u, size()); | 472 EXPECT_EQ(0u, size()); |
| 466 } | 473 } |
| OLD | NEW |