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

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: Move declaration of WaylandWindow::FromSurface to top of class Created 4 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
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 private:
60 wl::FakeServer server;
61 bool initialized = false;
62
63 protected:
64 WaylandDisplay display;
65 MockPlatformWindowDelegate delegate;
66 WaylandWindow window;
67
68 wl::MockPointer* pointer;
69 wl::MockSurface* surface;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest);
73 };
74
75 TEST_F(WaylandPointerTest, Leave) {
76 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
77 wl_pointer_send_leave(pointer->resource(), 2, surface->resource());
78 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT,
spang 2016/02/24 16:42:21 How can you get a button when the pointer isn't ov
Michael Forney 2016/02/24 19:32:21 If there are multiple platform windows created, so
spang 2016/02/25 23:14:32 Ok, let's do the 2 window test then so it's clear
Michael Forney 2016/02/26 01:25:52 Done. This also helped me find a bug where we mig
79 WL_POINTER_BUTTON_STATE_PRESSED);
80 EXPECT_CALL(delegate, DispatchEvent(_)).Times(0);
81 }
82
83 ACTION_P(CloneEvent, ptr) {
84 *ptr = Event::Clone(*arg0);
85 }
86
87 TEST_F(WaylandPointerTest, Motion) {
88 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
89 wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75),
90 wl_fixed_from_double(20.375));
91
92 scoped_ptr<Event> event;
93 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
94
95 Sync();
96
97 ASSERT_TRUE(event);
98 ASSERT_TRUE(event->IsMouseEvent());
99 auto mouse_event = static_cast<MouseEvent*>(event.get());
100 EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type());
101 EXPECT_EQ(0, mouse_event->button_flags());
102 EXPECT_EQ(0, mouse_event->changed_button_flags());
103 // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional
104 // coordinates sent above.
105 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f());
106 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f());
107 }
108
109 TEST_F(WaylandPointerTest, MotionDragged) {
110 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0);
111 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE,
112 WL_POINTER_BUTTON_STATE_PRESSED);
113
114 Sync();
115
116 scoped_ptr<Event> event;
117 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
118 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400),
119 wl_fixed_from_int(500));
120
121 Sync();
122
123 ASSERT_TRUE(event);
124 ASSERT_TRUE(event->IsMouseEvent());
125 auto mouse_event = static_cast<MouseEvent*>(event.get());
126 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type());
127 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags());
128 EXPECT_EQ(0, mouse_event->changed_button_flags());
129 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f());
130 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f());
131 }
132
133 TEST_F(WaylandPointerTest, ButtonPress) {
134 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
135 wl_fixed_from_int(200), wl_fixed_from_int(150));
136 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT,
137 WL_POINTER_BUTTON_STATE_PRESSED);
138
139 Sync();
140
141 scoped_ptr<Event> event;
142 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
143 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT,
144 WL_POINTER_BUTTON_STATE_PRESSED);
145
146 Sync();
147
148 ASSERT_TRUE(event);
149 ASSERT_TRUE(event->IsMouseEvent());
150 auto mouse_event = static_cast<MouseEvent*>(event.get());
151 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type());
152 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON,
153 mouse_event->button_flags());
154 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags());
155 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f());
156 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f());
157 }
158
159 TEST_F(WaylandPointerTest, ButtonRelease) {
160 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
161 wl_fixed_from_int(50), wl_fixed_from_int(50));
162 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK,
163 WL_POINTER_BUTTON_STATE_PRESSED);
164 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT,
165 WL_POINTER_BUTTON_STATE_PRESSED);
166
167 Sync();
168
169 scoped_ptr<Event> event;
170 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
171 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT,
172 WL_POINTER_BUTTON_STATE_RELEASED);
173
174 Sync();
175
176 ASSERT_TRUE(event);
177 ASSERT_TRUE(event->IsMouseEvent());
178 auto mouse_event = static_cast<MouseEvent*>(event.get());
179 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type());
180 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON,
181 mouse_event->button_flags());
182 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags());
183 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f());
184 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f());
185 }
186
187 TEST_F(WaylandPointerTest, AxisVertical) {
188 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
189 wl_fixed_from_int(0), wl_fixed_from_int(0));
190 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT,
191 WL_POINTER_BUTTON_STATE_PRESSED);
192
193 Sync();
194
195 scoped_ptr<Event> event;
196 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
197 // Wayland servers typically send a value of 10 per mouse wheel click.
198 wl_pointer_send_axis(pointer->resource(), 1003,
199 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20));
200
201 Sync();
202
203 ASSERT_TRUE(event);
204 ASSERT_TRUE(event->IsMouseWheelEvent());
205 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get());
206 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta),
207 mouse_wheel_event->offset());
208 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags());
209 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags());
210 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f());
211 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f());
212 }
213
214 TEST_F(WaylandPointerTest, AxisHorizontal) {
215 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(),
216 wl_fixed_from_int(50), wl_fixed_from_int(75));
217 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT,
218 WL_POINTER_BUTTON_STATE_PRESSED);
219
220 Sync();
221
222 scoped_ptr<Event> event;
223 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event));
224 // Wayland servers typically send a value of 10 per mouse wheel click.
225 wl_pointer_send_axis(pointer->resource(), 1003,
226 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
227 wl_fixed_from_int(10));
228
229 Sync();
230
231 ASSERT_TRUE(event);
232 ASSERT_TRUE(event->IsMouseWheelEvent());
233 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get());
234 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0),
235 mouse_wheel_event->offset());
236 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags());
237 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags());
238 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f());
239 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f());
240 }
241
242 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698