| 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 "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 6 | 6 |
| 7 #include <linux/input.h> | 7 #include <linux/input.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 #include "ui/events/keycodes/dom/dom_code.h" | 18 #include "ui/events/keycodes/dom/dom_code.h" |
| 19 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
| 20 #include "ui/events/ozone/device/device_manager.h" | 20 #include "ui/events/ozone/device/device_manager.h" |
| 21 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 21 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 22 #include "ui/events/ozone/evdev/event_converter_test_util.h" | 22 #include "ui/events/ozone/evdev/event_converter_test_util.h" |
| 23 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 23 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 24 #include "ui/events/ozone/evdev/keyboard_evdev.h" | 24 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
| 25 #include "ui/events/ozone/evdev/scoped_input_device.h" |
| 25 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 26 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 26 | 27 |
| 27 namespace ui { | 28 namespace ui { |
| 28 | 29 |
| 29 const char kTestDevicePath[] = "/dev/input/test-device"; | 30 const char kTestDevicePath[] = "/dev/input/test-device"; |
| 30 | 31 |
| 31 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl { | 32 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl { |
| 32 public: | 33 public: |
| 33 MockEventConverterEvdevImpl(int fd, | 34 MockEventConverterEvdevImpl(ScopedInputDevice fd, |
| 34 CursorDelegateEvdev* cursor, | 35 CursorDelegateEvdev* cursor, |
| 35 DeviceEventDispatcherEvdev* dispatcher) | 36 DeviceEventDispatcherEvdev* dispatcher) |
| 36 : EventConverterEvdevImpl(fd, | 37 : EventConverterEvdevImpl(std::move(fd), |
| 37 base::FilePath(kTestDevicePath), | 38 base::FilePath(kTestDevicePath), |
| 38 1, | 39 1, |
| 39 EventDeviceInfo(), | 40 EventDeviceInfo(), |
| 40 cursor, | 41 cursor, |
| 41 dispatcher) { | 42 dispatcher) { |
| 42 SetEnabled(true); | 43 SetEnabled(true); |
| 43 } | 44 } |
| 44 ~MockEventConverterEvdevImpl() override { SetEnabled(false); } | 45 ~MockEventConverterEvdevImpl() override { SetEnabled(false); } |
| 45 | 46 |
| 46 // EventConverterEvdevImpl: | 47 // EventConverterEvdevImpl: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 class EventConverterEvdevImplTest : public testing::Test { | 88 class EventConverterEvdevImplTest : public testing::Test { |
| 88 public: | 89 public: |
| 89 EventConverterEvdevImplTest() {} | 90 EventConverterEvdevImplTest() {} |
| 90 | 91 |
| 91 // Overridden from testing::Test: | 92 // Overridden from testing::Test: |
| 92 void SetUp() override { | 93 void SetUp() override { |
| 93 // Set up pipe to satisfy message pump (unused). | 94 // Set up pipe to satisfy message pump (unused). |
| 94 int evdev_io[2]; | 95 int evdev_io[2]; |
| 95 if (pipe(evdev_io)) | 96 if (pipe(evdev_io)) |
| 96 PLOG(FATAL) << "failed pipe"; | 97 PLOG(FATAL) << "failed pipe"; |
| 97 events_in_ = evdev_io[0]; | 98 ui::ScopedInputDevice events_in(evdev_io[0]); |
| 98 events_out_ = evdev_io[1]; | 99 events_out_.reset(evdev_io[1]); |
| 99 | 100 |
| 100 cursor_.reset(new ui::MockCursorEvdev()); | 101 cursor_.reset(new ui::MockCursorEvdev()); |
| 101 | 102 |
| 102 device_manager_ = ui::CreateDeviceManagerForTest(); | 103 device_manager_ = ui::CreateDeviceManagerForTest(); |
| 103 event_factory_ = ui::CreateEventFactoryEvdevForTest( | 104 event_factory_ = ui::CreateEventFactoryEvdevForTest( |
| 104 cursor_.get(), device_manager_.get(), | 105 cursor_.get(), device_manager_.get(), |
| 105 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), | 106 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), |
| 106 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest, | 107 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest, |
| 107 base::Unretained(this))); | 108 base::Unretained(this))); |
| 108 dispatcher_ = | 109 dispatcher_ = |
| 109 ui::CreateDeviceEventDispatcherEvdevForTest(event_factory_.get()); | 110 ui::CreateDeviceEventDispatcherEvdevForTest(event_factory_.get()); |
| 110 device_.reset(new ui::MockEventConverterEvdevImpl(events_in_, cursor_.get(), | 111 device_.reset(new ui::MockEventConverterEvdevImpl( |
| 111 dispatcher_.get())); | 112 std::move(events_in), cursor_.get(), dispatcher_.get())); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void TearDown() override { | 115 void TearDown() override { |
| 115 device_.reset(); | 116 device_.reset(); |
| 116 cursor_.reset(); | 117 cursor_.reset(); |
| 117 close(events_in_); | 118 events_out_.reset(); |
| 118 close(events_out_); | |
| 119 } | 119 } |
| 120 | 120 |
| 121 ui::MockCursorEvdev* cursor() { return cursor_.get(); } | 121 ui::MockCursorEvdev* cursor() { return cursor_.get(); } |
| 122 ui::MockEventConverterEvdevImpl* device() { return device_.get(); } | 122 ui::MockEventConverterEvdevImpl* device() { return device_.get(); } |
| 123 | 123 |
| 124 unsigned size() { return dispatched_events_.size(); } | 124 unsigned size() { return dispatched_events_.size(); } |
| 125 ui::KeyEvent* dispatched_event(unsigned index) { | 125 ui::KeyEvent* dispatched_event(unsigned index) { |
| 126 DCHECK_GT(dispatched_events_.size(), index); | 126 DCHECK_GT(dispatched_events_.size(), index); |
| 127 ui::Event* ev = dispatched_events_[index].get(); | 127 ui::Event* ev = dispatched_events_[index].get(); |
| 128 DCHECK(ev->IsKeyEvent()); | 128 DCHECK(ev->IsKeyEvent()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 150 base::MessageLoopForUI ui_loop_; | 150 base::MessageLoopForUI ui_loop_; |
| 151 | 151 |
| 152 std::unique_ptr<ui::MockCursorEvdev> cursor_; | 152 std::unique_ptr<ui::MockCursorEvdev> cursor_; |
| 153 std::unique_ptr<ui::DeviceManager> device_manager_; | 153 std::unique_ptr<ui::DeviceManager> device_manager_; |
| 154 std::unique_ptr<ui::EventFactoryEvdev> event_factory_; | 154 std::unique_ptr<ui::EventFactoryEvdev> event_factory_; |
| 155 std::unique_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_; | 155 std::unique_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_; |
| 156 std::unique_ptr<ui::MockEventConverterEvdevImpl> device_; | 156 std::unique_ptr<ui::MockEventConverterEvdevImpl> device_; |
| 157 | 157 |
| 158 std::vector<std::unique_ptr<ui::Event>> dispatched_events_; | 158 std::vector<std::unique_ptr<ui::Event>> dispatched_events_; |
| 159 | 159 |
| 160 int events_out_; | 160 ui::ScopedInputDevice events_out_; |
| 161 int events_in_; | |
| 162 | 161 |
| 163 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest); | 162 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest); |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 TEST_F(EventConverterEvdevImplTest, KeyPress) { | 165 TEST_F(EventConverterEvdevImplTest, KeyPress) { |
| 167 ui::MockEventConverterEvdevImpl* dev = device(); | 166 ui::MockEventConverterEvdevImpl* dev = device(); |
| 168 | 167 |
| 169 struct input_event mock_kernel_queue[] = { | 168 struct input_event mock_kernel_queue[] = { |
| 170 {{0, 0}, EV_MSC, MSC_SCAN, 0x7002a}, | 169 {{0, 0}, EV_MSC, MSC_SCAN, 0x7002a}, |
| 171 {{0, 0}, EV_KEY, KEY_BACKSPACE, 1}, | 170 {{0, 0}, EV_KEY, KEY_BACKSPACE, 1}, |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 dev->SetKeyFilter(true /* enable_filter */, allowed_keys); | 658 dev->SetKeyFilter(true /* enable_filter */, allowed_keys); |
| 660 ASSERT_EQ(1u, size()); | 659 ASSERT_EQ(1u, size()); |
| 661 event = dispatched_event(0); | 660 event = dispatched_event(0); |
| 662 EXPECT_EQ(ui::ET_KEY_RELEASED, event->type()); | 661 EXPECT_EQ(ui::ET_KEY_RELEASED, event->type()); |
| 663 | 662 |
| 664 // The real key release should be dropped, whenever it comes. | 663 // The real key release should be dropped, whenever it comes. |
| 665 ClearDispatchedEvents(); | 664 ClearDispatchedEvents(); |
| 666 dev->ProcessEvents(key_release, arraysize(key_release)); | 665 dev->ProcessEvents(key_release, arraysize(key_release)); |
| 667 ASSERT_EQ(0u, size()); | 666 ASSERT_EQ(0u, size()); |
| 668 } | 667 } |
| OLD | NEW |