6#include "gtest/gtest.h"
8#include "flutter/shell/platform/common/app_lifecycle_state.h"
9#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
10#include "flutter/shell/platform/linux/fl_engine_private.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
12#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
13#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
14#include "flutter/shell/platform/linux/testing/fl_test.h"
20TEST(FlEngineTest, WindowMetrics) {
26 SendWindowMetricsEvent,
29 EXPECT_EQ(
event->width,
static_cast<size_t>(3840));
30 EXPECT_EQ(
event->height,
static_cast<size_t>(2160));
31 EXPECT_EQ(
event->pixel_ratio, 2.0);
36 g_autoptr(GError)
error =
nullptr;
38 EXPECT_EQ(
error,
nullptr);
45TEST(FlEngineTest, MousePointer) {
53 size_t events_count) {
55 EXPECT_EQ(events_count,
static_cast<size_t>(1));
56 EXPECT_EQ(events[0].phase,
kDown);
57 EXPECT_EQ(events[0].timestamp,
static_cast<size_t>(1234567890));
58 EXPECT_EQ(events[0].
x, 800);
59 EXPECT_EQ(events[0].
y, 600);
60 EXPECT_EQ(events[0].
device,
static_cast<int32_t
>(0));
62 EXPECT_EQ(events[0].scroll_delta_x, 1.2);
63 EXPECT_EQ(events[0].scroll_delta_y, -3.4);
70 g_autoptr(GError)
error =
nullptr;
72 EXPECT_EQ(
error,
nullptr);
81TEST(FlEngineTest, PointerPanZoom) {
89 size_t events_count) {
91 EXPECT_EQ(events_count,
static_cast<size_t>(1));
93 EXPECT_EQ(events[0].timestamp,
static_cast<size_t>(1234567890));
94 EXPECT_EQ(events[0].
x, 800);
95 EXPECT_EQ(events[0].
y, 600);
96 EXPECT_EQ(events[0].
device,
static_cast<int32_t
>(1));
98 EXPECT_EQ(events[0].pan_x, 1.5);
99 EXPECT_EQ(events[0].pan_y, 2.5);
100 EXPECT_EQ(events[0].
scale, 3.5);
101 EXPECT_EQ(events[0].rotation, 4.5);
103 EXPECT_EQ(events[0].buttons, 0);
108 g_autoptr(GError)
error =
nullptr;
110 EXPECT_EQ(
error,
nullptr);
126 const uint8_t*
data,
size_t data_length) {
127 EXPECT_EQ(
id,
static_cast<uint64_t
>(42));
129 EXPECT_EQ(data_length,
static_cast<size_t>(4));
130 EXPECT_EQ(
data[0],
't');
131 EXPECT_EQ(
data[1],
'e');
132 EXPECT_EQ(
data[2],
's');
133 EXPECT_EQ(
data[3],
't');
139 g_autoptr(GError)
error =
nullptr;
141 EXPECT_EQ(
error,
nullptr);
142 g_autoptr(GBytes)
data = g_bytes_new_static(
"test", 4);
159 ([&called, old_handler](
auto engine,
161 if (strcmp(
message->channel,
"test") != 0) {
162 return old_handler(engine, message);
167 EXPECT_EQ(
message->message_size,
static_cast<size_t>(4));
168 EXPECT_EQ(
message->message[0],
't');
169 EXPECT_EQ(
message->message[1],
'e');
170 EXPECT_EQ(
message->message[2],
's');
171 EXPECT_EQ(
message->message[3],
't');
176 g_autoptr(GError)
error =
nullptr;
178 EXPECT_EQ(
error,
nullptr);
179 g_autoptr(GBytes)
message = g_bytes_new_static(
"test", 4);
193 SendPlatformMessageResponse,
196 const uint8_t*
data,
size_t data_length) {
202 EXPECT_EQ(data_length,
static_cast<size_t>(4));
203 EXPECT_EQ(
data[0],
't');
204 EXPECT_EQ(
data[1],
'e');
205 EXPECT_EQ(
data[2],
's');
206 EXPECT_EQ(
data[3],
't');
211 g_autoptr(GError)
error =
nullptr;
213 EXPECT_EQ(
error,
nullptr);
214 g_autoptr(GBytes) response = g_bytes_new_static(
"test", 4);
218 EXPECT_EQ(
error,
nullptr);
224TEST(FlEngineTest, SettingsPlugin) {
234 EXPECT_STREQ(
message->channel,
"flutter/settings");
237 g_autoptr(GBytes)
data =
239 g_autoptr(GError)
error =
nullptr;
243 EXPECT_EQ(
error,
nullptr);
247 EXPECT_NE(text_scale_factor,
nullptr);
250 FlValue* always_use_24hr_format =
252 EXPECT_NE(always_use_24hr_format,
nullptr);
258 EXPECT_NE(platform_brightness,
nullptr);
264 g_autoptr(GError)
error =
nullptr;
266 EXPECT_EQ(
error,
nullptr);
282TEST(FlEngineTest, OnPreEngineRestart) {
287 void* callback_user_data;
302 g_autoptr(GError)
error =
nullptr;
304 EXPECT_EQ(
error,
nullptr);
327 EXPECT_EQ(
count, 11);
330TEST(FlEngineTest, DartEntrypointArgs) {
333 GPtrArray* args_array = g_ptr_array_new();
334 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_one"));
335 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_two"));
336 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_three"));
337 g_ptr_array_add(args_array,
nullptr);
338 gchar**
args =
reinterpret_cast<gchar**
>(g_ptr_array_free(args_array,
false));
352 EXPECT_NE(set_args,
args->dart_entrypoint_argv);
353 EXPECT_EQ(
args->dart_entrypoint_argc, 3);
358 g_autoptr(GError)
error =
nullptr;
360 EXPECT_EQ(
error,
nullptr);
366 gchar* initial_language = g_strdup(g_getenv(
"LANGUAGE"));
367 g_setenv(
"LANGUAGE",
"de:en_US",
TRUE);
376 size_t locales_count) {
379 EXPECT_EQ(locales_count,
static_cast<size_t>(4));
381 EXPECT_STREQ(locales[0]->language_code,
"de");
382 EXPECT_STREQ(locales[0]->country_code,
nullptr);
383 EXPECT_STREQ(locales[0]->script_code,
nullptr);
384 EXPECT_STREQ(locales[0]->variant_code,
nullptr);
386 EXPECT_STREQ(locales[1]->language_code,
"en");
387 EXPECT_STREQ(locales[1]->country_code,
"US");
388 EXPECT_STREQ(locales[1]->script_code,
nullptr);
389 EXPECT_STREQ(locales[1]->variant_code,
nullptr);
391 EXPECT_STREQ(locales[2]->language_code,
"en");
392 EXPECT_STREQ(locales[2]->country_code,
nullptr);
393 EXPECT_STREQ(locales[2]->script_code,
nullptr);
394 EXPECT_STREQ(locales[2]->variant_code,
nullptr);
396 EXPECT_STREQ(locales[3]->language_code,
"C");
397 EXPECT_STREQ(locales[3]->country_code,
nullptr);
398 EXPECT_STREQ(locales[3]->script_code,
nullptr);
399 EXPECT_STREQ(locales[3]->variant_code,
nullptr);
404 g_autoptr(GError)
error =
nullptr;
406 EXPECT_EQ(
error,
nullptr);
410 if (initial_language) {
411 g_setenv(
"LANGUAGE", initial_language,
TRUE);
413 g_unsetenv(
"LANGUAGE");
415 g_free(initial_language);
418TEST(FlEngineTest, SwitchesEmpty) {
422 unsetenv(
"FLUTTER_ENGINE_SWITCHES");
426 EXPECT_EQ(switches->len, 0
U);
429TEST(FlEngineTest, SendWindowStateEvent) {
438 EXPECT_STREQ(
message->channel,
"flutter/lifecycle");
441 g_autoptr(GBytes)
data =
443 g_autoptr(GError)
error =
nullptr;
465#ifndef FLUTTER_RELEASE
469 setenv(
"FLUTTER_ENGINE_SWITCHES",
"2", 1);
470 setenv(
"FLUTTER_ENGINE_SWITCH_1",
"abc", 1);
471 setenv(
"FLUTTER_ENGINE_SWITCH_2",
"foo=\"bar, baz\"", 1);
474 EXPECT_EQ(switches->len, 2U);
475 EXPECT_STREQ(
static_cast<const char*
>(g_ptr_array_index(switches, 0)),
477 EXPECT_STREQ(
static_cast<const char*
>(g_ptr_array_index(switches, 1)),
478 "--foo=\"bar, baz\"");
480 unsetenv(
"FLUTTER_ENGINE_SWITCHES");
481 unsetenv(
"FLUTTER_ENGINE_SWITCH_1");
482 unsetenv(
"FLUTTER_ENGINE_SWITCH_2");
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
@ kPanZoomUpdate
The pan/zoom updated.
FlutterEngineResult(* FlutterEngineSendPlatformMessageFnPtr)(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *message)
@ kFlutterPointerButtonMouseSecondary
@ kFlutterPointerSignalKindScroll
@ kFlutterPointerSignalKindNone
@ kFlutterSemanticsActionTap
@ kFlutterPointerDeviceKindTrackpad
@ kFlutterPointerDeviceKindMouse
void(* OnPreEngineRestartCallback)(void *)
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
void fl_engine_send_pointer_pan_zoom_event(FlEngine *self, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
void fl_engine_set_on_pre_engine_restart_handler(FlEngine *self, FlEngineOnPreEngineRestartHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
void fl_engine_dispatch_semantics_action(FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
GPtrArray * fl_engine_get_switches(FlEngine *self)
void fl_engine_send_window_state_event(FlEngine *self, gboolean visible, gboolean focused)
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
void fl_engine_send_window_metrics_event(FlEngine *self, size_t width, size_t height, double pixel_ratio)
gboolean fl_engine_start(FlEngine *self, GError **error)
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
void on_pre_engine_restart_cb(FlEngine *engine, gpointer user_data)
TEST(FlEngineTest, WindowMetrics)
void on_pre_engine_restart_destroy_notify(gpointer user_data)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
FlEngine * make_mock_engine_with_project(FlDartProject *project)
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
constexpr const char * AppLifecycleStateToString(AppLifecycleState state)
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
void Initialize(zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
#define MOCK_ENGINE_PROC(proc, mock_impl)
Function-pointer-based versions of the APIs above.
FlutterEngineUpdateLocalesFnPtr UpdateLocales
FlutterEngineSendWindowMetricsEventFnPtr SendWindowMetricsEvent
FlutterEngineSendPointerEventFnPtr SendPointerEvent
FlutterEngineInitializeFnPtr Initialize
FlutterEngineDispatchSemanticsActionFnPtr DispatchSemanticsAction
FlutterEngineSendPlatformMessageFnPtr SendPlatformMessage
FlutterEngineSendPlatformMessageResponseFnPtr SendPlatformMessageResponse
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)