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

Side by Side Diff: ui/ozone/platform/wayland/wayland_pointer_unittest.cc

Issue 1712103002: ozone/platform/wayland: Implement pointer handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add second window for WaylandPointerTest.Leave, check for NULL surface in WaylandPointer::{Enter,Le… Created 4 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <linux/input.h>
6 #include <wayland-server.h>
7
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/event.h"
11 #include "ui/ozone/platform/wayland/fake_server.h"
12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h"
13 #include "ui/ozone/platform/wayland/wayland_display.h"
14 #include "ui/ozone/platform/wayland/wayland_window.h"
15
16 using ::testing::_;
17
18 namespace ui {
19
20 class WaylandPointerTest : public testing::Test {
21 public:
22 WaylandPointerTest()
23 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {}
24
25 void SetUp() override {
26 ASSERT_TRUE(server.Start());
27 ASSERT_TRUE(display.Initialize());
28 ASSERT_TRUE(window.Initialize());
29 wl_display_roundtrip(display.display());
30
31 server.Pause();
32
33 surface = server.GetObject<wl::MockSurface>(window.GetWidget());
34 ASSERT_TRUE(surface);
35 wl_seat_send_capabilities(server.seat()->resource(),
36 WL_SEAT_CAPABILITY_POINTER);
37 server.Flush();
38
39 Sync();
40
41 ASSERT_TRUE(surface->resource());
42 pointer = server.seat()->pointer.get();
43 ASSERT_TRUE(pointer);
44 initialized = true;
45 }
46
47 void TearDown() override {
48 server.Resume();
49 if (initialized)
50 wl_display_roundtrip(display.display());
51 }
52
53 void Sync() {
54 server.Resume();
55 wl_display_roundtrip(display.display());
56 server.Pause();
57 }
58
59 protected:
60 wl::FakeServer server;
61 WaylandDisplay display;
62 MockPlatformWindowDelegate delegate;
63 WaylandWindow window;
64
65 wl::MockPointer* pointer;
66 wl::MockSurface* surface;
67
68 private:
69 bool initialized = false;
70
71 DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest);
72 };
73
74 TEST_F(WaylandPointerTest, Leave) {
75 MockPlatformWindowDelegate other_delegate;
76 WaylandWindow other_window(&other_delegate, &display,
77 gfx::Rect(0, 0, 10, 10));
78 ASSERT_TRUE(other_window.Initialize());
79
80 Sync();
81
82 wl::MockSurface* other_surface =
83 server.GetObject<wl::MockSurface>(other_window.GetWidget());
84 ASSERT_TRUE(other_surface);
85
86 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
87 wl_pointer_send_leave(pointer->resource(), 2, surface->resource());
88 wl_pointer_send_enter(pointer->resource(), 3, other_surface->resource(), 0,
89 0);
90 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT,
91 WL_POINTER_BUTTON_STATE_PRESSED);
92 EXPECT_CALL(delegate, DispatchEvent(_)).Times(0);
93
94 // Do an extra Sync() here so that we process the second enter event before we
95 // destroy |other_window|.
96 Sync();
97 }
98
99 ACTION_P(CloneEvent, ptr) {
100 *ptr = Event::Clone(*arg0);
101 }
102
103 TEST_F(WaylandPointerTest, Motion) {
104 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
105 wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75),
106 wl_fixed_from_double(20.375));
107
108 scoped_ptr<Event> event;
109 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
110
111 Sync();
112
113 ASSERT_TRUE(event);
114 ASSERT_TRUE(event->IsMouseEvent());
115 auto mouse_event = static_cast<MouseEvent*>(event.get());
116 EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type());
117 EXPECT_EQ(0, mouse_event->button_flags());
118 EXPECT_EQ(0, mouse_event->changed_button_flags());
119 // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional
120 // coordinates sent above.
121 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f());
122 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f());
123 }
124
125 TEST_F(WaylandPointerTest, MotionDragged) {
126 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
127 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE,
128 WL_POINTER_BUTTON_STATE_PRESSED);
129
130 Sync();
131
132 scoped_ptr<Event> event;
133 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
134 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400),
135 wl_fixed_from_int(500));
136
137 Sync();
138
139 ASSERT_TRUE(event);
140 ASSERT_TRUE(event->IsMouseEvent());
141 auto mouse_event = static_cast<MouseEvent*>(event.get());
142 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type());
143 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags());
144 EXPECT_EQ(0, mouse_event->changed_button_flags());
145 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f());
146 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f());
147 }
148
149 TEST_F(WaylandPointerTest, ButtonPress) {
150 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
151 wl_fixed_from_int(200), wl_fixed_from_int(150));
152 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT,
153 WL_POINTER_BUTTON_STATE_PRESSED);
154
155 Sync();
156
157 scoped_ptr<Event> event;
158 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
159 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT,
160 WL_POINTER_BUTTON_STATE_PRESSED);
161
162 Sync();
163
164 ASSERT_TRUE(event);
165 ASSERT_TRUE(event->IsMouseEvent());
166 auto mouse_event = static_cast<MouseEvent*>(event.get());
167 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type());
168 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON,
169 mouse_event->button_flags());
170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags());
171 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f());
172 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f());
173 }
174
175 TEST_F(WaylandPointerTest, ButtonRelease) {
176 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
177 wl_fixed_from_int(50), wl_fixed_from_int(50));
178 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK,
179 WL_POINTER_BUTTON_STATE_PRESSED);
180 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT,
181 WL_POINTER_BUTTON_STATE_PRESSED);
182
183 Sync();
184
185 scoped_ptr<Event> event;
186 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
187 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT,
188 WL_POINTER_BUTTON_STATE_RELEASED);
189
190 Sync();
191
192 ASSERT_TRUE(event);
193 ASSERT_TRUE(event->IsMouseEvent());
194 auto mouse_event = static_cast<MouseEvent*>(event.get());
195 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type());
196 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON,
197 mouse_event->button_flags());
198 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags());
199 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f());
200 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f());
201 }
202
203 TEST_F(WaylandPointerTest, AxisVertical) {
204 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
205 wl_fixed_from_int(0), wl_fixed_from_int(0));
206 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT,
207 WL_POINTER_BUTTON_STATE_PRESSED);
208
209 Sync();
210
211 scoped_ptr<Event> event;
212 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
213 // Wayland servers typically send a value of 10 per mouse wheel click.
214 wl_pointer_send_axis(pointer->resource(), 1003,
215 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20));
216
217 Sync();
218
219 ASSERT_TRUE(event);
220 ASSERT_TRUE(event->IsMouseWheelEvent());
221 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get());
222 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta),
223 mouse_wheel_event->offset());
224 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags());
225 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags());
226 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f());
227 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f());
228 }
229
230 TEST_F(WaylandPointerTest, AxisHorizontal) {
231 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
232 wl_fixed_from_int(50), wl_fixed_from_int(75));
233 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT,
234 WL_POINTER_BUTTON_STATE_PRESSED);
235
236 Sync();
237
238 scoped_ptr<Event> event;
239 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
240 // Wayland servers typically send a value of 10 per mouse wheel click.
241 wl_pointer_send_axis(pointer->resource(), 1003,
242 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
243 wl_fixed_from_int(10));
244
245 Sync();
246
247 ASSERT_TRUE(event);
248 ASSERT_TRUE(event->IsMouseWheelEvent());
249 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get());
250 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0),
251 mouse_wheel_event->offset());
252 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags());
253 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags());
254 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f());
255 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f());
256 }
257
258 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698