| Flutter Linux Embedder |

fl_pointer_manager_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/shell/platform/linux/fl_pointer_manager.h"
6 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
7 #include "flutter/shell/platform/linux/fl_engine_private.h"
8
9 #include "gtest/gtest.h"
10
11 TEST(FlPointerManagerTest, EnterLeave) {
12 g_autoptr(FlDartProject) project = fl_dart_project_new();
13 g_autoptr(FlEngine) engine = fl_engine_new(project);
14
15 g_autoptr(GError) error = nullptr;
16 EXPECT_TRUE(fl_engine_start(engine, &error));
17 EXPECT_EQ(error, nullptr);
18
19 std::vector<FlutterPointerEvent> pointer_events;
20 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
21 SendPointerEvent,
22 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
23 size_t events_count) {
24 for (size_t i = 0; i < events_count; i++) {
25 pointer_events.push_back(events[i]);
26 }
27
28 return kSuccess;
29 }));
30
31 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
32 fl_pointer_manager_handle_enter(manager, 1234, kFlutterPointerDeviceKindMouse,
33 1.0, 2.0);
34 fl_pointer_manager_handle_leave(manager, 1235, kFlutterPointerDeviceKindMouse,
35 3.0, 4.0);
36
37 EXPECT_EQ(pointer_events.size(), 2u);
38
39 EXPECT_EQ(pointer_events[0].timestamp, 1234000u);
40 EXPECT_EQ(pointer_events[0].x, 1.0);
41 EXPECT_EQ(pointer_events[0].y, 2.0);
42 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
43 EXPECT_EQ(pointer_events[0].buttons, 0);
44 EXPECT_EQ(pointer_events[0].view_id, 42);
45
46 EXPECT_EQ(pointer_events[1].timestamp, 1235000u);
47 EXPECT_EQ(pointer_events[1].x, 3.0);
48 EXPECT_EQ(pointer_events[1].y, 4.0);
49 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
50 EXPECT_EQ(pointer_events[1].buttons, 0);
51 EXPECT_EQ(pointer_events[1].view_id, 42);
52 }
53
54 TEST(FlPointerManagerTest, EnterEnter) {
55 g_autoptr(FlDartProject) project = fl_dart_project_new();
56 g_autoptr(FlEngine) engine = fl_engine_new(project);
57
58 g_autoptr(GError) error = nullptr;
59 EXPECT_TRUE(fl_engine_start(engine, &error));
60 EXPECT_EQ(error, nullptr);
61
62 std::vector<FlutterPointerEvent> pointer_events;
63 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
64 SendPointerEvent,
65 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
66 size_t events_count) {
67 for (size_t i = 0; i < events_count; i++) {
68 pointer_events.push_back(events[i]);
69 }
70
71 return kSuccess;
72 }));
73
74 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
75 fl_pointer_manager_handle_enter(manager, 1234, kFlutterPointerDeviceKindMouse,
76 1.0, 2.0);
77 // Duplicate enter is ignored
78 fl_pointer_manager_handle_enter(manager, 1235, kFlutterPointerDeviceKindMouse,
79 3.0, 4.0);
80
81 EXPECT_EQ(pointer_events.size(), 1u);
82
83 EXPECT_EQ(pointer_events[0].timestamp, 1234000u);
84 EXPECT_EQ(pointer_events[0].x, 1.0);
85 EXPECT_EQ(pointer_events[0].y, 2.0);
86 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
87 EXPECT_EQ(pointer_events[0].buttons, 0);
88 EXPECT_EQ(pointer_events[0].view_id, 42);
89 }
90
91 TEST(FlPointerManagerTest, EnterLeaveLeave) {
92 g_autoptr(FlDartProject) project = fl_dart_project_new();
93 g_autoptr(FlEngine) engine = fl_engine_new(project);
94
95 g_autoptr(GError) error = nullptr;
96 EXPECT_TRUE(fl_engine_start(engine, &error));
97 EXPECT_EQ(error, nullptr);
98
99 std::vector<FlutterPointerEvent> pointer_events;
100 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
101 SendPointerEvent,
102 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
103 size_t events_count) {
104 for (size_t i = 0; i < events_count; i++) {
105 pointer_events.push_back(events[i]);
106 }
107
108 return kSuccess;
109 }));
110
111 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
112 fl_pointer_manager_handle_enter(manager, 1234, kFlutterPointerDeviceKindMouse,
113 1.0, 2.0);
114 fl_pointer_manager_handle_leave(manager, 1235, kFlutterPointerDeviceKindMouse,
115 3.0, 4.0);
116 // Duplicate leave is ignored
117 fl_pointer_manager_handle_leave(manager, 1235, kFlutterPointerDeviceKindMouse,
118 5.0, 6.0);
119
120 EXPECT_EQ(pointer_events.size(), 2u);
121
122 EXPECT_EQ(pointer_events[0].timestamp, 1234000u);
123 EXPECT_EQ(pointer_events[0].x, 1.0);
124 EXPECT_EQ(pointer_events[0].y, 2.0);
125 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
126 EXPECT_EQ(pointer_events[0].buttons, 0);
127 EXPECT_EQ(pointer_events[0].view_id, 42);
128
129 EXPECT_EQ(pointer_events[1].timestamp, 1235000u);
130 EXPECT_EQ(pointer_events[1].x, 3.0);
131 EXPECT_EQ(pointer_events[1].y, 4.0);
132 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
133 EXPECT_EQ(pointer_events[1].buttons, 0);
134 EXPECT_EQ(pointer_events[1].view_id, 42);
135 }
136
137 TEST(FlPointerManagerTest, EnterButtonPress) {
138 g_autoptr(FlDartProject) project = fl_dart_project_new();
139 g_autoptr(FlEngine) engine = fl_engine_new(project);
140
141 g_autoptr(GError) error = nullptr;
142 EXPECT_TRUE(fl_engine_start(engine, &error));
143 EXPECT_EQ(error, nullptr);
144
145 std::vector<FlutterPointerEvent> pointer_events;
146 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
147 SendPointerEvent,
148 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
149 size_t events_count) {
150 for (size_t i = 0; i < events_count; i++) {
151 pointer_events.push_back(events[i]);
152 }
153
154 return kSuccess;
155 }));
156
157 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
158 fl_pointer_manager_handle_enter(manager, 1234, kFlutterPointerDeviceKindMouse,
159 1.0, 2.0);
160 fl_pointer_manager_handle_button_press(manager, 1235,
161 kFlutterPointerDeviceKindMouse, 4.0,
162 8.0, GDK_BUTTON_PRIMARY);
163
164 EXPECT_EQ(pointer_events.size(), 2u);
165
166 EXPECT_EQ(pointer_events[0].timestamp, 1234000u);
167 EXPECT_EQ(pointer_events[0].x, 1.0);
168 EXPECT_EQ(pointer_events[0].y, 2.0);
169 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
170 EXPECT_EQ(pointer_events[0].buttons, 0);
171 EXPECT_EQ(pointer_events[0].view_id, 42);
172
173 EXPECT_EQ(pointer_events[1].timestamp, 1235000u);
174 EXPECT_EQ(pointer_events[1].x, 4.0);
175 EXPECT_EQ(pointer_events[1].y, 8.0);
176 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
177 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
178 EXPECT_EQ(pointer_events[1].view_id, 42);
179 }
180
181 TEST(FlPointerManagerTest, NoEnterButtonPress) {
182 g_autoptr(FlDartProject) project = fl_dart_project_new();
183 g_autoptr(FlEngine) engine = fl_engine_new(project);
184
185 g_autoptr(GError) error = nullptr;
186 EXPECT_TRUE(fl_engine_start(engine, &error));
187 EXPECT_EQ(error, nullptr);
188
189 std::vector<FlutterPointerEvent> pointer_events;
190 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
191 SendPointerEvent,
192 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
193 size_t events_count) {
194 for (size_t i = 0; i < events_count; i++) {
195 pointer_events.push_back(events[i]);
196 }
197
198 return kSuccess;
199 }));
200
201 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
202 fl_pointer_manager_handle_button_press(manager, 1234,
203 kFlutterPointerDeviceKindMouse, 4.0,
204 8.0, GDK_BUTTON_PRIMARY);
205
206 EXPECT_EQ(pointer_events.size(), 2u);
207
208 // Synthetic enter events
209 EXPECT_EQ(pointer_events[0].timestamp, 1234000u);
210 EXPECT_EQ(pointer_events[0].x, 4.0);
211 EXPECT_EQ(pointer_events[0].y, 8.0);
212 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindMouse);
213 EXPECT_EQ(pointer_events[0].buttons, 0);
214 EXPECT_EQ(pointer_events[0].view_id, 42);
215
216 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
217 EXPECT_EQ(pointer_events[1].x, 4.0);
218 EXPECT_EQ(pointer_events[1].y, 8.0);
219 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
220 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
221 EXPECT_EQ(pointer_events[1].view_id, 42);
222 }
223
224 TEST(FlPointerManagerTest, ButtonPressButtonReleasePrimary) {
225 g_autoptr(FlDartProject) project = fl_dart_project_new();
226 g_autoptr(FlEngine) engine = fl_engine_new(project);
227
228 g_autoptr(GError) error = nullptr;
229 EXPECT_TRUE(fl_engine_start(engine, &error));
230 EXPECT_EQ(error, nullptr);
231
232 std::vector<FlutterPointerEvent> pointer_events;
233 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
234 SendPointerEvent,
235 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
236 size_t events_count) {
237 for (size_t i = 0; i < events_count; i++) {
238 pointer_events.push_back(events[i]);
239 }
240
241 return kSuccess;
242 }));
243
244 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
245 fl_pointer_manager_handle_button_press(manager, 1234,
246 kFlutterPointerDeviceKindMouse, 4.0,
247 8.0, GDK_BUTTON_PRIMARY);
248 fl_pointer_manager_handle_button_release(manager, 1235,
249 kFlutterPointerDeviceKindMouse, 5.0,
250 9.0, GDK_BUTTON_PRIMARY);
251
252 EXPECT_EQ(pointer_events.size(), 3u);
253
254 // Ignore first synthetic enter event
255 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
256 EXPECT_EQ(pointer_events[1].x, 4.0);
257 EXPECT_EQ(pointer_events[1].y, 8.0);
258 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
259 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
260 EXPECT_EQ(pointer_events[1].view_id, 42);
261 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
262 EXPECT_EQ(pointer_events[2].x, 5.0);
263 EXPECT_EQ(pointer_events[2].y, 9.0);
264 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
265 EXPECT_EQ(pointer_events[2].buttons, 0);
266 EXPECT_EQ(pointer_events[2].view_id, 42);
267 }
268
269 TEST(FlPointerManagerTest, ButtonPressButtonReleaseSecondary) {
270 g_autoptr(FlDartProject) project = fl_dart_project_new();
271 g_autoptr(FlEngine) engine = fl_engine_new(project);
272
273 g_autoptr(GError) error = nullptr;
274 EXPECT_TRUE(fl_engine_start(engine, &error));
275 EXPECT_EQ(error, nullptr);
276
277 std::vector<FlutterPointerEvent> pointer_events;
278 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
279 SendPointerEvent,
280 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
281 size_t events_count) {
282 for (size_t i = 0; i < events_count; i++) {
283 pointer_events.push_back(events[i]);
284 }
285
286 return kSuccess;
287 }));
288
289 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
290 fl_pointer_manager_handle_button_press(manager, 1234,
291 kFlutterPointerDeviceKindMouse, 4.0,
292 8.0, GDK_BUTTON_SECONDARY);
293 fl_pointer_manager_handle_button_release(manager, 1235,
294 kFlutterPointerDeviceKindMouse, 5.0,
295 9.0, GDK_BUTTON_SECONDARY);
296
297 EXPECT_EQ(pointer_events.size(), 3u);
298
299 // Ignore first synthetic enter event
300 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
301 EXPECT_EQ(pointer_events[1].x, 4.0);
302 EXPECT_EQ(pointer_events[1].y, 8.0);
303 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
304 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMouseSecondary);
305 EXPECT_EQ(pointer_events[1].view_id, 42);
306 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
307 EXPECT_EQ(pointer_events[2].x, 5.0);
308 EXPECT_EQ(pointer_events[2].y, 9.0);
309 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
310 EXPECT_EQ(pointer_events[2].buttons, 0);
311 EXPECT_EQ(pointer_events[2].view_id, 42);
312 }
313
314 TEST(FlPointerManagerTest, ButtonPressButtonReleaseMiddle) {
315 g_autoptr(FlDartProject) project = fl_dart_project_new();
316 g_autoptr(FlEngine) engine = fl_engine_new(project);
317
318 g_autoptr(GError) error = nullptr;
319 EXPECT_TRUE(fl_engine_start(engine, &error));
320 EXPECT_EQ(error, nullptr);
321
322 std::vector<FlutterPointerEvent> pointer_events;
323 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
324 SendPointerEvent,
325 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
326 size_t events_count) {
327 for (size_t i = 0; i < events_count; i++) {
328 pointer_events.push_back(events[i]);
329 }
330
331 return kSuccess;
332 }));
333
334 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
335 fl_pointer_manager_handle_button_press(manager, 1234,
336 kFlutterPointerDeviceKindMouse, 4.0,
337 8.0, GDK_BUTTON_MIDDLE);
338 fl_pointer_manager_handle_button_release(manager, 1235,
339 kFlutterPointerDeviceKindMouse, 5.0,
340 9.0, GDK_BUTTON_MIDDLE);
341
342 EXPECT_EQ(pointer_events.size(), 3u);
343
344 // Ignore first synthetic enter event
345 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
346 EXPECT_EQ(pointer_events[1].x, 4.0);
347 EXPECT_EQ(pointer_events[1].y, 8.0);
348 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
349 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMouseMiddle);
350 EXPECT_EQ(pointer_events[1].view_id, 42);
351 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
352 EXPECT_EQ(pointer_events[2].x, 5.0);
353 EXPECT_EQ(pointer_events[2].y, 9.0);
354 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
355 EXPECT_EQ(pointer_events[2].buttons, 0);
356 EXPECT_EQ(pointer_events[2].view_id, 42);
357 }
358
359 TEST(FlPointerManagerTest, ButtonPressButtonReleaseBack) {
360 g_autoptr(FlDartProject) project = fl_dart_project_new();
361 g_autoptr(FlEngine) engine = fl_engine_new(project);
362
363 g_autoptr(GError) error = nullptr;
364 EXPECT_TRUE(fl_engine_start(engine, &error));
365 EXPECT_EQ(error, nullptr);
366
367 std::vector<FlutterPointerEvent> pointer_events;
368 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
369 SendPointerEvent,
370 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
371 size_t events_count) {
372 for (size_t i = 0; i < events_count; i++) {
373 pointer_events.push_back(events[i]);
374 }
375
376 return kSuccess;
377 }));
378
379 // Forward button is 8 (no GDK define).
380 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
381 fl_pointer_manager_handle_button_press(
382 manager, 1234, kFlutterPointerDeviceKindMouse, 4.0, 8.0, 8);
383 fl_pointer_manager_handle_button_release(
384 manager, 1235, kFlutterPointerDeviceKindMouse, 5.0, 9.0, 8);
385
386 EXPECT_EQ(pointer_events.size(), 3u);
387
388 // Ignore first synthetic enter event
389 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
390 EXPECT_EQ(pointer_events[1].x, 4.0);
391 EXPECT_EQ(pointer_events[1].y, 8.0);
392 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
393 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMouseBack);
394 EXPECT_EQ(pointer_events[1].view_id, 42);
395 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
396 EXPECT_EQ(pointer_events[2].x, 5.0);
397 EXPECT_EQ(pointer_events[2].y, 9.0);
398 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
399 EXPECT_EQ(pointer_events[2].buttons, 0);
400 EXPECT_EQ(pointer_events[2].view_id, 42);
401 }
402
403 TEST(FlPointerManagerTest, ButtonPressButtonReleaseForward) {
404 g_autoptr(FlDartProject) project = fl_dart_project_new();
405 g_autoptr(FlEngine) engine = fl_engine_new(project);
406
407 g_autoptr(GError) error = nullptr;
408 EXPECT_TRUE(fl_engine_start(engine, &error));
409 EXPECT_EQ(error, nullptr);
410
411 std::vector<FlutterPointerEvent> pointer_events;
412 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
413 SendPointerEvent,
414 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
415 size_t events_count) {
416 for (size_t i = 0; i < events_count; i++) {
417 pointer_events.push_back(events[i]);
418 }
419
420 return kSuccess;
421 }));
422
423 // Forward button is 9 (no GDK define).
424 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
425 fl_pointer_manager_handle_button_press(
426 manager, 1234, kFlutterPointerDeviceKindMouse, 4.0, 8.0, 9);
427 fl_pointer_manager_handle_button_release(
428 manager, 1235, kFlutterPointerDeviceKindMouse, 5.0, 9.0, 9);
429
430 EXPECT_EQ(pointer_events.size(), 3u);
431
432 // Ignore first synthetic enter event
433 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
434 EXPECT_EQ(pointer_events[1].x, 4.0);
435 EXPECT_EQ(pointer_events[1].y, 8.0);
436 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
437 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMouseForward);
438 EXPECT_EQ(pointer_events[1].view_id, 42);
439 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
440 EXPECT_EQ(pointer_events[2].x, 5.0);
441 EXPECT_EQ(pointer_events[2].y, 9.0);
442 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
443 EXPECT_EQ(pointer_events[2].buttons, 0);
444 EXPECT_EQ(pointer_events[2].view_id, 42);
445 }
446
447 TEST(FlPointerManagerTest, ButtonPressButtonReleaseThreeButtons) {
448 g_autoptr(FlDartProject) project = fl_dart_project_new();
449 g_autoptr(FlEngine) engine = fl_engine_new(project);
450
451 g_autoptr(GError) error = nullptr;
452 EXPECT_TRUE(fl_engine_start(engine, &error));
453 EXPECT_EQ(error, nullptr);
454
455 std::vector<FlutterPointerEvent> pointer_events;
456 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
457 SendPointerEvent,
458 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
459 size_t events_count) {
460 for (size_t i = 0; i < events_count; i++) {
461 pointer_events.push_back(events[i]);
462 }
463
464 return kSuccess;
465 }));
466
467 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
468 // Press buttons 1-2-3, release 3-2-1
469 fl_pointer_manager_handle_button_press(manager, 1234,
470 kFlutterPointerDeviceKindMouse, 1.0,
471 2.0, GDK_BUTTON_PRIMARY);
472 fl_pointer_manager_handle_button_press(manager, 1235,
473 kFlutterPointerDeviceKindMouse, 3.0,
474 4.0, GDK_BUTTON_SECONDARY);
475 fl_pointer_manager_handle_button_press(manager, 1236,
476 kFlutterPointerDeviceKindMouse, 5.0,
477 6.0, GDK_BUTTON_MIDDLE);
478 fl_pointer_manager_handle_button_release(manager, 1237,
479 kFlutterPointerDeviceKindMouse, 7.0,
480 8.0, GDK_BUTTON_MIDDLE);
481 fl_pointer_manager_handle_button_release(manager, 1238,
482 kFlutterPointerDeviceKindMouse, 9.0,
483 10.0, GDK_BUTTON_SECONDARY);
484 fl_pointer_manager_handle_button_release(
485 manager, 1239, kFlutterPointerDeviceKindMouse, 11.0, 12.0,
486 kFlutterPointerButtonMousePrimary);
487
488 EXPECT_EQ(pointer_events.size(), 7u);
489
490 // Ignore first synthetic enter event
491 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
492 EXPECT_EQ(pointer_events[1].x, 1.0);
493 EXPECT_EQ(pointer_events[1].y, 2.0);
494 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
495 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
496 EXPECT_EQ(pointer_events[2].x, 3.0);
497 EXPECT_EQ(pointer_events[2].y, 4.0);
498 EXPECT_EQ(pointer_events[2].buttons, kFlutterPointerButtonMousePrimary |
499 kFlutterPointerButtonMouseSecondary);
500 EXPECT_EQ(pointer_events[3].timestamp, 1236000u);
501 EXPECT_EQ(pointer_events[3].x, 5.0);
502 EXPECT_EQ(pointer_events[3].y, 6.0);
503 EXPECT_EQ(pointer_events[3].buttons, kFlutterPointerButtonMousePrimary |
504 kFlutterPointerButtonMouseSecondary |
505 kFlutterPointerButtonMouseMiddle);
506 EXPECT_EQ(pointer_events[4].timestamp, 1237000u);
507 EXPECT_EQ(pointer_events[4].x, 7.0);
508 EXPECT_EQ(pointer_events[4].y, 8.0);
509 EXPECT_EQ(pointer_events[4].buttons, kFlutterPointerButtonMousePrimary |
510 kFlutterPointerButtonMouseSecondary);
511 EXPECT_EQ(pointer_events[5].timestamp, 1238000u);
512 EXPECT_EQ(pointer_events[5].x, 9.0);
513 EXPECT_EQ(pointer_events[5].y, 10.0);
514 EXPECT_EQ(pointer_events[5].buttons, kFlutterPointerButtonMousePrimary);
515 EXPECT_EQ(pointer_events[6].timestamp, 1239000u);
516 EXPECT_EQ(pointer_events[6].x, 11.0);
517 EXPECT_EQ(pointer_events[6].y, 12.0);
518 EXPECT_EQ(pointer_events[6].buttons, 0);
519 }
520
521 TEST(FlPointerManagerTest, ButtonPressButtonPressButtonRelease) {
522 g_autoptr(FlDartProject) project = fl_dart_project_new();
523 g_autoptr(FlEngine) engine = fl_engine_new(project);
524
525 g_autoptr(GError) error = nullptr;
526 EXPECT_TRUE(fl_engine_start(engine, &error));
527 EXPECT_EQ(error, nullptr);
528
529 std::vector<FlutterPointerEvent> pointer_events;
530 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
531 SendPointerEvent,
532 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
533 size_t events_count) {
534 for (size_t i = 0; i < events_count; i++) {
535 pointer_events.push_back(events[i]);
536 }
537
538 return kSuccess;
539 }));
540
541 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
542 fl_pointer_manager_handle_button_press(manager, 1234,
543 kFlutterPointerDeviceKindMouse, 4.0,
544 8.0, GDK_BUTTON_PRIMARY);
545 // Ignore duplicate press
546 fl_pointer_manager_handle_button_press(manager, 1234,
547 kFlutterPointerDeviceKindMouse, 6.0,
548 10.0, GDK_BUTTON_PRIMARY);
549 fl_pointer_manager_handle_button_release(manager, 1235,
550 kFlutterPointerDeviceKindMouse, 5.0,
551 9.0, GDK_BUTTON_PRIMARY);
552
553 EXPECT_EQ(pointer_events.size(), 3u);
554
555 // Ignore first synthetic enter event
556 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
557 EXPECT_EQ(pointer_events[1].x, 4.0);
558 EXPECT_EQ(pointer_events[1].y, 8.0);
559 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
560 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
561 EXPECT_EQ(pointer_events[1].view_id, 42);
562 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
563 EXPECT_EQ(pointer_events[2].x, 5.0);
564 EXPECT_EQ(pointer_events[2].y, 9.0);
565 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
566 EXPECT_EQ(pointer_events[2].buttons, 0);
567 EXPECT_EQ(pointer_events[2].view_id, 42);
568 }
569
570 TEST(FlPointerManagerTest, ButtonPressButtonReleaseButtonRelease) {
571 g_autoptr(FlDartProject) project = fl_dart_project_new();
572 g_autoptr(FlEngine) engine = fl_engine_new(project);
573
574 g_autoptr(GError) error = nullptr;
575 EXPECT_TRUE(fl_engine_start(engine, &error));
576 EXPECT_EQ(error, nullptr);
577
578 std::vector<FlutterPointerEvent> pointer_events;
579 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
580 SendPointerEvent,
581 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
582 size_t events_count) {
583 for (size_t i = 0; i < events_count; i++) {
584 pointer_events.push_back(events[i]);
585 }
586
587 return kSuccess;
588 }));
589
590 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
591 fl_pointer_manager_handle_button_press(manager, 1234,
592 kFlutterPointerDeviceKindMouse, 4.0,
593 8.0, GDK_BUTTON_PRIMARY);
594 fl_pointer_manager_handle_button_release(manager, 1235,
595 kFlutterPointerDeviceKindMouse, 5.0,
596 9.0, GDK_BUTTON_PRIMARY);
597 // Ignore duplicate release
598 fl_pointer_manager_handle_button_release(manager, 1235,
599 kFlutterPointerDeviceKindMouse, 6.0,
600 10.0, GDK_BUTTON_PRIMARY);
601
602 EXPECT_EQ(pointer_events.size(), 3u);
603
604 // Ignore first synthetic enter event
605 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
606 EXPECT_EQ(pointer_events[1].x, 4.0);
607 EXPECT_EQ(pointer_events[1].y, 8.0);
608 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
609 EXPECT_EQ(pointer_events[1].buttons, kFlutterPointerButtonMousePrimary);
610 EXPECT_EQ(pointer_events[1].view_id, 42);
611 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
612 EXPECT_EQ(pointer_events[2].x, 5.0);
613 EXPECT_EQ(pointer_events[2].y, 9.0);
614 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
615 EXPECT_EQ(pointer_events[2].buttons, 0);
616 EXPECT_EQ(pointer_events[2].view_id, 42);
617 }
618
619 TEST(FlPointerManagerTest, NoButtonPressButtonRelease) {
620 g_autoptr(FlDartProject) project = fl_dart_project_new();
621 g_autoptr(FlEngine) engine = fl_engine_new(project);
622
623 g_autoptr(GError) error = nullptr;
624 EXPECT_TRUE(fl_engine_start(engine, &error));
625 EXPECT_EQ(error, nullptr);
626
627 std::vector<FlutterPointerEvent> pointer_events;
628 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
629 SendPointerEvent,
630 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
631 size_t events_count) {
632 for (size_t i = 0; i < events_count; i++) {
633 pointer_events.push_back(events[i]);
634 }
635
636 return kSuccess;
637 }));
638
639 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
640 // Release without associated press, will be ignored
641 fl_pointer_manager_handle_button_release(manager, 1235,
642 kFlutterPointerDeviceKindMouse, 5.0,
643 9.0, GDK_BUTTON_PRIMARY);
644
645 EXPECT_EQ(pointer_events.size(), 0u);
646 }
647
648 TEST(FlPointerManagerTest, Motion) {
649 g_autoptr(FlDartProject) project = fl_dart_project_new();
650 g_autoptr(FlEngine) engine = fl_engine_new(project);
651
652 g_autoptr(GError) error = nullptr;
653 EXPECT_TRUE(fl_engine_start(engine, &error));
654 EXPECT_EQ(error, nullptr);
655
656 std::vector<FlutterPointerEvent> pointer_events;
657 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
658 SendPointerEvent,
659 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
660 size_t events_count) {
661 for (size_t i = 0; i < events_count; i++) {
662 pointer_events.push_back(events[i]);
663 }
664
665 return kSuccess;
666 }));
667
668 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
669 fl_pointer_manager_handle_motion(manager, 1234,
670 kFlutterPointerDeviceKindMouse, 1.0, 2.0);
671 fl_pointer_manager_handle_motion(manager, 1235,
672 kFlutterPointerDeviceKindMouse, 3.0, 4.0);
673 fl_pointer_manager_handle_motion(manager, 1236,
674 kFlutterPointerDeviceKindMouse, 5.0, 6.0);
675
676 EXPECT_EQ(pointer_events.size(), 4u);
677
678 // Ignore first synthetic enter event
679 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
680 EXPECT_EQ(pointer_events[1].x, 1.0);
681 EXPECT_EQ(pointer_events[1].y, 2.0);
682 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindMouse);
683 EXPECT_EQ(pointer_events[1].buttons, 0);
684 EXPECT_EQ(pointer_events[1].view_id, 42);
685 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
686 EXPECT_EQ(pointer_events[2].x, 3.0);
687 EXPECT_EQ(pointer_events[2].y, 4.0);
688 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindMouse);
689 EXPECT_EQ(pointer_events[2].buttons, 0);
690 EXPECT_EQ(pointer_events[2].view_id, 42);
691 EXPECT_EQ(pointer_events[3].timestamp, 1236000u);
692 EXPECT_EQ(pointer_events[3].x, 5.0);
693 EXPECT_EQ(pointer_events[3].y, 6.0);
694 EXPECT_EQ(pointer_events[3].device_kind, kFlutterPointerDeviceKindMouse);
695 EXPECT_EQ(pointer_events[3].buttons, 0);
696 EXPECT_EQ(pointer_events[3].view_id, 42);
697 }
698
699 TEST(FlPointerManagerTest, Drag) {
700 g_autoptr(FlDartProject) project = fl_dart_project_new();
701 g_autoptr(FlEngine) engine = fl_engine_new(project);
702
703 g_autoptr(GError) error = nullptr;
704 EXPECT_TRUE(fl_engine_start(engine, &error));
705 EXPECT_EQ(error, nullptr);
706
707 std::vector<FlutterPointerEvent> pointer_events;
708 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
709 SendPointerEvent,
710 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
711 size_t events_count) {
712 for (size_t i = 0; i < events_count; i++) {
713 pointer_events.push_back(events[i]);
714 }
715
716 return kSuccess;
717 }));
718
719 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
720 fl_pointer_manager_handle_motion(manager, 1234,
721 kFlutterPointerDeviceKindMouse, 1.0, 2.0);
722 fl_pointer_manager_handle_button_press(manager, 1235,
723 kFlutterPointerDeviceKindMouse, 3.0,
724 4.0, GDK_BUTTON_PRIMARY);
725 fl_pointer_manager_handle_motion(manager, 1236,
726 kFlutterPointerDeviceKindMouse, 5.0, 6.0);
727 fl_pointer_manager_handle_button_release(manager, 1237,
728 kFlutterPointerDeviceKindMouse, 7.0,
729 8.0, GDK_BUTTON_PRIMARY);
730 fl_pointer_manager_handle_motion(manager, 1238,
731 kFlutterPointerDeviceKindMouse, 9.0, 10.0);
732
733 EXPECT_EQ(pointer_events.size(), 6u);
734
735 // Ignore first synthetic enter event
736 EXPECT_EQ(pointer_events[1].timestamp, 1234000u);
737 EXPECT_EQ(pointer_events[1].x, 1.0);
738 EXPECT_EQ(pointer_events[1].y, 2.0);
739 EXPECT_EQ(pointer_events[1].buttons, 0);
740 EXPECT_EQ(pointer_events[1].view_id, 42);
741 EXPECT_EQ(pointer_events[2].timestamp, 1235000u);
742 EXPECT_EQ(pointer_events[2].x, 3.0);
743 EXPECT_EQ(pointer_events[2].y, 4.0);
744 EXPECT_EQ(pointer_events[2].buttons, kFlutterPointerButtonMousePrimary);
745 EXPECT_EQ(pointer_events[2].view_id, 42);
746 EXPECT_EQ(pointer_events[3].timestamp, 1236000u);
747 EXPECT_EQ(pointer_events[3].x, 5.0);
748 EXPECT_EQ(pointer_events[3].y, 6.0);
749 EXPECT_EQ(pointer_events[3].buttons, kFlutterPointerButtonMousePrimary);
750 EXPECT_EQ(pointer_events[3].view_id, 42);
751 EXPECT_EQ(pointer_events[4].timestamp, 1237000u);
752 EXPECT_EQ(pointer_events[4].x, 7.0);
753 EXPECT_EQ(pointer_events[4].y, 8.0);
754 EXPECT_EQ(pointer_events[4].buttons, 0);
755 EXPECT_EQ(pointer_events[4].view_id, 42);
756 EXPECT_EQ(pointer_events[5].timestamp, 1238000u);
757 EXPECT_EQ(pointer_events[5].x, 9.0);
758 EXPECT_EQ(pointer_events[5].y, 10.0);
759 EXPECT_EQ(pointer_events[5].buttons, 0);
760 EXPECT_EQ(pointer_events[5].view_id, 42);
761 }
762
763 TEST(FlPointerManagerTest, DeviceKind) {
764 g_autoptr(FlDartProject) project = fl_dart_project_new();
765 g_autoptr(FlEngine) engine = fl_engine_new(project);
766
767 g_autoptr(GError) error = nullptr;
768 EXPECT_TRUE(fl_engine_start(engine, &error));
769 EXPECT_EQ(error, nullptr);
770
771 std::vector<FlutterPointerEvent> pointer_events;
772 fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
773 SendPointerEvent,
774 ([&pointer_events](auto engine, const FlutterPointerEvent* events,
775 size_t events_count) {
776 for (size_t i = 0; i < events_count; i++) {
777 pointer_events.push_back(events[i]);
778 }
779
780 return kSuccess;
781 }));
782
783 g_autoptr(FlPointerManager) manager = fl_pointer_manager_new(42, engine);
784 fl_pointer_manager_handle_enter(manager, 1234,
785 kFlutterPointerDeviceKindTrackpad, 1.0, 2.0);
786 fl_pointer_manager_handle_button_press(manager, 1235,
787 kFlutterPointerDeviceKindTrackpad, 1.0,
788 2.0, GDK_BUTTON_PRIMARY);
789 fl_pointer_manager_handle_motion(manager, 1238,
790 kFlutterPointerDeviceKindTrackpad, 3.0, 4.0);
791 fl_pointer_manager_handle_button_release(manager, 1237,
792 kFlutterPointerDeviceKindTrackpad,
793 3.0, 4.0, GDK_BUTTON_PRIMARY);
794 fl_pointer_manager_handle_leave(manager, 1235,
795 kFlutterPointerDeviceKindTrackpad, 3.0, 4.0);
796
797 EXPECT_EQ(pointer_events.size(), 5u);
798
799 EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindTrackpad);
800 EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindTrackpad);
801 EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindTrackpad);
802 EXPECT_EQ(pointer_events[3].device_kind, kFlutterPointerDeviceKindTrackpad);
803 EXPECT_EQ(pointer_events[4].device_kind, kFlutterPointerDeviceKindTrackpad);
804 }
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:726
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:613
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:584
fl_engine_private.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_pointer_manager_handle_button_press
gboolean fl_pointer_manager_handle_button_press(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_button)
Definition: fl_pointer_manager.cc:105
fl_pointer_manager_new
FlPointerManager * fl_pointer_manager_new(FlutterViewId view_id, FlEngine *engine)
Definition: fl_pointer_manager.cc:94
fl_pointer_manager_handle_motion
gboolean fl_pointer_manager_handle_motion(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
Definition: fl_pointer_manager.cc:179
fl_pointer_manager_handle_enter
gboolean fl_pointer_manager_handle_enter(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
Definition: fl_pointer_manager.cc:201
fl_pointer_manager_handle_leave
gboolean fl_pointer_manager_handle_leave(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
Definition: fl_pointer_manager.cc:218
fl_pointer_manager_handle_button_release
gboolean fl_pointer_manager_handle_button_release(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_button)
Definition: fl_pointer_manager.cc:143
fl_pointer_manager.h
TEST
TEST(FlPointerManagerTest, EnterLeave)
Definition: fl_pointer_manager_test.cc:11
i
int i
Definition: fl_socket_accessible.cc:18
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49