Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc

Issue 874723002: [PATCH 9/11] ozone: evdev: Add a device event dispatcher that forwards to UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/ozone/evdev/event_converter_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/device/device_manager.h" 14 #include "ui/events/ozone/device/device_manager.h"
15 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" 15 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
16 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" 16 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h"
17 #include "ui/events/ozone/evdev/event_converter_test_util.h"
17 #include "ui/events/ozone/evdev/event_factory_evdev.h" 18 #include "ui/events/ozone/evdev/event_factory_evdev.h"
18 #include "ui/events/ozone/evdev/keyboard_evdev.h" 19 #include "ui/events/ozone/evdev/keyboard_evdev.h"
19 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" 20 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
20 21
21 namespace ui { 22 namespace ui {
22 23
23 const char kTestDevicePath[] = "/dev/input/test-device"; 24 const char kTestDevicePath[] = "/dev/input/test-device";
24 25
25 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl { 26 class MockEventConverterEvdevImpl : public EventConverterEvdevImpl {
26 public: 27 public:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 66 }
66 gfx::PointF GetLocation() override { return cursor_location_; } 67 gfx::PointF GetLocation() override { return cursor_location_; }
67 68
68 private: 69 private:
69 // The location of the mock cursor. 70 // The location of the mock cursor.
70 gfx::PointF cursor_location_; 71 gfx::PointF cursor_location_;
71 72
72 DISALLOW_COPY_AND_ASSIGN(MockCursorEvdev); 73 DISALLOW_COPY_AND_ASSIGN(MockCursorEvdev);
73 }; 74 };
74 75
75 class MockDeviceManager : public ui::DeviceManager {
76 public:
77 MockDeviceManager() {}
78 ~MockDeviceManager() override {}
79
80 // DeviceManager:
81 void ScanDevices(DeviceEventObserver* observer) override {}
82 void AddObserver(DeviceEventObserver* observer) override {}
83 void RemoveObserver(DeviceEventObserver* observer) override {}
84 };
85
86 class TestEventFactoryEvdev : public EventFactoryEvdev {
87 public:
88 TestEventFactoryEvdev(CursorDelegateEvdev* cursor,
89 DeviceManager* device_manager,
90 KeyboardLayoutEngine* keyboard_layout_engine,
91 const EventDispatchCallback& callback)
92 : EventFactoryEvdev(cursor, device_manager, keyboard_layout_engine),
93 callback_(callback) {}
94 ~TestEventFactoryEvdev() override {}
95
96 private:
97 void PostUiEvent(scoped_ptr<Event> event) override {
98 callback_.Run(event.Pass());
99 }
100
101 EventDispatchCallback callback_;
102 };
103
104 } // namespace ui 76 } // namespace ui
105 77
106 // Test fixture. 78 // Test fixture.
107 class EventConverterEvdevImplTest : public testing::Test { 79 class EventConverterEvdevImplTest : public testing::Test {
108 public: 80 public:
109 EventConverterEvdevImplTest() {} 81 EventConverterEvdevImplTest() {}
110 82
111 // Overridden from testing::Test: 83 // Overridden from testing::Test:
112 void SetUp() override { 84 void SetUp() override {
113 // Set up pipe to satisfy message pump (unused). 85 // Set up pipe to satisfy message pump (unused).
114 int evdev_io[2]; 86 int evdev_io[2];
115 if (pipe(evdev_io)) 87 if (pipe(evdev_io))
116 PLOG(FATAL) << "failed pipe"; 88 PLOG(FATAL) << "failed pipe";
117 events_in_ = evdev_io[0]; 89 events_in_ = evdev_io[0];
118 events_out_ = evdev_io[1]; 90 events_out_ = evdev_io[1];
119 91
120 cursor_.reset(new ui::MockCursorEvdev()); 92 cursor_.reset(new ui::MockCursorEvdev());
121 device_manager_.reset(new ui::MockDeviceManager()); 93
122 event_factory_.reset(new ui::TestEventFactoryEvdev( 94 device_manager_ = ui::CreateDeviceManagerForTest();
95 event_factory_ = ui::CreateEventFactoryEvdevForTest(
123 cursor_.get(), device_manager_.get(), 96 cursor_.get(), device_manager_.get(),
124 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), 97 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
125 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest, 98 base::Bind(&EventConverterEvdevImplTest::DispatchEventForTest,
126 base::Unretained(this)))); 99 base::Unretained(this)));
100 dispatcher_ =
101 ui::CreateDeviceEventDispatcherEvdevForTest(event_factory_.get());
102 device_.reset(new ui::MockEventConverterEvdevImpl(events_in_, cursor_.get(),
103 dispatcher_.get()));
104 }
127 105
128 device_.reset(new ui::MockEventConverterEvdevImpl(events_in_, cursor_.get(),
129 event_factory_.get()));
130 }
131 void TearDown() override { 106 void TearDown() override {
132 device_.reset(); 107 device_.reset();
133 cursor_.reset(); 108 cursor_.reset();
134 close(events_in_); 109 close(events_in_);
135 close(events_out_); 110 close(events_out_);
136 } 111 }
137 112
138 ui::MockCursorEvdev* cursor() { return cursor_.get(); } 113 ui::MockCursorEvdev* cursor() { return cursor_.get(); }
139 ui::MockEventConverterEvdevImpl* device() { return device_.get(); } 114 ui::MockEventConverterEvdevImpl* device() { return device_.get(); }
140 115
(...skipping 14 matching lines...) Expand all
155 private: 130 private:
156 void DispatchEventForTest(scoped_ptr<ui::Event> event) { 131 void DispatchEventForTest(scoped_ptr<ui::Event> event) {
157 dispatched_events_.push_back(event.release()); 132 dispatched_events_.push_back(event.release());
158 } 133 }
159 134
160 base::MessageLoopForUI ui_loop_; 135 base::MessageLoopForUI ui_loop_;
161 136
162 scoped_ptr<ui::MockCursorEvdev> cursor_; 137 scoped_ptr<ui::MockCursorEvdev> cursor_;
163 scoped_ptr<ui::DeviceManager> device_manager_; 138 scoped_ptr<ui::DeviceManager> device_manager_;
164 scoped_ptr<ui::EventFactoryEvdev> event_factory_; 139 scoped_ptr<ui::EventFactoryEvdev> event_factory_;
140 scoped_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_;
165 scoped_ptr<ui::MockEventConverterEvdevImpl> device_; 141 scoped_ptr<ui::MockEventConverterEvdevImpl> device_;
166 142
167 ScopedVector<ui::Event> dispatched_events_; 143 ScopedVector<ui::Event> dispatched_events_;
168 144
169 int events_out_; 145 int events_out_;
170 int events_in_; 146 int events_in_;
171 147
172 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest); 148 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest);
173 }; 149 };
174 150
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 {{0, 0}, EV_KEY, BTN_TOUCH, 1}, 448 {{0, 0}, EV_KEY, BTN_TOUCH, 1},
473 {{0, 0}, EV_SYN, SYN_REPORT, 0}, 449 {{0, 0}, EV_SYN, SYN_REPORT, 0},
474 450
475 {{0, 0}, EV_KEY, BTN_TOUCH, 0}, 451 {{0, 0}, EV_KEY, BTN_TOUCH, 0},
476 {{0, 0}, EV_SYN, SYN_REPORT, 0}, 452 {{0, 0}, EV_SYN, SYN_REPORT, 0},
477 }; 453 };
478 454
479 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue)); 455 dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
480 EXPECT_EQ(0u, size()); 456 EXPECT_EQ(0u, size());
481 } 457 }
OLDNEW
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/ozone/evdev/event_converter_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698