Flutter Linux Embedder
fl_touch_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 
6 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
8 
9 #include <gdk/gdkwayland.h>
10 #include <cstring>
11 #include <vector>
12 
13 #include "gtest/gtest.h"
14 
15 TEST(FlTouchManagerTest, TouchEvents) {
16  g_autoptr(FlDartProject) project = fl_dart_project_new();
17  g_autoptr(FlEngine) engine = fl_engine_new(project);
18 
19  g_autoptr(GError) error = nullptr;
20  EXPECT_TRUE(fl_engine_start(engine, &error));
21  EXPECT_EQ(error, nullptr);
22 
23  std::vector<FlutterPointerEvent> pointer_events;
24  fl_engine_get_embedder_api(engine)->SendPointerEvent = MOCK_ENGINE_PROC(
25  SendPointerEvent,
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]);
30  }
31 
32  return kSuccess;
33  }));
34 
35  g_autoptr(FlTouchManager) manager = fl_touch_manager_new(engine, 0);
36 
37  GdkDevice* touchscreen =
38  GDK_DEVICE(g_object_new(gdk_wayland_device_get_type(), "input-source",
39  GDK_SOURCE_TOUCHSCREEN, nullptr));
40  GdkEventTouch* event =
41  reinterpret_cast<GdkEventTouch*>(gdk_event_new(GDK_TOUCH_BEGIN));
42  event->time = 1;
43  event->x = 4.0;
44  event->y = 8.0;
45  event->device = touchscreen;
46  fl_touch_manager_handle_touch_event(manager, event, 1.0);
47  EXPECT_EQ(pointer_events.size(), 2u);
48  EXPECT_EQ(pointer_events[0].x, 4.0);
49  EXPECT_EQ(pointer_events[0].y, 8.0);
50  EXPECT_EQ(pointer_events[0].device_kind, kFlutterPointerDeviceKindTouch);
51  EXPECT_EQ(pointer_events[0].timestamp,
52  1000lu); // Milliseconds -> Microseconds
53  EXPECT_EQ(pointer_events[0].phase, kAdd);
54 
55  EXPECT_EQ(pointer_events[1].x, 4.0);
56  EXPECT_EQ(pointer_events[1].y, 8.0);
57  EXPECT_EQ(pointer_events[1].device_kind, kFlutterPointerDeviceKindTouch);
58  EXPECT_EQ(pointer_events[1].timestamp,
59  1000lu); // Milliseconds -> Microseconds
60  EXPECT_EQ(pointer_events[1].phase, kDown);
61 
62  event->type = GDK_TOUCH_UPDATE;
63  fl_touch_manager_handle_touch_event(manager, event, 1.0);
64  EXPECT_EQ(pointer_events.size(), 3u);
65  EXPECT_EQ(pointer_events[2].x, 4.0);
66  EXPECT_EQ(pointer_events[2].y, 8.0);
67  EXPECT_EQ(pointer_events[2].device_kind, kFlutterPointerDeviceKindTouch);
68  EXPECT_EQ(pointer_events[2].timestamp,
69  1000lu); // Milliseconds -> Microseconds
70  EXPECT_EQ(pointer_events[2].phase, kMove);
71 
72  event->type = GDK_TOUCH_END;
73  fl_touch_manager_handle_touch_event(manager, event, 1.0);
74  EXPECT_EQ(pointer_events.size(), 5u);
75  EXPECT_EQ(pointer_events[3].x, 4.0);
76  EXPECT_EQ(pointer_events[3].y, 8.0);
77  EXPECT_EQ(pointer_events[3].device_kind, kFlutterPointerDeviceKindTouch);
78  EXPECT_EQ(pointer_events[3].timestamp,
79  1000lu); // Milliseconds -> Microseconds
80  EXPECT_EQ(pointer_events[3].phase, kUp);
81 
82  EXPECT_EQ(pointer_events[4].x, 4.0);
83  EXPECT_EQ(pointer_events[4].y, 8.0);
84  EXPECT_EQ(pointer_events[4].device_kind, kFlutterPointerDeviceKindTouch);
85  EXPECT_EQ(pointer_events[4].timestamp,
86  1000lu); // Milliseconds -> Microseconds
87  EXPECT_EQ(pointer_events[4].phase, kRemove);
88 }
TEST
TEST(FlTouchManagerTest, TouchEvents)
Definition: fl_touch_manager_test.cc:15
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:721
fl_touch_manager.h
i
int i
Definition: fl_socket_accessible.cc:18
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_touch_manager_handle_touch_event
void fl_touch_manager_handle_touch_event(FlTouchManager *self, GdkEventTouch *touch_event, gint scale_factor)
Definition: fl_touch_manager.cc:131
fl_engine_private.h
fl_touch_manager_new
FlTouchManager * fl_touch_manager_new(FlEngine *engine, FlutterViewId view_id)
Definition: fl_touch_manager.cc:48
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:580
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:607