5#include "flutter/lib/ui/window/pointer_data_packet_converter.h"
8#include <unordered_set>
10#include "gtest/gtest.h"
25 return views_.count(view_id) != 0;
28 void AddView(int64_t view_id) { views_.insert(view_id); }
30 void RemoveView(int64_t view_id) { views_.erase(view_id); }
33 std::unordered_set<int64_t> views_;
47 data.pointer_identifier = 0;
50 data.physical_delta_x = 0.0;
51 data.physical_delta_y = 0.0;
52 data.buttons = buttons;
56 data.pressure_min = 0.0;
57 data.pressure_max = 0.0;
59 data.distance_max = 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;
67 data.platformData = 0;
68 data.scroll_delta_x = 0.0;
69 data.scroll_delta_y = 0.0;
79 double scroll_delta_x,
80 double scroll_delta_y,
85 data.signal_kind = signal_kind;
87 data.pointer_identifier = 0;
90 data.physical_delta_x = 0.0;
91 data.physical_delta_y = 0.0;
92 data.buttons = buttons;
96 data.pressure_min = 0.0;
97 data.pressure_max = 0.0;
99 data.distance_max = 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;
107 data.platformData = 0;
108 data.scroll_delta_x = scroll_delta_x;
109 data.scroll_delta_y = scroll_delta_y;
123 data.change = change;
127 data.pointer_identifier = 0;
129 data.physical_y = dy;
130 data.physical_delta_x = 0.0;
131 data.physical_delta_y = 0.0;
134 data.synthesized = 0;
136 data.pressure_min = 0.0;
137 data.pressure_max = 0.0;
139 data.distance_max = 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;
147 data.platformData = 0;
148 data.scroll_delta_x = 0.0;
149 data.scroll_delta_y = 0.0;
152 data.pan_delta_x = 0.0;
153 data.pan_delta_y = 0.0;
155 data.rotation = rotation;
160 std::unique_ptr<PointerDataPacket> packet) {
161 for (
size_t i = 0;
i < packet->GetLength();
i++) {
163 output.push_back(pointer_data);
168TEST(PointerDataPacketConverterTest, CanConvertPointerDataPacket) {
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);
186 packet->SetPointerData(5,
data);
187 auto converted_packet =
converter.Convert(*packet);
189 std::vector<PointerData>
result;
192 ASSERT_EQ(
result.size(), (
size_t)6);
194 ASSERT_EQ(
result[0].synthesized, 0);
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);
202 ASSERT_EQ(
result[2].pointer_identifier, 1);
203 ASSERT_EQ(
result[2].synthesized, 0);
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);
212 ASSERT_EQ(
result[4].pointer_identifier, 1);
213 ASSERT_EQ(
result[4].synthesized, 0);
216 ASSERT_EQ(
result[5].synthesized, 0);
219TEST(PointerDataPacketConverterTest, CanSynthesizeDownAndUp) {
223 auto packet = std::make_unique<PointerDataPacket>(4);
226 packet->SetPointerData(0,
data);
228 packet->SetPointerData(1,
data);
230 packet->SetPointerData(2,
data);
233 packet->SetPointerData(3,
data);
234 auto converted_packet =
converter.Convert(*packet);
236 std::vector<PointerData>
result;
239 ASSERT_EQ(
result.size(), (
size_t)6);
241 ASSERT_EQ(
result[0].synthesized, 0);
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);
251 ASSERT_EQ(
result[2].pointer_identifier, 1);
252 ASSERT_EQ(
result[2].synthesized, 0);
253 ASSERT_EQ(
result[2].buttons, 1);
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);
264 ASSERT_EQ(
result[4].pointer_identifier, 1);
265 ASSERT_EQ(
result[4].synthesized, 0);
266 ASSERT_EQ(
result[4].buttons, 0);
269 ASSERT_EQ(
result[5].synthesized, 0);
272TEST(PointerDataPacketConverterTest, CanUpdatePointerIdentifier) {
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);
292 packet->SetPointerData(6,
data);
293 auto converted_packet =
converter.Convert(*packet);
295 std::vector<PointerData>
result;
298 ASSERT_EQ(
result.size(), (
size_t)7);
300 ASSERT_EQ(
result[0].synthesized, 0);
303 ASSERT_EQ(
result[1].pointer_identifier, 1);
304 ASSERT_EQ(
result[1].synthesized, 0);
307 ASSERT_EQ(
result[2].pointer_identifier, 1);
308 ASSERT_EQ(
result[2].synthesized, 0);
312 ASSERT_EQ(
result[3].pointer_identifier, 2);
313 ASSERT_EQ(
result[3].synthesized, 0);
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);
322 ASSERT_EQ(
result[5].pointer_identifier, 2);
323 ASSERT_EQ(
result[5].synthesized, 0);
326 ASSERT_EQ(
result[6].synthesized, 0);
329TEST(PointerDataPacketConverterTest, AlwaysForwardMoveEvent) {
333 auto packet = std::make_unique<PointerDataPacket>(4);
336 packet->SetPointerData(0,
data);
338 packet->SetPointerData(1,
data);
341 packet->SetPointerData(2,
data);
343 packet->SetPointerData(3,
data);
345 auto converted_packet =
converter.Convert(*packet);
347 std::vector<PointerData>
result;
350 ASSERT_EQ(
result.size(), (
size_t)4);
352 ASSERT_EQ(
result[0].synthesized, 0);
355 ASSERT_EQ(
result[1].pointer_identifier, 1);
356 ASSERT_EQ(
result[1].synthesized, 0);
360 ASSERT_EQ(
result[2].pointer_identifier, 1);
361 ASSERT_EQ(
result[2].synthesized, 0);
364 ASSERT_EQ(
result[3].pointer_identifier, 1);
365 ASSERT_EQ(
result[3].synthesized, 0);
368TEST(PointerDataPacketConverterTest, CanWorkWithDifferentDevices) {
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);
396 packet->SetPointerData(10,
data);
399 packet->SetPointerData(11,
data);
400 auto converted_packet =
converter.Convert(*packet);
402 std::vector<PointerData>
result;
405 ASSERT_EQ(
result.size(), (
size_t)12);
408 ASSERT_EQ(
result[0].synthesized, 0);
412 ASSERT_EQ(
result[1].pointer_identifier, 1);
413 ASSERT_EQ(
result[1].synthesized, 0);
417 ASSERT_EQ(
result[2].synthesized, 0);
421 ASSERT_EQ(
result[3].pointer_identifier, 2);
422 ASSERT_EQ(
result[3].synthesized, 0);
426 ASSERT_EQ(
result[4].pointer_identifier, 1);
427 ASSERT_EQ(
result[4].synthesized, 0);
431 ASSERT_EQ(
result[5].pointer_identifier, 3);
432 ASSERT_EQ(
result[5].synthesized, 0);
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);
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);
450 ASSERT_EQ(
result[8].pointer_identifier, 2);
451 ASSERT_EQ(
result[8].synthesized, 0);
455 ASSERT_EQ(
result[9].pointer_identifier, 3);
456 ASSERT_EQ(
result[9].synthesized, 0);
460 ASSERT_EQ(
result[10].synthesized, 0);
464 ASSERT_EQ(
result[11].synthesized, 0);
467TEST(PointerDataPacketConverterTest, CanSynthesizeAdd) {
471 auto packet = std::make_unique<PointerDataPacket>(2);
475 packet->SetPointerData(0,
data);
477 packet->SetPointerData(1,
data);
478 auto converted_packet =
converter.Convert(*packet);
480 std::vector<PointerData>
result;
483 ASSERT_EQ(
result.size(), (
size_t)4);
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);
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);
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);
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);
513TEST(PointerDataPacketConverterTest, CanHandleThreeFingerGesture) {
519 std::vector<PointerData>
result;
521 auto packet = std::make_unique<PointerDataPacket>(1);
523 packet->SetPointerData(0,
data);
524 auto converted_packet =
converter.Convert(*packet);
527 packet = std::make_unique<PointerDataPacket>(1);
530 packet->SetPointerData(0,
data);
531 converted_packet =
converter.Convert(*packet);
534 packet = std::make_unique<PointerDataPacket>(3);
537 packet->SetPointerData(0,
data);
540 packet->SetPointerData(1,
data);
543 packet->SetPointerData(2,
data);
544 converted_packet =
converter.Convert(*packet);
547 ASSERT_EQ(
result.size(), (
size_t)6);
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);
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);
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);
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);
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);
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);
590TEST(PointerDataPacketConverterTest, CanConvertPointerSignals) {
600 auto packet = std::make_unique<PointerDataPacket>(6);
605 packet->SetPointerData(0,
data);
609 packet->SetPointerData(1,
data);
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);
625 std::vector<PointerData>
result;
628 ASSERT_EQ(
result.size(), (
size_t)9);
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);
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);
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);
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);
662 ASSERT_EQ(
result[4].signal_kind, kind);
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);
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);
681 ASSERT_EQ(
result[6].signal_kind, kind);
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);
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);
697 ASSERT_EQ(
result[8].signal_kind, kind);
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);
706TEST(PointerDataPacketConverterTest, CanConvertTrackpadGesture) {
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);
723 std::vector<PointerData>
result;
726 ASSERT_EQ(
result.size(), (
size_t)4);
729 ASSERT_EQ(
result[0].synthesized, 1);
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);
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);
748 ASSERT_EQ(
result[2].rotation, 0.0);
749 ASSERT_EQ(
result[2].synthesized, 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);
759TEST(PointerDataPacketConverterTest, CanConvertViewId) {
764 auto packet = std::make_unique<PointerDataPacket>(2);
768 packet->SetPointerData(0,
data);
771 packet->SetPointerData(1,
data);
772 auto converted_packet =
converter.Convert(*packet);
774 std::vector<PointerData>
result;
777 ASSERT_EQ(
result.size(), (
size_t)2);
778 ASSERT_EQ(
result[0].view_id, 100);
779 ASSERT_EQ(
result[1].view_id, 200);
void RemoveView(int64_t view_id)
void AddView(int64_t view_id)
bool ViewExists(int64_t view_id) const override
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
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