6 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
9 #include <gdk/gdkwayland.h>
13 #include "gtest/gtest.h"
15 TEST(FlScrollingManagerTest, DiscreteDirectional) {
19 g_autoptr(GError)
error =
nullptr;
21 EXPECT_EQ(
error,
nullptr);
23 std::vector<FlutterPointerEvent> pointer_events;
26 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
27 size_t events_count) {
28 for (
size_t i = 0;
i < events_count;
i++) {
29 pointer_events.push_back(events[
i]);
38 GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(),
"input-source",
39 GDK_SOURCE_MOUSE,
nullptr));
40 GdkEventScroll*
event =
41 reinterpret_cast<GdkEventScroll*
>(gdk_event_new(GDK_SCROLL));
45 event->device = mouse;
46 event->direction = GDK_SCROLL_UP;
48 EXPECT_EQ(pointer_events.size(), 1u);
49 EXPECT_EQ(pointer_events[0].x, 4.0);
50 EXPECT_EQ(pointer_events[0].y, 8.0);
51 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
52 EXPECT_EQ(pointer_events[0].timestamp,
54 EXPECT_EQ(pointer_events[0].scroll_delta_x, 0);
55 EXPECT_EQ(pointer_events[0].scroll_delta_y, 53 * -1.0);
56 event->direction = GDK_SCROLL_DOWN;
58 EXPECT_EQ(pointer_events.size(), 2u);
59 EXPECT_EQ(pointer_events[1].x, 4.0);
60 EXPECT_EQ(pointer_events[1].y, 8.0);
61 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
62 EXPECT_EQ(pointer_events[1].timestamp,
64 EXPECT_EQ(pointer_events[1].scroll_delta_x, 0);
65 EXPECT_EQ(pointer_events[1].scroll_delta_y, 53 * 1.0);
66 event->direction = GDK_SCROLL_LEFT;
68 EXPECT_EQ(pointer_events.size(), 3u);
69 EXPECT_EQ(pointer_events[2].x, 4.0);
70 EXPECT_EQ(pointer_events[2].y, 8.0);
71 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
72 EXPECT_EQ(pointer_events[2].timestamp,
74 EXPECT_EQ(pointer_events[2].scroll_delta_x, 53 * -1.0);
75 EXPECT_EQ(pointer_events[2].scroll_delta_y, 0);
76 event->direction = GDK_SCROLL_RIGHT;
78 EXPECT_EQ(pointer_events.size(), 4u);
79 EXPECT_EQ(pointer_events[3].x, 4.0);
80 EXPECT_EQ(pointer_events[3].y, 8.0);
81 EXPECT_EQ(pointer_events[3].device_kind, kFlutterPointerDeviceKindMouse);
82 EXPECT_EQ(pointer_events[3].timestamp,
84 EXPECT_EQ(pointer_events[3].scroll_delta_x, 53 * 1.0);
85 EXPECT_EQ(pointer_events[3].scroll_delta_y, 0);
88 TEST(FlScrollingManagerTest, DiscreteScrolling) {
92 g_autoptr(GError)
error =
nullptr;
94 EXPECT_EQ(
error,
nullptr);
96 std::vector<FlutterPointerEvent> pointer_events;
99 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
100 size_t events_count) {
101 for (
size_t i = 0;
i < events_count;
i++) {
102 pointer_events.push_back(events[
i]);
111 GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(),
"input-source",
112 GDK_SOURCE_MOUSE,
nullptr));
113 GdkEventScroll*
event =
114 reinterpret_cast<GdkEventScroll*
>(gdk_event_new(GDK_SCROLL));
118 event->delta_x = 1.0;
119 event->delta_y = 2.0;
120 event->device = mouse;
121 event->direction = GDK_SCROLL_SMOOTH;
123 EXPECT_EQ(pointer_events.size(), 1u);
124 EXPECT_EQ(pointer_events[0].x, 4.0);
125 EXPECT_EQ(pointer_events[0].y, 8.0);
126 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
127 EXPECT_EQ(pointer_events[0].timestamp,
129 EXPECT_EQ(pointer_events[0].scroll_delta_x, 53 * 1.0);
130 EXPECT_EQ(pointer_events[0].scroll_delta_y, 53 * 2.0);
133 TEST(FlScrollingManagerTest, Panning) {
137 g_autoptr(GError)
error =
nullptr;
139 EXPECT_EQ(
error,
nullptr);
141 std::vector<FlutterPointerEvent> pointer_events;
144 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
145 size_t events_count) {
146 for (
size_t i = 0;
i < events_count;
i++) {
147 pointer_events.push_back(events[
i]);
155 GdkDevice* touchpad =
156 GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(),
"input-source",
157 GDK_SOURCE_TOUCHPAD,
nullptr));
158 GdkEventScroll*
event =
159 reinterpret_cast<GdkEventScroll*
>(gdk_event_new(GDK_SCROLL));
163 event->delta_x = 1.0;
164 event->delta_y = 2.0;
165 event->device = touchpad;
166 event->direction = GDK_SCROLL_SMOOTH;
168 EXPECT_EQ(pointer_events.size(), 2u);
169 EXPECT_EQ(pointer_events[0].x, 4.0);
170 EXPECT_EQ(pointer_events[0].y, 8.0);
171 EXPECT_EQ(pointer_events[0].timestamp,
173 EXPECT_EQ(pointer_events[0].phase, kPanZoomStart);
174 EXPECT_EQ(pointer_events[1].x, 4.0);
175 EXPECT_EQ(pointer_events[1].y, 8.0);
176 EXPECT_EQ(pointer_events[1].timestamp,
178 EXPECT_EQ(pointer_events[1].phase, kPanZoomUpdate);
179 EXPECT_EQ(pointer_events[1].pan_x, 53 * -1.0);
180 EXPECT_EQ(pointer_events[1].pan_y, 53 * -2.0);
181 EXPECT_EQ(pointer_events[1].scale, 1.0);
182 EXPECT_EQ(pointer_events[1].rotation, 0.0);
184 EXPECT_EQ(pointer_events.size(), 3u);
185 EXPECT_EQ(pointer_events[2].x, 4.0);
186 EXPECT_EQ(pointer_events[2].y, 8.0);
187 EXPECT_EQ(pointer_events[2].timestamp,
189 EXPECT_EQ(pointer_events[2].phase, kPanZoomUpdate);
190 EXPECT_EQ(pointer_events[2].pan_x, 53 * -2.0);
191 EXPECT_EQ(pointer_events[2].pan_y, 53 * -4.0);
192 EXPECT_EQ(pointer_events[2].scale, 1.0);
193 EXPECT_EQ(pointer_events[2].rotation, 0.0);
194 event->is_stop =
true;
196 EXPECT_EQ(pointer_events.size(), 4u);
197 EXPECT_EQ(pointer_events[3].x, 4.0);
198 EXPECT_EQ(pointer_events[3].y, 8.0);
199 EXPECT_EQ(pointer_events[3].timestamp,
201 EXPECT_EQ(pointer_events[3].phase, kPanZoomEnd);
204 TEST(FlScrollingManagerTest, Zooming) {
208 g_autoptr(GError)
error =
nullptr;
210 EXPECT_EQ(
error,
nullptr);
212 std::vector<FlutterPointerEvent> pointer_events;
215 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
216 size_t events_count) {
217 for (
size_t i = 0;
i < events_count;
i++) {
218 pointer_events.push_back(events[
i]);
226 size_t time_start = g_get_real_time();
228 EXPECT_EQ(pointer_events.size(), 1u);
229 EXPECT_EQ(pointer_events[0].x, 0);
230 EXPECT_EQ(pointer_events[0].y, 0);
231 EXPECT_EQ(pointer_events[0].phase, kPanZoomStart);
232 EXPECT_GE(pointer_events[0].timestamp, time_start);
234 EXPECT_EQ(pointer_events.size(), 2u);
235 EXPECT_EQ(pointer_events[1].x, 0);
236 EXPECT_EQ(pointer_events[1].y, 0);
237 EXPECT_EQ(pointer_events[1].phase, kPanZoomUpdate);
238 EXPECT_GE(pointer_events[1].timestamp, pointer_events[0].timestamp);
239 EXPECT_EQ(pointer_events[1].pan_x, 0);
240 EXPECT_EQ(pointer_events[1].pan_y, 0);
241 EXPECT_EQ(pointer_events[1].scale, 1.1);
242 EXPECT_EQ(pointer_events[1].rotation, 0);
244 EXPECT_EQ(pointer_events.size(), 3u);
245 EXPECT_EQ(pointer_events[2].x, 0);
246 EXPECT_EQ(pointer_events[2].y, 0);
247 EXPECT_EQ(pointer_events[2].phase, kPanZoomEnd);
248 EXPECT_GE(pointer_events[2].timestamp, pointer_events[1].timestamp);
251 TEST(FlScrollingManagerTest, Rotating) {
255 g_autoptr(GError)
error =
nullptr;
257 EXPECT_EQ(
error,
nullptr);
259 std::vector<FlutterPointerEvent> pointer_events;
262 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
263 size_t events_count) {
264 for (
size_t i = 0;
i < events_count;
i++) {
265 pointer_events.push_back(events[
i]);
273 size_t time_start = g_get_real_time();
275 EXPECT_EQ(pointer_events.size(), 1u);
276 EXPECT_EQ(pointer_events[0].x, 0);
277 EXPECT_EQ(pointer_events[0].y, 0);
278 EXPECT_EQ(pointer_events[0].phase, kPanZoomStart);
279 EXPECT_GE(pointer_events[0].timestamp, time_start);
281 EXPECT_EQ(pointer_events.size(), 2u);
282 EXPECT_EQ(pointer_events[1].x, 0);
283 EXPECT_EQ(pointer_events[1].y, 0);
284 EXPECT_EQ(pointer_events[1].phase, kPanZoomUpdate);
285 EXPECT_GE(pointer_events[1].timestamp, pointer_events[0].timestamp);
286 EXPECT_EQ(pointer_events[1].pan_x, 0);
287 EXPECT_EQ(pointer_events[1].pan_y, 0);
288 EXPECT_EQ(pointer_events[1].scale, 1.0);
289 EXPECT_EQ(pointer_events[1].rotation, 0.5);
291 EXPECT_EQ(pointer_events.size(), 3u);
292 EXPECT_EQ(pointer_events[2].x, 0);
293 EXPECT_EQ(pointer_events[2].y, 0);
294 EXPECT_EQ(pointer_events[2].phase, kPanZoomEnd);
295 EXPECT_GE(pointer_events[2].timestamp, pointer_events[1].timestamp);
298 TEST(FlScrollingManagerTest, SynchronizedZoomingAndRotating) {
302 g_autoptr(GError)
error =
nullptr;
304 EXPECT_EQ(
error,
nullptr);
306 std::vector<FlutterPointerEvent> pointer_events;
309 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
310 size_t events_count) {
311 for (
size_t i = 0;
i < events_count;
i++) {
312 pointer_events.push_back(events[
i]);
320 size_t time_start = g_get_real_time();
322 EXPECT_EQ(pointer_events.size(), 1u);
323 EXPECT_EQ(pointer_events[0].x, 0);
324 EXPECT_EQ(pointer_events[0].y, 0);
325 EXPECT_EQ(pointer_events[0].phase, kPanZoomStart);
326 EXPECT_GE(pointer_events[0].timestamp, time_start);
328 EXPECT_EQ(pointer_events.size(), 2u);
329 EXPECT_EQ(pointer_events[1].x, 0);
330 EXPECT_EQ(pointer_events[1].y, 0);
331 EXPECT_EQ(pointer_events[1].phase, kPanZoomUpdate);
332 EXPECT_GE(pointer_events[1].timestamp, pointer_events[0].timestamp);
333 EXPECT_EQ(pointer_events[1].pan_x, 0);
334 EXPECT_EQ(pointer_events[1].pan_y, 0);
335 EXPECT_EQ(pointer_events[1].scale, 1.1);
336 EXPECT_EQ(pointer_events[1].rotation, 0);
338 EXPECT_EQ(pointer_events.size(), 2u);
340 EXPECT_EQ(pointer_events.size(), 3u);
341 EXPECT_EQ(pointer_events[2].x, 0);
342 EXPECT_EQ(pointer_events[2].y, 0);
343 EXPECT_EQ(pointer_events[2].phase, kPanZoomUpdate);
344 EXPECT_GE(pointer_events[2].timestamp, pointer_events[1].timestamp);
345 EXPECT_EQ(pointer_events[2].pan_x, 0);
346 EXPECT_EQ(pointer_events[2].pan_y, 0);
347 EXPECT_EQ(pointer_events[2].scale, 1.1);
348 EXPECT_EQ(pointer_events[2].rotation, 0.5);
351 EXPECT_EQ(pointer_events.size(), 3u);
353 EXPECT_EQ(pointer_events.size(), 4u);
354 EXPECT_EQ(pointer_events[3].x, 0);
355 EXPECT_EQ(pointer_events[3].y, 0);
356 EXPECT_EQ(pointer_events[3].phase, kPanZoomEnd);
357 EXPECT_GE(pointer_events[3].timestamp, pointer_events[2].timestamp);
362 TEST(FlScrollingManagerTest, UnsynchronizedZoomingAndRotating) {
366 g_autoptr(GError)
error =
nullptr;
368 EXPECT_EQ(
error,
nullptr);
370 std::vector<FlutterPointerEvent> pointer_events;
373 ([&pointer_events](
auto engine,
const FlutterPointerEvent* events,
374 size_t events_count) {
375 for (
size_t i = 0;
i < events_count;
i++) {
376 pointer_events.push_back(events[
i]);
384 size_t time_start = g_get_real_time();
386 EXPECT_EQ(pointer_events.size(), 1u);
387 EXPECT_EQ(pointer_events[0].x, 0);
388 EXPECT_EQ(pointer_events[0].y, 0);
389 EXPECT_EQ(pointer_events[0].phase, kPanZoomStart);
390 EXPECT_GE(pointer_events[0].timestamp, time_start);
392 EXPECT_EQ(pointer_events.size(), 2u);
393 EXPECT_EQ(pointer_events[1].x, 0);
394 EXPECT_EQ(pointer_events[1].y, 0);
395 EXPECT_EQ(pointer_events[1].phase, kPanZoomUpdate);
396 EXPECT_GE(pointer_events[1].timestamp, pointer_events[0].timestamp);
397 EXPECT_EQ(pointer_events[1].pan_x, 0);
398 EXPECT_EQ(pointer_events[1].pan_y, 0);
399 EXPECT_EQ(pointer_events[1].scale, 1.1);
400 EXPECT_EQ(pointer_events[1].rotation, 0);
402 EXPECT_EQ(pointer_events.size(), 2u);
404 EXPECT_EQ(pointer_events.size(), 3u);
405 EXPECT_EQ(pointer_events[2].x, 0);
406 EXPECT_EQ(pointer_events[2].y, 0);
407 EXPECT_EQ(pointer_events[2].phase, kPanZoomUpdate);
408 EXPECT_GE(pointer_events[2].timestamp, pointer_events[1].timestamp);
409 EXPECT_EQ(pointer_events[2].pan_x, 0);
410 EXPECT_EQ(pointer_events[2].pan_y, 0);
411 EXPECT_EQ(pointer_events[2].scale, 1.1);
412 EXPECT_EQ(pointer_events[2].rotation, 0.5);
414 EXPECT_EQ(pointer_events.size(), 3u);
416 EXPECT_EQ(pointer_events.size(), 4u);
417 EXPECT_EQ(pointer_events[3].x, 0);
418 EXPECT_EQ(pointer_events[3].y, 0);
419 EXPECT_EQ(pointer_events[3].phase, kPanZoomUpdate);
420 EXPECT_GE(pointer_events[3].timestamp, pointer_events[2].timestamp);
421 EXPECT_EQ(pointer_events[3].pan_x, 0);
422 EXPECT_EQ(pointer_events[3].pan_y, 0);
423 EXPECT_EQ(pointer_events[3].scale, 1.1);
424 EXPECT_EQ(pointer_events[3].rotation, 1.0);
426 EXPECT_EQ(pointer_events.size(), 5u);
427 EXPECT_EQ(pointer_events[4].x, 0);
428 EXPECT_EQ(pointer_events[4].y, 0);
429 EXPECT_EQ(pointer_events[4].phase, kPanZoomEnd);
430 EXPECT_GE(pointer_events[4].timestamp, pointer_events[3].timestamp);