| Flutter Linux Embedder |

Functions
fl_engine_test.cc File Reference
`#include "gtest/gtest.h"`
`#include "flutter/shell/platform/common/app_lifecycle_state.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"`
`#include "flutter/shell/platform/linux/testing/fl_test.h"`

Go to the source code of this file.

## Functions
| TEST (FlEngineTest, WindowMetrics)
| TEST (FlEngineTest, MousePointer)
| TEST (FlEngineTest, PointerPanZoom)
| TEST (FlEngineTest, DispatchSemanticsAction)
| TEST (FlEngineTest, PlatformMessage)
| TEST (FlEngineTest, PlatformMessageResponse)
| TEST (FlEngineTest, SettingsPlugin)
void | on_pre_engine_restart_cb (FlEngine *engine, gpointer user_data)
void | on_pre_engine_restart_destroy_notify (gpointer user_data)
| TEST (FlEngineTest, OnPreEngineRestart)
| TEST (FlEngineTest, DartEntrypointArgs)
| TEST (FlEngineTest, Locales)
| TEST (FlEngineTest, SwitchesEmpty)
| TEST (FlEngineTest, SendWindowStateEvent)
| TEST (FlEngineTest, Switches)

## Function Documentation

## ◆ on_pre_engine_restart_cb()

void on_pre_engine_restart_cb | ( | FlEngine * | engine,
|  | gpointer | user_data
| ) |  |

Definition at line 271 of file fl_engine_test.cc.

271 {
272 int* count = reinterpret_cast<int*>(user_data);
273 *count += 1;
274 }

References user_data.

Referenced by TEST().

## ◆ on_pre_engine_restart_destroy_notify()

void on_pre_engine_restart_destroy_notify | ( | gpointer | user_data | ) |

Definition at line 276 of file fl_engine_test.cc.

276 {
277 int* count = reinterpret_cast<int*>(user_data);
278 *count += 10;
279 }

References user_data.

Referenced by TEST().

## ◆ TEST() [1/13]

TEST | ( | FlEngineTest | ,
|  | DartEntrypointArgs |
| ) |  |

Definition at line 330 of file fl_engine_test.cc.

330 {
331 g_autoptr(FlDartProject) project = fl_dart_project_new();
332
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));
339
340 fl_dart_project_set_dart_entrypoint_arguments(project, args);
341
342 g_autoptr(FlEngine) engine = make_mock_engine_with_project(project);
343 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
344
345 bool called = false;
346 embedder_api->Initialize = MOCK_ENGINE_PROC(
347 Initialize, ([&called, &set_args = args](
348 size_t version, const FlutterRendererConfig* config,
349 const FlutterProjectArgs* args, void* user_data,
350 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
351 called = true;
352 EXPECT_NE(set_args, args->dart_entrypoint_argv);
353 EXPECT_EQ(args->dart_entrypoint_argc, 3);
354
355 return kSuccess;
356 }));
357
358 g_autoptr(GError) error = nullptr;
359 EXPECT_TRUE(fl_engine_start(engine, &error));
360 EXPECT_EQ(error, nullptr);
361
362 EXPECT_TRUE(called);
363 }

References args, error, fl_dart_project_new(), fl_dart_project_set_dart_entrypoint_arguments(), fl_engine_get_embedder_api(), fl_engine_start(), and user_data.

## ◆ TEST() [2/13]

TEST | ( | FlEngineTest | ,
|  | DispatchSemanticsAction |
| ) |  |

Definition at line 118 of file fl_engine_test.cc.

118 {
119 g_autoptr(FlEngine) engine = make_mock_engine();
120 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
121
122 bool called = false;
123 embedder_api->DispatchSemanticsAction = MOCK_ENGINE_PROC(
124 DispatchSemanticsAction,
125 ([&called](auto engine, uint64_t id, FlutterSemanticsAction action,
126 const uint8_t* data, size_t data_length) {
127 EXPECT_EQ(id, static_cast<uint64_t>(42));
128 EXPECT_EQ(action, kFlutterSemanticsActionTap);
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');
134 called = true;
135
136 return kSuccess;
137 }));
138
139 g_autoptr(GError) error = nullptr;
140 EXPECT_TRUE(fl_engine_start(engine, &error));
141 EXPECT_EQ(error, nullptr);
142 g_autoptr(GBytes) data = g_bytes_new_static("test", 4);
143 fl_engine_dispatch_semantics_action(engine, 42, kFlutterSemanticsActionTap,
144 data);
145
146 EXPECT_TRUE(called);
147 }

References error, fl_engine_dispatch_semantics_action(), fl_engine_get_embedder_api(), fl_engine_start(), and make_mock_engine().

## ◆ TEST() [3/13]

TEST | ( | FlEngineTest | ,
|  | Locales |
| ) |  |

Definition at line 365 of file fl_engine_test.cc.

365 {
366 gchar* initial_language = g_strdup(g_getenv("LANGUAGE"));
367 g_setenv("LANGUAGE", "de:en_US", TRUE);
368 g_autoptr(FlDartProject) project = fl_dart_project_new();
369
370 g_autoptr(FlEngine) engine = make_mock_engine_with_project(project);
371 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
372
373 bool called = false;
374 embedder_api->UpdateLocales = MOCK_ENGINE_PROC(
375 UpdateLocales, ([&called](auto engine, const FlutterLocale** locales,
376 size_t locales_count) {
377 called = true;
378
379 EXPECT_EQ(locales_count, static_cast<size_t>(4));
380
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);
385
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);
390
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);
395
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);
400
401 return kSuccess;
402 }));
403
404 g_autoptr(GError) error = nullptr;
405 EXPECT_TRUE(fl_engine_start(engine, &error));
406 EXPECT_EQ(error, nullptr);
407
408 EXPECT_TRUE(called);
409
410 if (initial_language) {
411 g_setenv("LANGUAGE", initial_language, TRUE);
412 } else {
413 g_unsetenv("LANGUAGE");
414 }
415 g_free(initial_language);
416 }

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), and TRUE.

## ◆ TEST() [4/13]

TEST | ( | FlEngineTest | ,
|  | MousePointer |
| ) |  |

Definition at line 45 of file fl_engine_test.cc.

45 {
46 g_autoptr(FlEngine) engine = make_mock_engine();
47 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
48
49 bool called = false;
50 embedder_api->SendPointerEvent = MOCK_ENGINE_PROC(
51 SendPointerEvent,
52 ([&called](auto engine, const FlutterPointerEvent* events,
53 size_t events_count) {
54 called = true;
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));
61 EXPECT_EQ(events[0].signal_kind, kFlutterPointerSignalKindScroll);
62 EXPECT_EQ(events[0].scroll_delta_x, 1.2);
63 EXPECT_EQ(events[0].scroll_delta_y, -3.4);
64 EXPECT_EQ(events[0].device_kind, kFlutterPointerDeviceKindMouse);
65 EXPECT_EQ(events[0].buttons, kFlutterPointerButtonMouseSecondary);
66
67 return kSuccess;
68 }));
69
70 g_autoptr(GError) error = nullptr;
71 EXPECT_TRUE(fl_engine_start(engine, &error));
72 EXPECT_EQ(error, nullptr);
73 fl_engine_send_mouse_pointer_event(engine, kDown, 1234567890, 800, 600,
74 kFlutterPointerDeviceKindMouse, 1.2, -3.4,
75 kFlutterPointerButtonMouseSecondary);
76
77 EXPECT_TRUE(called);
78 }

References error, fl_engine_get_embedder_api(), fl_engine_send_mouse_pointer_event(), fl_engine_start(), and make_mock_engine().

## ◆ TEST() [5/13]

TEST | ( | FlEngineTest | ,
|  | OnPreEngineRestart |
| ) |  |

Definition at line 282 of file fl_engine_test.cc.

282 {
283 FlEngine* engine = make_mock_engine();
284 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
285
286 OnPreEngineRestartCallback callback;
287 void* callback_user_data;
288
289 bool called = false;
290 embedder_api->Initialize = MOCK_ENGINE_PROC(
291 Initialize, ([&callback, &callback_user_data, &called](
292 size_t version, const FlutterRendererConfig* config,
293 const FlutterProjectArgs* args, void* user_data,
294 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
295 called = true;
296 callback = args->on_pre_engine_restart_callback;
297 callback_user_data = user_data;
298
299 return kSuccess;
300 }));
301
302 g_autoptr(GError) error = nullptr;
303 EXPECT_TRUE(fl_engine_start(engine, &error));
304 EXPECT_EQ(error, nullptr);
305
306 EXPECT_TRUE(called);
307 EXPECT_NE(callback, nullptr);
308
309 // The following call has no effect but should not crash.
310 callback(callback_user_data);
311
312 int count = 0;
313
314 // Set handler so that:
315 //
316 // * When the engine restarts, count += 1;
317 // * When the engine is freed, count += 10.
318 fl_engine_set_on_pre_engine_restart_handler(
319 engine, on_pre_engine_restart_cb, &count,
320 on_pre_engine_restart_destroy_notify);
321
322 callback(callback_user_data);
323 EXPECT_EQ(count, 1);
324
325 // Disposal should call the destroy notify.
326 g_object_unref(engine);
327 EXPECT_EQ(count, 11);
328 }

References args, callback, error, fl_engine_get_embedder_api(), fl_engine_set_on_pre_engine_restart_handler(), fl_engine_start(), make_mock_engine(), on_pre_engine_restart_cb(), on_pre_engine_restart_destroy_notify(), and user_data.

## ◆ TEST() [6/13]

TEST | ( | FlEngineTest | ,
|  | PlatformMessage |
| ) |  |

Definition at line 150 of file fl_engine_test.cc.

150 {
151 g_autoptr(FlEngine) engine = make_mock_engine();
152 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
153
154 bool called = false;
155 FlutterEngineSendPlatformMessageFnPtr old_handler =
156 embedder_api->SendPlatformMessage;
157 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
158 SendPlatformMessage,
159 ([&called, old_handler](auto engine,
160 const FlutterPlatformMessage* message) {
161 if (strcmp(message->channel, "test") != 0) {
162 return old_handler(engine, message);
163 }
164
165 called = true;
166
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');
172
173 return kSuccess;
174 }));
175
176 g_autoptr(GError) error = nullptr;
177 EXPECT_TRUE(fl_engine_start(engine, &error));
178 EXPECT_EQ(error, nullptr);
179 g_autoptr(GBytes) message = g_bytes_new_static("test", 4);
180 fl_engine_send_platform_message(engine, "test", message, nullptr, nullptr,
181 nullptr);
182
183 EXPECT_TRUE(called);
184 }

References error, fl_engine_get_embedder_api(), fl_engine_send_platform_message(), fl_engine_start(), and make_mock_engine().

## ◆ TEST() [7/13]

TEST | ( | FlEngineTest | ,
|  | PlatformMessageResponse |
| ) |  |

Definition at line 187 of file fl_engine_test.cc.

187 {
188 g_autoptr(FlEngine) engine = make_mock_engine();
189 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
190
191 bool called = false;
192 embedder_api->SendPlatformMessageResponse = MOCK_ENGINE_PROC(
193 SendPlatformMessageResponse,
194 ([&called](auto engine,
195 const FlutterPlatformMessageResponseHandle* handle,
196 const uint8_t* data, size_t data_length) {
197 called = true;
198
199 EXPECT_EQ(
200 handle,
201 reinterpret_cast<const FlutterPlatformMessageResponseHandle*>(42));
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');
207
208 return kSuccess;
209 }));
210
211 g_autoptr(GError) error = nullptr;
212 EXPECT_TRUE(fl_engine_start(engine, &error));
213 EXPECT_EQ(error, nullptr);
214 g_autoptr(GBytes) response = g_bytes_new_static("test", 4);
215 EXPECT_TRUE(fl_engine_send_platform_message_response(
216 engine, reinterpret_cast<const FlutterPlatformMessageResponseHandle*>(42),
217 response, &error));
218 EXPECT_EQ(error, nullptr);
219
220 EXPECT_TRUE(called);
221 }

References error, fl_engine_get_embedder_api(), fl_engine_send_platform_message_response(), fl_engine_start(), and make_mock_engine().

## ◆ TEST() [8/13]

TEST | ( | FlEngineTest | ,
|  | PointerPanZoom |
| ) |  |

Definition at line 81 of file fl_engine_test.cc.

81 {
82 g_autoptr(FlEngine) engine = make_mock_engine();
83 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
84
85 bool called = false;
86 embedder_api->SendPointerEvent = MOCK_ENGINE_PROC(
87 SendPointerEvent,
88 ([&called](auto engine, const FlutterPointerEvent* events,
89 size_t events_count) {
90 called = true;
91 EXPECT_EQ(events_count, static_cast<size_t>(1));
92 EXPECT_EQ(events[0].phase, kPanZoomUpdate);
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));
97 EXPECT_EQ(events[0].signal_kind, kFlutterPointerSignalKindNone);
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);
102 EXPECT_EQ(events[0].device_kind, kFlutterPointerDeviceKindTrackpad);
103 EXPECT_EQ(events[0].buttons, 0);
104
105 return kSuccess;
106 }));
107
108 g_autoptr(GError) error = nullptr;
109 EXPECT_TRUE(fl_engine_start(engine, &error));
110 EXPECT_EQ(error, nullptr);
111 fl_engine_send_pointer_pan_zoom_event(engine, 1234567890, 800, 600,
112 kPanZoomUpdate, 1.5, 2.5, 3.5, 4.5);
113
114 EXPECT_TRUE(called);
115 }

References error, fl_engine_get_embedder_api(), fl_engine_send_pointer_pan_zoom_event(), fl_engine_start(), and make_mock_engine().

## ◆ TEST() [9/13]

TEST | ( | FlEngineTest | ,
|  | SendWindowStateEvent |
| ) |  |

Definition at line 429 of file fl_engine_test.cc.

429 {
430 g_autoptr(FlEngine) engine = make_mock_engine();
431 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
432
433 bool called = false;
434 std::string state;
435 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
436 SendPlatformMessage,
437 ([&called, &state](auto engine, const FlutterPlatformMessage* message) {
438 EXPECT_STREQ(message->channel, "flutter/lifecycle");
439 called = true;
440 g_autoptr(FlStringCodec) codec = fl_string_codec_new();
441 g_autoptr(GBytes) data =
442 g_bytes_new(message->message, message->message_size);
443 g_autoptr(GError) error = nullptr;
444 g_autoptr(FlValue) parsed_state = fl_message_codec_decode_message(
445 FL_MESSAGE_CODEC(codec), data, &error);
446
447 state = fl_value_get_string(parsed_state);
448 return kSuccess;
449 }));
450 fl_engine_send_window_state_event(engine, false, false);
451 EXPECT_STREQ(state.c_str(), flutter::AppLifecycleStateToString(
452 flutter::AppLifecycleState::kHidden));
453 fl_engine_send_window_state_event(engine, false, true);
454 EXPECT_STREQ(state.c_str(), flutter::AppLifecycleStateToString(
455 flutter::AppLifecycleState::kHidden));
456 fl_engine_send_window_state_event(engine, true, false);
457 EXPECT_STREQ(state.c_str(), flutter::AppLifecycleStateToString(
458 flutter::AppLifecycleState::kInactive));
459 fl_engine_send_window_state_event(engine, true, true);
460 EXPECT_STREQ(state.c_str(), flutter::AppLifecycleStateToString(
461 flutter::AppLifecycleState::kResumed));
462 EXPECT_TRUE(called);
463 }

References flutter::AppLifecycleStateToString(), error, fl_engine_get_embedder_api(), fl_engine_send_window_state_event(), fl_message_codec_decode_message(), fl_string_codec_new(), fl_value_get_string(), flutter::kHidden, flutter::kInactive, flutter::kResumed, make_mock_engine(), and state.

## ◆ TEST() [10/13]

TEST | ( | FlEngineTest | ,
|  | SettingsPlugin |
| ) |  |

Definition at line 224 of file fl_engine_test.cc.

224 {
225 g_autoptr(FlEngine) engine = make_mock_engine();
226 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
227
228 bool called = false;
229 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
230 SendPlatformMessage,
231 ([&called](auto engine, const FlutterPlatformMessage* message) {
232 called = true;
233
234 EXPECT_STREQ(message->channel, "flutter/settings");
235
236 g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new();
237 g_autoptr(GBytes) data =
238 g_bytes_new(message->message, message->message_size);
239 g_autoptr(GError) error = nullptr;
240 g_autoptr(FlValue) settings = fl_message_codec_decode_message(
241 FL_MESSAGE_CODEC(codec), data, &error);
242 EXPECT_NE(settings, nullptr);
243 EXPECT_EQ(error, nullptr);
244
245 FlValue* text_scale_factor =
246 fl_value_lookup_string(settings, "textScaleFactor");
247 EXPECT_NE(text_scale_factor, nullptr);
248 EXPECT_EQ(fl_value_get_type(text_scale_factor), FL_VALUE_TYPE_FLOAT);
249
250 FlValue* always_use_24hr_format =
251 fl_value_lookup_string(settings, "alwaysUse24HourFormat");
252 EXPECT_NE(always_use_24hr_format, nullptr);
253 EXPECT_EQ(fl_value_get_type(always_use_24hr_format),
254 FL_VALUE_TYPE_BOOL);
255
256 FlValue* platform_brightness =
257 fl_value_lookup_string(settings, "platformBrightness");
258 EXPECT_NE(platform_brightness, nullptr);
259 EXPECT_EQ(fl_value_get_type(platform_brightness), FL_VALUE_TYPE_STRING);
260
261 return kSuccess;
262 }));
263
264 g_autoptr(GError) error = nullptr;
265 EXPECT_TRUE(fl_engine_start(engine, &error));
266 EXPECT_EQ(error, nullptr);
267
268 EXPECT_TRUE(called);
269 }

References error, fl_engine_get_embedder_api(), fl_engine_start(), fl_json_message_codec_new(), fl_message_codec_decode_message(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_BOOL, FL_VALUE_TYPE_FLOAT, FL_VALUE_TYPE_STRING, and make_mock_engine().

## ◆ TEST() [11/13]

TEST | ( | FlEngineTest | ,
|  | Switches |
| ) |  |

Definition at line 466 of file fl_engine_test.cc.

466 {
467 g_autoptr(FlEngine) engine = make_mock_engine();
468
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);
472
473 g_autoptr(GPtrArray) switches = fl_engine_get_switches(engine);
474 EXPECT_EQ(switches->len, 2U);
475 EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 0)),
476 "--abc");
477 EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 1)),
478 "--foo=\"bar, baz\"");
479
480 unsetenv("FLUTTER_ENGINE_SWITCHES");
481 unsetenv("FLUTTER_ENGINE_SWITCH_1");
482 unsetenv("FLUTTER_ENGINE_SWITCH_2");
483 }

References fl_engine_get_switches(), and make_mock_engine().

## ◆ TEST() [12/13]

TEST | ( | FlEngineTest | ,
|  | SwitchesEmpty |
| ) |  |

Definition at line 418 of file fl_engine_test.cc.

418 {
419 g_autoptr(FlEngine) engine = make_mock_engine();
420
421 // Clear the main environment variable, since test order is not guaranteed.
422 unsetenv("FLUTTER_ENGINE_SWITCHES");
423
424 g_autoptr(GPtrArray) switches = fl_engine_get_switches(engine);
425
426 EXPECT_EQ(switches->len, 0U);
427 }

References fl_engine_get_switches(), and make_mock_engine().

## ◆ TEST() [13/13]

TEST | ( | FlEngineTest | ,
|  | WindowMetrics |
| ) |  |

Definition at line 20 of file fl_engine_test.cc.

20 {
21 g_autoptr(FlEngine) engine = make_mock_engine();
22 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
23
24 bool called = false;
25 embedder_api->SendWindowMetricsEvent = MOCK_ENGINE_PROC(
26 SendWindowMetricsEvent,
27 ([&called](auto engine, const FlutterWindowMetricsEvent* event) {
28 called = true;
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);
32
33 return kSuccess;
34 }));
35
36 g_autoptr(GError) error = nullptr;
37 EXPECT_TRUE(fl_engine_start(engine, &error));
38 EXPECT_EQ(error, nullptr);
39 fl_engine_send_window_metrics_event(engine, 3840, 2160, 2.0);
40
41 EXPECT_TRUE(called);
42 }

References error, event, fl_engine_get_embedder_api(), fl_engine_send_window_metrics_event(), fl_engine_start(), and make_mock_engine().

event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
flutter::AppLifecycleState::kHidden
@ kHidden
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:602
on_pre_engine_restart_destroy_notify
void on_pre_engine_restart_destroy_notify(gpointer user_data)
Definition: fl_engine_test.cc:276
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_json_message_codec_new
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
Definition: fl_json_message_codec.cc:306
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
fl_engine_dispatch_semantics_action
void fl_engine_dispatch_semantics_action(FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
Definition: fl_engine.cc:876
fl_engine_send_window_metrics_event
void fl_engine_send_window_metrics_event(FlEngine *self, size_t width, size_t height, double pixel_ratio)
Definition: fl_engine.cc:771
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
state
AtkStateType state
Definition: fl_accessible_node.cc:10
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
fl_engine_send_pointer_pan_zoom_event
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)
Definition: fl_engine.cc:829
flutter::AppLifecycleState::kInactive
@ kInactive
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
fl_dart_project_set_dart_entrypoint_arguments
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
Definition: fl_dart_project.cc:110
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
flutter::AppLifecycleState::kResumed
@ kResumed
fl_engine_send_mouse_pointer_event
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)
Definition: fl_engine.cc:793
fl_engine_send_platform_message
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:691
on_pre_engine_restart_cb
void on_pre_engine_restart_cb(FlEngine *engine, gpointer user_data)
Definition: fl_engine_test.cc:271
fl_string_codec_new
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
Definition: fl_string_codec.cc:53
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:474
FL_VALUE_TYPE_FLOAT
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:68
fl_engine_send_window_state_event
void fl_engine_send_window_state_event(FlEngine *self, gboolean visible, gboolean focused)
Definition: fl_engine.cc:759
flutter::AppLifecycleStateToString
constexpr const char * AppLifecycleStateToString(AppLifecycleState state)
Definition: app_lifecycle_state.h:72
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
fl_engine_get_switches
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:951
FL_VALUE_TYPE_BOOL
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:66
fl_engine_send_platform_message_response
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:659
fl_engine_set_on_pre_engine_restart_handler
void fl_engine_set_on_pre_engine_restart_handler(FlEngine *self, FlEngineOnPreEngineRestartHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:641