Flutter Engine
The Flutter Engine
pointer_data_packet_converter_unittests.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/lib/ui/window/pointer_data_packet_converter.h"
6
7#include <cstring>
8#include <unordered_set>
9
10#include "gtest/gtest.h"
11
12namespace flutter {
13namespace testing {
14
15namespace {
16
17constexpr int64_t kImplicitViewId = 0;
18
19}
20
22 public:
23 // |PointerDataPacketConverter::Delegate|
24 bool ViewExists(int64_t view_id) const override {
25 return views_.count(view_id) != 0;
26 }
27
28 void AddView(int64_t view_id) { views_.insert(view_id); }
29
30 void RemoveView(int64_t view_id) { views_.erase(view_id); }
31
32 private:
33 std::unordered_set<int64_t> views_;
34};
35
38 int64_t device,
39 double dx,
40 double dy,
41 int64_t buttons) {
42 data.time_stamp = 0;
43 data.change = change;
46 data.device = device;
47 data.pointer_identifier = 0;
48 data.physical_x = dx;
49 data.physical_y = dy;
50 data.physical_delta_x = 0.0;
51 data.physical_delta_y = 0.0;
52 data.buttons = buttons;
53 data.obscured = 0;
54 data.synthesized = 0;
55 data.pressure = 0.0;
56 data.pressure_min = 0.0;
57 data.pressure_max = 0.0;
58 data.distance = 0.0;
59 data.distance_max = 0.0;
60 data.size = 0.0;
61 data.radius_major = 0.0;
62 data.radius_minor = 0.0;
63 data.radius_min = 0.0;
64 data.radius_max = 0.0;
65 data.orientation = 0.0;
66 data.tilt = 0.0;
67 data.platformData = 0;
68 data.scroll_delta_x = 0.0;
69 data.scroll_delta_y = 0.0;
70 data.view_id = kImplicitViewId;
71}
72
75 PointerData::SignalKind signal_kind,
76 int64_t device,
77 double dx,
78 double dy,
79 double scroll_delta_x,
80 double scroll_delta_y,
81 int64_t buttons) {
82 data.time_stamp = 0;
83 data.change = change;
85 data.signal_kind = signal_kind;
86 data.device = device;
87 data.pointer_identifier = 0;
88 data.physical_x = dx;
89 data.physical_y = dy;
90 data.physical_delta_x = 0.0;
91 data.physical_delta_y = 0.0;
92 data.buttons = buttons;
93 data.obscured = 0;
94 data.synthesized = 0;
95 data.pressure = 0.0;
96 data.pressure_min = 0.0;
97 data.pressure_max = 0.0;
98 data.distance = 0.0;
99 data.distance_max = 0.0;
100 data.size = 0.0;
101 data.radius_major = 0.0;
102 data.radius_minor = 0.0;
103 data.radius_min = 0.0;
104 data.radius_max = 0.0;
105 data.orientation = 0.0;
106 data.tilt = 0.0;
107 data.platformData = 0;
108 data.scroll_delta_x = scroll_delta_x;
109 data.scroll_delta_y = scroll_delta_y;
110 data.view_id = kImplicitViewId;
111}
112
114 PointerData::Change change,
115 int64_t device,
116 double dx,
117 double dy,
118 double pan_x,
119 double pan_y,
120 double scale,
121 double rotation) {
122 data.time_stamp = 0;
123 data.change = change;
126 data.device = device;
127 data.pointer_identifier = 0;
128 data.physical_x = dx;
129 data.physical_y = dy;
130 data.physical_delta_x = 0.0;
131 data.physical_delta_y = 0.0;
132 data.buttons = 0;
133 data.obscured = 0;
134 data.synthesized = 0;
135 data.pressure = 0.0;
136 data.pressure_min = 0.0;
137 data.pressure_max = 0.0;
138 data.distance = 0.0;
139 data.distance_max = 0.0;
140 data.size = 0.0;
141 data.radius_major = 0.0;
142 data.radius_minor = 0.0;
143 data.radius_min = 0.0;
144 data.radius_max = 0.0;
145 data.orientation = 0.0;
146 data.tilt = 0.0;
147 data.platformData = 0;
148 data.scroll_delta_x = 0.0;
149 data.scroll_delta_y = 0.0;
150 data.pan_x = pan_x;
151 data.pan_y = pan_y;
152 data.pan_delta_x = 0.0;
153 data.pan_delta_y = 0.0;
154 data.scale = scale;
155 data.rotation = rotation;
156 data.view_id = 0;
157}
158
159void UnpackPointerPacket(std::vector<PointerData>& output, // NOLINT
160 std::unique_ptr<PointerDataPacket> packet) {
161 for (size_t i = 0; i < packet->GetLength(); i++) {
162 PointerData pointer_data = packet->GetPointerData(i);
163 output.push_back(pointer_data);
164 }
165 packet.reset();
166}
167
168TEST(PointerDataPacketConverterTest, CanConvertPointerDataPacket) {
169 TestDelegate delegate;
170 delegate.AddView(kImplicitViewId);
172 auto packet = std::make_unique<PointerDataPacket>(6);
175 packet->SetPointerData(0, data);
177 packet->SetPointerData(1, data);
179 packet->SetPointerData(2, data);
181 packet->SetPointerData(3, data);
183 packet->SetPointerData(4, data);
185 0);
186 packet->SetPointerData(5, data);
187 auto converted_packet = converter.Convert(*packet);
188
189 std::vector<PointerData> result;
190 UnpackPointerPacket(result, std::move(converted_packet));
191
192 ASSERT_EQ(result.size(), (size_t)6);
193 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
194 ASSERT_EQ(result[0].synthesized, 0);
195
196 ASSERT_EQ(result[1].change, PointerData::Change::kHover);
197 ASSERT_EQ(result[1].synthesized, 0);
198 ASSERT_EQ(result[1].physical_delta_x, 3.0);
199 ASSERT_EQ(result[1].physical_delta_y, 0.0);
200
201 ASSERT_EQ(result[2].change, PointerData::Change::kDown);
202 ASSERT_EQ(result[2].pointer_identifier, 1);
203 ASSERT_EQ(result[2].synthesized, 0);
204
205 ASSERT_EQ(result[3].change, PointerData::Change::kMove);
206 ASSERT_EQ(result[3].pointer_identifier, 1);
207 ASSERT_EQ(result[3].synthesized, 0);
208 ASSERT_EQ(result[3].physical_delta_x, 0.0);
209 ASSERT_EQ(result[3].physical_delta_y, 4.0);
210
211 ASSERT_EQ(result[4].change, PointerData::Change::kUp);
212 ASSERT_EQ(result[4].pointer_identifier, 1);
213 ASSERT_EQ(result[4].synthesized, 0);
214
215 ASSERT_EQ(result[5].change, PointerData::Change::kRemove);
216 ASSERT_EQ(result[5].synthesized, 0);
217}
218
219TEST(PointerDataPacketConverterTest, CanSynthesizeDownAndUp) {
220 TestDelegate delegate;
221 delegate.AddView(kImplicitViewId);
223 auto packet = std::make_unique<PointerDataPacket>(4);
226 packet->SetPointerData(0, data);
228 packet->SetPointerData(1, data);
230 packet->SetPointerData(2, data);
232 0);
233 packet->SetPointerData(3, data);
234 auto converted_packet = converter.Convert(*packet);
235
236 std::vector<PointerData> result;
237 UnpackPointerPacket(result, std::move(converted_packet));
238
239 ASSERT_EQ(result.size(), (size_t)6);
240 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
241 ASSERT_EQ(result[0].synthesized, 0);
242
243 // A hover should be synthesized.
244 ASSERT_EQ(result[1].change, PointerData::Change::kHover);
245 ASSERT_EQ(result[1].synthesized, 1);
246 ASSERT_EQ(result[1].physical_delta_x, 3.0);
247 ASSERT_EQ(result[1].physical_delta_y, 0.0);
248 ASSERT_EQ(result[1].buttons, 0);
249
250 ASSERT_EQ(result[2].change, PointerData::Change::kDown);
251 ASSERT_EQ(result[2].pointer_identifier, 1);
252 ASSERT_EQ(result[2].synthesized, 0);
253 ASSERT_EQ(result[2].buttons, 1);
254
255 // A move should be synthesized.
256 ASSERT_EQ(result[3].change, PointerData::Change::kMove);
257 ASSERT_EQ(result[3].pointer_identifier, 1);
258 ASSERT_EQ(result[3].synthesized, 1);
259 ASSERT_EQ(result[3].physical_delta_x, 0.0);
260 ASSERT_EQ(result[3].physical_delta_y, 4.0);
261 ASSERT_EQ(result[3].buttons, 1);
262
263 ASSERT_EQ(result[4].change, PointerData::Change::kUp);
264 ASSERT_EQ(result[4].pointer_identifier, 1);
265 ASSERT_EQ(result[4].synthesized, 0);
266 ASSERT_EQ(result[4].buttons, 0);
267
268 ASSERT_EQ(result[5].change, PointerData::Change::kRemove);
269 ASSERT_EQ(result[5].synthesized, 0);
270}
271
272TEST(PointerDataPacketConverterTest, CanUpdatePointerIdentifier) {
273 TestDelegate delegate;
274 delegate.AddView(kImplicitViewId);
276 auto packet = std::make_unique<PointerDataPacket>(7);
279 packet->SetPointerData(0, data);
281 packet->SetPointerData(1, data);
283 packet->SetPointerData(2, data);
285 packet->SetPointerData(3, data);
287 packet->SetPointerData(4, data);
289 packet->SetPointerData(5, data);
291 0);
292 packet->SetPointerData(6, data);
293 auto converted_packet = converter.Convert(*packet);
294
295 std::vector<PointerData> result;
296 UnpackPointerPacket(result, std::move(converted_packet));
297
298 ASSERT_EQ(result.size(), (size_t)7);
299 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
300 ASSERT_EQ(result[0].synthesized, 0);
301
302 ASSERT_EQ(result[1].change, PointerData::Change::kDown);
303 ASSERT_EQ(result[1].pointer_identifier, 1);
304 ASSERT_EQ(result[1].synthesized, 0);
305
306 ASSERT_EQ(result[2].change, PointerData::Change::kUp);
307 ASSERT_EQ(result[2].pointer_identifier, 1);
308 ASSERT_EQ(result[2].synthesized, 0);
309
310 // Pointer count increase to 2.
311 ASSERT_EQ(result[3].change, PointerData::Change::kDown);
312 ASSERT_EQ(result[3].pointer_identifier, 2);
313 ASSERT_EQ(result[3].synthesized, 0);
314
315 ASSERT_EQ(result[4].change, PointerData::Change::kMove);
316 ASSERT_EQ(result[4].pointer_identifier, 2);
317 ASSERT_EQ(result[4].synthesized, 0);
318 ASSERT_EQ(result[4].physical_delta_x, 3.0);
319 ASSERT_EQ(result[4].physical_delta_y, 0.0);
320
321 ASSERT_EQ(result[5].change, PointerData::Change::kUp);
322 ASSERT_EQ(result[5].pointer_identifier, 2);
323 ASSERT_EQ(result[5].synthesized, 0);
324
325 ASSERT_EQ(result[6].change, PointerData::Change::kRemove);
326 ASSERT_EQ(result[6].synthesized, 0);
327}
328
329TEST(PointerDataPacketConverterTest, AlwaysForwardMoveEvent) {
330 TestDelegate delegate;
331 delegate.AddView(kImplicitViewId);
333 auto packet = std::make_unique<PointerDataPacket>(4);
336 packet->SetPointerData(0, data);
338 packet->SetPointerData(1, data);
339 // Creates a move event without a location change.
341 packet->SetPointerData(2, data);
343 packet->SetPointerData(3, data);
344
345 auto converted_packet = converter.Convert(*packet);
346
347 std::vector<PointerData> result;
348 UnpackPointerPacket(result, std::move(converted_packet));
349
350 ASSERT_EQ(result.size(), (size_t)4);
351 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
352 ASSERT_EQ(result[0].synthesized, 0);
353
354 ASSERT_EQ(result[1].change, PointerData::Change::kDown);
355 ASSERT_EQ(result[1].pointer_identifier, 1);
356 ASSERT_EQ(result[1].synthesized, 0);
357
358 // Does not filter out the move event.
359 ASSERT_EQ(result[2].change, PointerData::Change::kMove);
360 ASSERT_EQ(result[2].pointer_identifier, 1);
361 ASSERT_EQ(result[2].synthesized, 0);
362
363 ASSERT_EQ(result[3].change, PointerData::Change::kUp);
364 ASSERT_EQ(result[3].pointer_identifier, 1);
365 ASSERT_EQ(result[3].synthesized, 0);
366}
367
368TEST(PointerDataPacketConverterTest, CanWorkWithDifferentDevices) {
369 TestDelegate delegate;
370 delegate.AddView(kImplicitViewId);
372 auto packet = std::make_unique<PointerDataPacket>(12);
375 packet->SetPointerData(0, data);
377 packet->SetPointerData(1, data);
379 packet->SetPointerData(2, data);
381 packet->SetPointerData(3, data);
383 packet->SetPointerData(4, data);
385 packet->SetPointerData(5, data);
387 packet->SetPointerData(6, data);
389 packet->SetPointerData(7, data);
391 packet->SetPointerData(8, data);
393 packet->SetPointerData(9, data);
395 0);
396 packet->SetPointerData(10, data);
398 0);
399 packet->SetPointerData(11, data);
400 auto converted_packet = converter.Convert(*packet);
401
402 std::vector<PointerData> result;
403 UnpackPointerPacket(result, std::move(converted_packet));
404
405 ASSERT_EQ(result.size(), (size_t)12);
406 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
407 ASSERT_EQ(result[0].device, 0);
408 ASSERT_EQ(result[0].synthesized, 0);
409
410 ASSERT_EQ(result[1].change, PointerData::Change::kDown);
411 ASSERT_EQ(result[1].device, 0);
412 ASSERT_EQ(result[1].pointer_identifier, 1);
413 ASSERT_EQ(result[1].synthesized, 0);
414
415 ASSERT_EQ(result[2].change, PointerData::Change::kAdd);
416 ASSERT_EQ(result[2].device, 1);
417 ASSERT_EQ(result[2].synthesized, 0);
418
419 ASSERT_EQ(result[3].change, PointerData::Change::kDown);
420 ASSERT_EQ(result[3].device, 1);
421 ASSERT_EQ(result[3].pointer_identifier, 2);
422 ASSERT_EQ(result[3].synthesized, 0);
423
424 ASSERT_EQ(result[4].change, PointerData::Change::kUp);
425 ASSERT_EQ(result[4].device, 0);
426 ASSERT_EQ(result[4].pointer_identifier, 1);
427 ASSERT_EQ(result[4].synthesized, 0);
428
429 ASSERT_EQ(result[5].change, PointerData::Change::kDown);
430 ASSERT_EQ(result[5].device, 0);
431 ASSERT_EQ(result[5].pointer_identifier, 3);
432 ASSERT_EQ(result[5].synthesized, 0);
433
434 ASSERT_EQ(result[6].change, PointerData::Change::kMove);
435 ASSERT_EQ(result[6].device, 1);
436 ASSERT_EQ(result[6].pointer_identifier, 2);
437 ASSERT_EQ(result[6].synthesized, 0);
438 ASSERT_EQ(result[6].physical_delta_x, 0.0);
439 ASSERT_EQ(result[6].physical_delta_y, 4.0);
440
441 ASSERT_EQ(result[7].change, PointerData::Change::kMove);
442 ASSERT_EQ(result[7].device, 0);
443 ASSERT_EQ(result[7].pointer_identifier, 3);
444 ASSERT_EQ(result[7].synthesized, 0);
445 ASSERT_EQ(result[7].physical_delta_x, 3.0);
446 ASSERT_EQ(result[7].physical_delta_y, 0.0);
447
448 ASSERT_EQ(result[8].change, PointerData::Change::kUp);
449 ASSERT_EQ(result[8].device, 1);
450 ASSERT_EQ(result[8].pointer_identifier, 2);
451 ASSERT_EQ(result[8].synthesized, 0);
452
453 ASSERT_EQ(result[9].change, PointerData::Change::kUp);
454 ASSERT_EQ(result[9].device, 0);
455 ASSERT_EQ(result[9].pointer_identifier, 3);
456 ASSERT_EQ(result[9].synthesized, 0);
457
458 ASSERT_EQ(result[10].change, PointerData::Change::kRemove);
459 ASSERT_EQ(result[10].device, 0);
460 ASSERT_EQ(result[10].synthesized, 0);
461
462 ASSERT_EQ(result[11].change, PointerData::Change::kRemove);
463 ASSERT_EQ(result[11].device, 1);
464 ASSERT_EQ(result[11].synthesized, 0);
465}
466
467TEST(PointerDataPacketConverterTest, CanSynthesizeAdd) {
468 TestDelegate delegate;
469 delegate.AddView(kImplicitViewId);
471 auto packet = std::make_unique<PointerDataPacket>(2);
474 1);
475 packet->SetPointerData(0, data);
477 packet->SetPointerData(1, data);
478 auto converted_packet = converter.Convert(*packet);
479
480 std::vector<PointerData> result;
481 UnpackPointerPacket(result, std::move(converted_packet));
482
483 ASSERT_EQ(result.size(), (size_t)4);
484 // A add should be synthesized.
485 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
486 ASSERT_EQ(result[0].physical_x, 330.0);
487 ASSERT_EQ(result[0].physical_y, 450.0);
488 ASSERT_EQ(result[0].synthesized, 1);
489 ASSERT_EQ(result[0].buttons, 0);
490
491 ASSERT_EQ(result[1].change, PointerData::Change::kDown);
492 ASSERT_EQ(result[1].physical_x, 330.0);
493 ASSERT_EQ(result[1].physical_y, 450.0);
494 ASSERT_EQ(result[1].synthesized, 0);
495 ASSERT_EQ(result[1].buttons, 1);
496
497 // A move should be synthesized.
498 ASSERT_EQ(result[2].change, PointerData::Change::kMove);
499 ASSERT_EQ(result[2].physical_delta_x, -330.0);
500 ASSERT_EQ(result[2].physical_delta_y, -450.0);
501 ASSERT_EQ(result[2].physical_x, 0.0);
502 ASSERT_EQ(result[2].physical_y, 0.0);
503 ASSERT_EQ(result[2].synthesized, 1);
504 ASSERT_EQ(result[2].buttons, 1);
505
506 ASSERT_EQ(result[3].change, PointerData::Change::kUp);
507 ASSERT_EQ(result[3].physical_x, 0.0);
508 ASSERT_EQ(result[3].physical_y, 0.0);
509 ASSERT_EQ(result[3].synthesized, 0);
510 ASSERT_EQ(result[3].buttons, 0);
511}
512
513TEST(PointerDataPacketConverterTest, CanHandleThreeFingerGesture) {
514 // Regression test https://github.com/flutter/flutter/issues/20517.
515 TestDelegate delegate;
516 delegate.AddView(kImplicitViewId);
519 std::vector<PointerData> result;
520 // First finger down.
521 auto packet = std::make_unique<PointerDataPacket>(1);
523 packet->SetPointerData(0, data);
524 auto converted_packet = converter.Convert(*packet);
525 UnpackPointerPacket(result, std::move(converted_packet));
526 // Second finger down.
527 packet = std::make_unique<PointerDataPacket>(1);
529 1);
530 packet->SetPointerData(0, data);
531 converted_packet = converter.Convert(*packet);
532 UnpackPointerPacket(result, std::move(converted_packet));
533 // Triggers three cancels.
534 packet = std::make_unique<PointerDataPacket>(3);
536 0);
537 packet->SetPointerData(0, data);
539 0);
540 packet->SetPointerData(1, data);
542 0);
543 packet->SetPointerData(2, data);
544 converted_packet = converter.Convert(*packet);
545 UnpackPointerPacket(result, std::move(converted_packet));
546
547 ASSERT_EQ(result.size(), (size_t)6);
548 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
549 ASSERT_EQ(result[0].device, 0);
550 ASSERT_EQ(result[0].physical_x, 0.0);
551 ASSERT_EQ(result[0].physical_y, 0.0);
552 ASSERT_EQ(result[0].synthesized, 1);
553 ASSERT_EQ(result[0].buttons, 0);
554
555 ASSERT_EQ(result[1].change, PointerData::Change::kDown);
556 ASSERT_EQ(result[1].device, 0);
557 ASSERT_EQ(result[1].physical_x, 0.0);
558 ASSERT_EQ(result[1].physical_y, 0.0);
559 ASSERT_EQ(result[1].synthesized, 0);
560 ASSERT_EQ(result[1].buttons, 1);
561
562 ASSERT_EQ(result[2].change, PointerData::Change::kAdd);
563 ASSERT_EQ(result[2].device, 1);
564 ASSERT_EQ(result[2].physical_x, 33.0);
565 ASSERT_EQ(result[2].physical_y, 44.0);
566 ASSERT_EQ(result[2].synthesized, 1);
567 ASSERT_EQ(result[2].buttons, 0);
568
569 ASSERT_EQ(result[3].change, PointerData::Change::kDown);
570 ASSERT_EQ(result[3].device, 1);
571 ASSERT_EQ(result[3].physical_x, 33.0);
572 ASSERT_EQ(result[3].physical_y, 44.0);
573 ASSERT_EQ(result[3].synthesized, 0);
574 ASSERT_EQ(result[3].buttons, 1);
575
576 ASSERT_EQ(result[4].change, PointerData::Change::kCancel);
577 ASSERT_EQ(result[4].device, 1);
578 ASSERT_EQ(result[4].physical_x, 33.0);
579 ASSERT_EQ(result[4].physical_y, 44.0);
580 ASSERT_EQ(result[4].synthesized, 0);
581
582 ASSERT_EQ(result[5].change, PointerData::Change::kCancel);
583 ASSERT_EQ(result[5].device, 0);
584 ASSERT_EQ(result[5].physical_x, 0.0);
585 ASSERT_EQ(result[5].physical_y, 0.0);
586 ASSERT_EQ(result[5].synthesized, 0);
587 // Third cancel should be dropped
588}
589
590TEST(PointerDataPacketConverterTest, CanConvertPointerSignals) {
591 PointerData::SignalKind signal_kinds[] = {
595 };
596 for (const PointerData::SignalKind& kind : signal_kinds) {
597 TestDelegate delegate;
598 delegate.AddView(kImplicitViewId);
600 auto packet = std::make_unique<PointerDataPacket>(6);
604 0.0, 0.0, 0);
605 packet->SetPointerData(0, data);
608 0.0, 0.0, 0);
609 packet->SetPointerData(1, data);
612 0.0, 0.0, 1);
613 packet->SetPointerData(2, data);
615 34.0, 34.0, 30.0, 0.0, 0);
616 packet->SetPointerData(3, data);
618 49.0, 49.0, 50.0, 0.0, 0);
619 packet->SetPointerData(4, data);
621 10.0, 20.0, 30.0, 40.0, 0);
622 packet->SetPointerData(5, data);
623 auto converted_packet = converter.Convert(*packet);
624
625 std::vector<PointerData> result;
626 UnpackPointerPacket(result, std::move(converted_packet));
627
628 ASSERT_EQ(result.size(), (size_t)9);
629 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
630 ASSERT_EQ(result[0].signal_kind, PointerData::SignalKind::kNone);
631 ASSERT_EQ(result[0].device, 0);
632 ASSERT_EQ(result[0].physical_x, 0.0);
633 ASSERT_EQ(result[0].physical_y, 0.0);
634 ASSERT_EQ(result[0].synthesized, 0);
635
636 ASSERT_EQ(result[1].change, PointerData::Change::kAdd);
637 ASSERT_EQ(result[1].signal_kind, PointerData::SignalKind::kNone);
638 ASSERT_EQ(result[1].device, 1);
639 ASSERT_EQ(result[1].physical_x, 0.0);
640 ASSERT_EQ(result[1].physical_y, 0.0);
641 ASSERT_EQ(result[1].synthesized, 0);
642
643 ASSERT_EQ(result[2].change, PointerData::Change::kDown);
644 ASSERT_EQ(result[2].signal_kind, PointerData::SignalKind::kNone);
645 ASSERT_EQ(result[2].device, 1);
646 ASSERT_EQ(result[2].physical_x, 0.0);
647 ASSERT_EQ(result[2].physical_y, 0.0);
648 ASSERT_EQ(result[2].synthesized, 0);
649
650 // Converter will synthesize a hover to position for device 0.
651 ASSERT_EQ(result[3].change, PointerData::Change::kHover);
652 ASSERT_EQ(result[3].signal_kind, PointerData::SignalKind::kNone);
653 ASSERT_EQ(result[3].device, 0);
654 ASSERT_EQ(result[3].physical_x, 34.0);
655 ASSERT_EQ(result[3].physical_y, 34.0);
656 ASSERT_EQ(result[3].physical_delta_x, 34.0);
657 ASSERT_EQ(result[3].physical_delta_y, 34.0);
658 ASSERT_EQ(result[3].buttons, 0);
659 ASSERT_EQ(result[3].synthesized, 1);
660
661 ASSERT_EQ(result[4].change, PointerData::Change::kHover);
662 ASSERT_EQ(result[4].signal_kind, kind);
663 ASSERT_EQ(result[4].device, 0);
664 ASSERT_EQ(result[4].physical_x, 34.0);
665 ASSERT_EQ(result[4].physical_y, 34.0);
666 ASSERT_EQ(result[4].scroll_delta_x, 30.0);
667 ASSERT_EQ(result[4].scroll_delta_y, 0.0);
668
669 // Converter will synthesize a move to position for device 1.
670 ASSERT_EQ(result[5].change, PointerData::Change::kMove);
671 ASSERT_EQ(result[5].signal_kind, PointerData::SignalKind::kNone);
672 ASSERT_EQ(result[5].device, 1);
673 ASSERT_EQ(result[5].physical_x, 49.0);
674 ASSERT_EQ(result[5].physical_y, 49.0);
675 ASSERT_EQ(result[5].physical_delta_x, 49.0);
676 ASSERT_EQ(result[5].physical_delta_y, 49.0);
677 ASSERT_EQ(result[5].buttons, 1);
678 ASSERT_EQ(result[5].synthesized, 1);
679
680 ASSERT_EQ(result[6].change, PointerData::Change::kHover);
681 ASSERT_EQ(result[6].signal_kind, kind);
682 ASSERT_EQ(result[6].device, 1);
683 ASSERT_EQ(result[6].physical_x, 49.0);
684 ASSERT_EQ(result[6].physical_y, 49.0);
685 ASSERT_EQ(result[6].scroll_delta_x, 50.0);
686 ASSERT_EQ(result[6].scroll_delta_y, 0.0);
687
688 // Converter will synthesize an add for device 2.
689 ASSERT_EQ(result[7].change, PointerData::Change::kAdd);
690 ASSERT_EQ(result[7].signal_kind, PointerData::SignalKind::kNone);
691 ASSERT_EQ(result[7].device, 2);
692 ASSERT_EQ(result[7].physical_x, 10.0);
693 ASSERT_EQ(result[7].physical_y, 20.0);
694 ASSERT_EQ(result[7].synthesized, 1);
695
696 ASSERT_EQ(result[8].change, PointerData::Change::kHover);
697 ASSERT_EQ(result[8].signal_kind, kind);
698 ASSERT_EQ(result[8].device, 2);
699 ASSERT_EQ(result[8].physical_x, 10.0);
700 ASSERT_EQ(result[8].physical_y, 20.0);
701 ASSERT_EQ(result[8].scroll_delta_x, 30.0);
702 ASSERT_EQ(result[8].scroll_delta_y, 40.0);
703 }
704}
705
706TEST(PointerDataPacketConverterTest, CanConvertTrackpadGesture) {
707 TestDelegate delegate;
708 delegate.AddView(kImplicitViewId);
710 auto packet = std::make_unique<PointerDataPacket>(3);
713 0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
714 packet->SetPointerData(0, data);
716 0, 0.0, 0.0, 3.0, 4.0, 1.0, 0.0);
717 packet->SetPointerData(1, data);
719 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
720 packet->SetPointerData(2, data);
721 auto converted_packet = converter.Convert(*packet);
722
723 std::vector<PointerData> result;
724 UnpackPointerPacket(result, std::move(converted_packet));
725
726 ASSERT_EQ(result.size(), (size_t)4);
727 ASSERT_EQ(result[0].change, PointerData::Change::kAdd);
728 ASSERT_EQ(result[0].device, 0);
729 ASSERT_EQ(result[0].synthesized, 1);
730
731 ASSERT_EQ(result[1].change, PointerData::Change::kPanZoomStart);
732 ASSERT_EQ(result[1].signal_kind, PointerData::SignalKind::kNone);
733 ASSERT_EQ(result[1].device, 0);
734 ASSERT_EQ(result[1].physical_x, 0.0);
735 ASSERT_EQ(result[1].physical_y, 0.0);
736 ASSERT_EQ(result[1].synthesized, 0);
737
738 ASSERT_EQ(result[2].change, PointerData::Change::kPanZoomUpdate);
739 ASSERT_EQ(result[2].signal_kind, PointerData::SignalKind::kNone);
740 ASSERT_EQ(result[2].device, 0);
741 ASSERT_EQ(result[2].physical_x, 0.0);
742 ASSERT_EQ(result[2].physical_y, 0.0);
743 ASSERT_EQ(result[2].pan_x, 3.0);
744 ASSERT_EQ(result[2].pan_y, 4.0);
745 ASSERT_EQ(result[2].pan_delta_x, 3.0);
746 ASSERT_EQ(result[2].pan_delta_y, 4.0);
747 ASSERT_EQ(result[2].scale, 1.0);
748 ASSERT_EQ(result[2].rotation, 0.0);
749 ASSERT_EQ(result[2].synthesized, 0);
750
751 ASSERT_EQ(result[3].change, PointerData::Change::kPanZoomEnd);
752 ASSERT_EQ(result[3].signal_kind, PointerData::SignalKind::kNone);
753 ASSERT_EQ(result[3].device, 0);
754 ASSERT_EQ(result[3].physical_x, 0.0);
755 ASSERT_EQ(result[3].physical_y, 0.0);
756 ASSERT_EQ(result[3].synthesized, 0);
757}
758
759TEST(PointerDataPacketConverterTest, CanConvertViewId) {
760 TestDelegate delegate;
761 delegate.AddView(100);
762 delegate.AddView(200);
764 auto packet = std::make_unique<PointerDataPacket>(2);
767 data.view_id = 100;
768 packet->SetPointerData(0, data);
770 data.view_id = 200;
771 packet->SetPointerData(1, data);
772 auto converted_packet = converter.Convert(*packet);
773
774 std::vector<PointerData> result;
775 UnpackPointerPacket(result, std::move(converted_packet));
776
777 ASSERT_EQ(result.size(), (size_t)2);
778 ASSERT_EQ(result[0].view_id, 100);
779 ASSERT_EQ(result[1].view_id, 200);
780}
781
782} // namespace testing
783} // namespace flutter
bool ViewExists(int64_t view_id) const override
VkDevice device
Definition: main.cc:53
GAsyncResult * result
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
string converter
Definition: cacheimages.py:19
void CreateSimulatedPointerData(PointerData &data, PointerData::Change change, int64_t device, double dx, double dy, int64_t buttons)
void CreateSimulatedMousePointerData(PointerData &data, PointerData::Change change, PointerData::SignalKind signal_kind, int64_t device, double dx, double dy, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
void CreateSimulatedTrackpadGestureData(PointerData &data, PointerData::Change change, int64_t device, double dx, double dy, double pan_x, double pan_y, double scale, double rotation)
TEST(DisplayListComplexity, EmptyDisplayList)
void UnpackPointerPacket(std::vector< PointerData > &output, std::unique_ptr< PointerDataPacket > packet)
constexpr int64_t kImplicitViewId
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
const Scalar scale