5#include "flutter/shell/platform/windows/flutter_windows_engine.h"
7#include "flutter/fml/logging.h"
8#include "flutter/fml/macros.h"
9#include "flutter/shell/platform/embedder/embedder.h"
10#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
11#include "flutter/shell/platform/windows/flutter_windows_view.h"
12#include "flutter/shell/platform/windows/public/flutter_windows.h"
13#include "flutter/shell/platform/windows/testing/egl/mock_manager.h"
14#include "flutter/shell/platform/windows/testing/engine_modifier.h"
15#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
16#include "flutter/shell/platform/windows/testing/mock_platform_view_manager.h"
17#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
18#include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h"
19#include "flutter/shell/platform/windows/testing/test_keyboard.h"
20#include "flutter/shell/platform/windows/testing/windows_test.h"
21#include "flutter/shell/platform/windows/testing/windows_test_config_builder.h"
22#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h"
24#include "gmock/gmock.h"
25#include "gtest/gtest.h"
33using ::testing::NiceMock;
34using ::testing::Return;
41 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
46 ASSERT_TRUE(
engine->Run());
48 ASSERT_EQ(
engine->view(123),
nullptr);
53 builder.AddDartEntrypointArgument(
"arg1");
54 builder.AddDartEntrypointArgument(
"arg2");
56 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
60 bool run_called =
false;
62 Run, ([&run_called, engine_instance =
engine.get()](
70 EXPECT_NE(config,
nullptr);
75 EXPECT_NE(
args->assets_path,
nullptr);
76 EXPECT_NE(
args->icu_data_path,
nullptr);
77 EXPECT_EQ(
args->dart_entrypoint_argc, 2U);
78 EXPECT_EQ(strcmp(
args->dart_entrypoint_argv[0],
"arg1"), 0);
79 EXPECT_EQ(strcmp(
args->dart_entrypoint_argv[1],
"arg2"), 0);
80 EXPECT_NE(
args->platform_message_callback,
nullptr);
81 EXPECT_NE(
args->custom_task_runners,
nullptr);
82 EXPECT_NE(
args->custom_task_runners->thread_priority_setter,
nullptr);
83 EXPECT_EQ(
args->custom_dart_entrypoint,
nullptr);
84 EXPECT_NE(
args->vsync_callback,
nullptr);
85 EXPECT_EQ(
args->update_semantics_callback,
nullptr);
86 EXPECT_NE(
args->update_semantics_callback2,
nullptr);
87 EXPECT_EQ(
args->update_semantics_node_callback,
nullptr);
88 EXPECT_EQ(
args->update_semantics_custom_action_callback,
nullptr);
90 args->custom_task_runners->thread_priority_setter(
92 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
93 THREAD_PRIORITY_ABOVE_NORMAL);
98 UpdateAccessibilityFeatures,
103 bool update_locales_called =
false;
107 size_t locales_count) {
108 update_locales_called =
true;
110 EXPECT_GT(locales_count, 0);
111 EXPECT_NE(locales,
nullptr);
117 bool settings_message_sent =
false;
121 if (std::string(
message->channel) == std::string(
"flutter/settings")) {
122 settings_message_sent = true;
129 bool notify_display_update_called =
false;
133 ([¬ify_display_update_called, engine_instance =
engine.get()](
137 size_t display_count) {
139 EXPECT_EQ(display_count, 1);
147 notify_display_update_called =
true;
152 modifier.
SetEGLManager(std::make_unique<egl::MockManager>());
169 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
171 bool on_vsync_called =
false;
177 ([&on_vsync_called, engine_instance =
engine.get()](
179 uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos) {
181 EXPECT_EQ(frame_start_time_nanos, 16600000);
182 EXPECT_EQ(frame_target_time_nanos, 33200000);
183 on_vsync_called =
true;
196 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
201 ([engine_instance =
engine.get()](
205 size_t display_count) {
return kSuccess; }));
208 bool run_called =
false;
210 Run, ([&run_called, engine_instance =
engine.get()](
222 UpdateAccessibilityFeatures,
230 size_t locales_count) {
return kSuccess; }));
249 builder.SetSwitches({
"--enable-impeller=true"});
250 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
255 ([engine_instance =
engine.get()](
259 size_t display_count) {
return kSuccess; }));
263 UpdateAccessibilityFeatures,
271 size_t locales_count) {
return kSuccess; }));
279 EXPECT_FALSE(
engine->Run());
284 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
287 const char* channel =
"test";
288 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
293 SendPlatformMessage, ([&called, test_message](
auto engine,
auto message) {
295 EXPECT_STREQ(
message->channel,
"test");
296 EXPECT_EQ(
message->message_size, test_message.size());
300 EXPECT_EQ(
message->response_handle,
nullptr);
304 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
311 builder.SetDartEntrypoint(
"hiPlatformChannels");
313 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
317 auto binary_messenger =
318 std::make_unique<BinaryMessengerImpl>(
engine->messenger());
321 bool did_call_callback =
false;
322 bool did_call_reply =
false;
323 bool did_call_dart_reply =
false;
324 std::string channel =
"hi";
325 binary_messenger->SetMessageHandler(
327 [&did_call_callback, &did_call_dart_reply](
329 if (message_size == 5) {
330 EXPECT_EQ(
message[0],
static_cast<uint8_t
>(
'h'));
331 char response[] = {
'b',
'y',
'e'};
332 reply(
reinterpret_cast<uint8_t*
>(response), 3);
333 did_call_callback =
true;
335 EXPECT_EQ(message_size, 3);
336 EXPECT_EQ(
message[0],
static_cast<uint8_t
>(
'b'));
337 did_call_dart_reply =
true;
340 char payload[] = {
'h',
'e',
'l',
'l',
'o'};
341 binary_messenger->Send(
342 channel,
reinterpret_cast<uint8_t*
>(payload), 5,
343 [&did_call_reply](
const uint8_t* reply,
size_t reply_size) {
344 EXPECT_EQ(reply_size, 5);
345 EXPECT_EQ(reply[0],
static_cast<uint8_t
>(
'h'));
346 did_call_reply =
true;
349 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
350 engine->task_runner()->ProcessTasks();
356 builder.SetDartEntrypoint(
"hiPlatformChannels");
358 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
363 auto binary_messenger =
364 std::make_unique<BinaryMessengerImpl>(
engine->messenger());
367 bool did_call_callback =
false;
368 bool did_call_reply =
false;
369 bool did_call_dart_reply =
false;
370 std::string channel =
"hi";
371 std::unique_ptr<std::thread> reply_thread;
372 binary_messenger->SetMessageHandler(
374 [&did_call_callback, &did_call_dart_reply, &reply_thread](
376 if (message_size == 5) {
377 EXPECT_EQ(
message[0],
static_cast<uint8_t
>(
'h'));
378 reply_thread.reset(
new std::thread([reply = std::move(reply)]() {
379 char response[] = {
'b',
'y',
'e'};
380 reply(
reinterpret_cast<uint8_t*
>(response), 3);
382 did_call_callback =
true;
384 EXPECT_EQ(message_size, 3);
385 EXPECT_EQ(
message[0],
static_cast<uint8_t
>(
'b'));
386 did_call_dart_reply =
true;
389 char payload[] = {
'h',
'e',
'l',
'l',
'o'};
390 binary_messenger->Send(
391 channel,
reinterpret_cast<uint8_t*
>(payload), 5,
392 [&did_call_reply](
const uint8_t* reply,
size_t reply_size) {
393 EXPECT_EQ(reply_size, 5);
394 EXPECT_EQ(reply[0],
static_cast<uint8_t
>(
'h'));
395 did_call_reply =
true;
398 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
399 engine->task_runner()->ProcessTasks();
401 ASSERT_TRUE(reply_thread);
402 reply_thread->join();
407 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
410 const char* channel =
"test";
411 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
412 auto* dummy_response_handle =
415 void* reply_user_data =
reinterpret_cast<void*
>(6);
419 bool create_response_handle_called =
false;
422 PlatformMessageCreateResponseHandle,
423 ([&create_response_handle_called, &reply_handler, reply_user_data,
425 auto response_handle) {
426 create_response_handle_called =
true;
427 EXPECT_EQ(reply, reply_handler);
429 EXPECT_NE(response_handle,
nullptr);
430 *response_handle = dummy_response_handle;
433 bool release_response_handle_called =
false;
436 PlatformMessageReleaseResponseHandle,
437 ([&release_response_handle_called, dummy_response_handle](
438 auto engine,
auto response_handle) {
439 release_response_handle_called =
true;
440 EXPECT_EQ(response_handle, dummy_response_handle);
443 bool send_message_called =
false;
445 SendPlatformMessage, ([&send_message_called, test_message,
447 send_message_called =
true;
448 EXPECT_STREQ(
message->channel,
"test");
449 EXPECT_EQ(
message->message_size, test_message.size());
453 EXPECT_EQ(
message->response_handle, dummy_response_handle);
457 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
458 reply_handler, reply_user_data);
466 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
479 EXPECT_EQ(data_length,
message.size());
491 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
492 THREAD_PRIORITY_BELOW_NORMAL);
495 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
496 THREAD_PRIORITY_ABOVE_NORMAL);
499 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
500 THREAD_PRIORITY_ABOVE_NORMAL);
504 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
507 EXPECT_EQ(GetThreadPriority(GetCurrentThread()), THREAD_PRIORITY_NORMAL);
512 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
516 std::make_shared<MockKeyResponseController>());
523 engine->AddPluginRegistrarDestructionCallback(
525 auto result =
reinterpret_cast<int*
>(ref);
529 engine->AddPluginRegistrarDestructionCallback(
531 auto result =
reinterpret_cast<int*
>(ref);
537 EXPECT_EQ(result1, 1);
538 EXPECT_EQ(result2, 2);
543 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
559 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
569 engine->SetNextFrameCallback([]() {});
575 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
576 EXPECT_EQ(
engine->GetExecutableName(),
"flutter_windows_unittests.exe");
582 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
583 EXPECT_CALL(*windows_proc_table, GetHighContrastEnabled)
584 .WillOnce(Return(
true))
585 .WillOnce(Return(
false));
588 builder.SetWindowsProcTable(windows_proc_table);
589 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
592 std::optional<FlutterAccessibilityFeature> engine_flags;
594 UpdateAccessibilityFeatures, ([&engine_flags](
auto engine,
auto flags) {
595 engine_flags =
flags;
603 engine->UpdateHighContrastMode();
608 engine_flags.value() &
612 engine_flags.reset();
613 engine->UpdateHighContrastMode();
615 EXPECT_FALSE(
engine->high_contrast_enabled());
618 engine_flags.value() &
624 std::unique_ptr<FlutterWindowsEngine>
engine =
builder.Build();
628 PostRenderThreadTask, ([](
auto engine,
auto callback,
auto context) {
634 engine->PostRasterThreadTask([&called]() { called =
true; });
642 std::unique_ptr<WindowBindingHandler> wbh)
647 NotifyWinEventWrapper,
660 builder.SetDartEntrypoint(
"sendAccessibilityAnnouncement");
665 context.AddNativeFunction(
"Signal", native_entry);
668 ASSERT_NE(
engine,
nullptr);
673 auto window_binding_handler =
674 std::make_unique<NiceMock<MockWindowBindingHandler>>();
675 EXPECT_CALL(*window_binding_handler, GetAlertDelegate)
676 .WillOnce(Return(&delegate));
679 MockFlutterWindowsView view{windows_engine,
680 std::move(window_binding_handler)};
684 windows_engine->UpdateSemanticsEnabled(
true);
686 EXPECT_CALL(view, NotifyWinEventWrapper).Times(1);
690 windows_engine->task_runner()->ProcessTasks();
698 builder.SetDartEntrypoint(
"sendAccessibilityAnnouncement");
703 context.AddNativeFunction(
"Signal", native_entry);
706 ASSERT_NE(
engine,
nullptr);
713 windows_engine->task_runner()->ProcessTasks();
724 builder.SetDartEntrypoint(
"sendAccessibilityTooltipEvent");
729 context.AddNativeFunction(
"Signal", native_entry);
732 ASSERT_NE(controller,
nullptr);
740 windows_engine->task_runner()->ProcessTasks();
746 EXPECT_EQ(log_capture.
str().find(
"tooltip"), std::string::npos);
758 (std::optional<HWND>, std::optional<WPARAM>, std::optional<LPARAM>,
UINT),
776 builder.SetDartEntrypoint(
"exitTestExit");
777 bool finished =
false;
780 auto window_binding_handler =
781 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
782 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
787 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
789 EXPECT_CALL(*handler, Quit)
790 .WillOnce([&finished](std::optional<HWND> hwnd,
791 std::optional<WPARAM> wparam,
792 std::optional<LPARAM> lparam,
793 UINT exit_code) { finished = exit_code == 0; });
794 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(
true));
797 engine->lifecycle_manager()->BeginProcessingExit();
801 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
807 engine->task_runner()->ProcessTasks();
813 builder.SetDartEntrypoint(
"exitTestCancel");
814 bool did_call =
false;
817 auto window_binding_handler =
818 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
819 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
824 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
826 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(
true));
827 EXPECT_CALL(*handler, Quit).Times(0);
829 engine->lifecycle_manager()->BeginProcessingExit();
831 auto binary_messenger =
832 std::make_unique<BinaryMessengerImpl>(
engine->messenger());
833 binary_messenger->SetMessageHandler(
834 "flutter/platform", [&did_call](
const uint8_t*
message,
837 EXPECT_NE(contents.find(
"\"method\":\"System.exitApplication\""),
839 EXPECT_NE(contents.find(
"\"type\":\"required\""), std::string::npos);
840 EXPECT_NE(contents.find(
"\"exitCode\":0"), std::string::npos);
842 char response[] =
"";
843 reply(
reinterpret_cast<uint8_t*
>(response), 0);
848 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
852 engine->task_runner()->ProcessTasks();
861 builder.SetDartEntrypoint(
"exitTestExit");
862 bool second_close =
false;
865 auto window_binding_handler =
866 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
867 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
872 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
874 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(
true));
875 EXPECT_CALL(*handler, Quit)
876 .WillOnce([handler_ptr = handler.get()](
877 std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
878 std::optional<LPARAM> lparam,
UINT exit_code) {
879 handler_ptr->WindowsLifecycleManager::Quit(hwnd, wparam, lparam,
885 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
886 hwnd, msg, wparam, lparam);
889 engine->lifecycle_manager()->BeginProcessingExit();
897 engine->window_proc_delegate_manager()->RegisterTopLevelWindowProcDelegate(
902 bool* called =
reinterpret_cast<bool*
>(
user_data);
909 reinterpret_cast<void*
>(&second_close));
911 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
914 while (!second_close) {
915 engine->task_runner()->ProcessTasks();
921 builder.SetDartEntrypoint(
"exitTestExit");
922 bool finished =
false;
925 auto window_binding_handler =
926 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
927 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
932 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
934 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce([&finished]() {
939 EXPECT_CALL(*handler, Quit).Times(0);
941 engine->lifecycle_manager()->BeginProcessingExit();
945 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
949 engine->task_runner()->ProcessTasks();
957 auto window_binding_handler =
958 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
959 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
964 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
965 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(0);
968 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
976 auto window_binding_handler =
977 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
978 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
983 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
984 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(
false));
986 engine->lifecycle_manager()->BeginProcessingExit();
988 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
996 auto window_binding_handler =
997 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
998 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1003 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
1004 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(
false));
1006 engine->lifecycle_manager()->BeginProcessingExit();
1008 engine->lifecycle_manager()->ExternalWindowMessage(0, WM_CLOSE, 0, 0);
1015 auto window_binding_handler =
1016 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1017 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1022 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
1033 auto window_binding_handler =
1034 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1035 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1042 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1043 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1044 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1047 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1048 (HWND)1, WM_SIZE, SIZE_MINIMIZED, 0);
1049 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1052 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1053 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1054 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1062 auto window_binding_handler =
1063 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1064 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1073 engine->ProcessExternalWindowMessage(
reinterpret_cast<HWND
>(1), WM_SHOWWINDOW,
1075 engine->ProcessExternalWindowMessage(
reinterpret_cast<HWND
>(1), WM_SHOWWINDOW,
1078 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1084 HWND outer =
reinterpret_cast<HWND
>(1);
1085 HWND inner =
reinterpret_cast<HWND
>(2);
1088 auto window_binding_handler =
1089 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1090 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1091 ON_CALL(view, GetWindowHandle).WillByDefault([=]() {
return inner; });
1100 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1101 outer, WM_SHOWWINDOW,
TRUE, NULL);
1105 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1112 EXPECT_EQ(
engine->lifecycle_manager()->GetLifecycleState(),
1118 builder.SetDartEntrypoint(
"enableLifecycleTest");
1119 bool finished =
false;
1122 auto window_binding_handler =
1123 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1124 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1129 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
1130 EXPECT_CALL(*handler, SetLifecycleState)
1132 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1136 auto binary_messenger =
1137 std::make_unique<BinaryMessengerImpl>(
engine->messenger());
1139 binary_messenger->SetMessageHandler(
1140 "flutter/unittest", [&finished](
const uint8_t*
message,
1143 EXPECT_NE(contents.find(
"AppLifecycleState.inactive"),
1146 char response[] =
"";
1147 reply(
reinterpret_cast<uint8_t*
>(response), 0);
1153 HWND hwnd =
reinterpret_cast<HWND
>(1);
1156 EXPECT_FALSE(finished);
1160 engine->lifecycle_manager()->BeginProcessingLifecycle();
1164 engine->task_runner()->ProcessTasks();
1170 builder.SetDartEntrypoint(
"enableLifecycleToFrom");
1171 bool enabled_lifecycle =
false;
1172 bool dart_responded =
false;
1175 auto window_binding_handler =
1176 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1177 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1182 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
1183 EXPECT_CALL(*handler, SetLifecycleState)
1185 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1187 handler->begin_processing_callback = [&]() { enabled_lifecycle =
true; };
1190 auto binary_messenger =
1191 std::make_unique<BinaryMessengerImpl>(
engine->messenger());
1192 binary_messenger->SetMessageHandler(
1196 EXPECT_NE(contents.find(
"AppLifecycleState."), std::string::npos);
1197 dart_responded =
true;
1198 char response[] =
"";
1199 reply(
reinterpret_cast<uint8_t*
>(response), 0);
1204 while (!enabled_lifecycle) {
1205 engine->task_runner()->ProcessTasks();
1208 HWND hwnd =
reinterpret_cast<HWND
>(1);
1212 while (!dart_responded) {
1213 engine->task_runner()->ProcessTasks();
1219 builder.SetDartEntrypoint(
"enableLifecycleToFrom");
1222 auto window_binding_handler =
1223 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1224 MockFlutterWindowsView view(
engine.get(), std::move(window_binding_handler));
1230 bool lifecycle_began =
false;
1231 auto handler = std::make_unique<MockWindowsLifecycleManager>(
engine.get());
1232 EXPECT_CALL(*handler, SetLifecycleState).Times(1);
1233 handler->begin_processing_callback = [&]() { lifecycle_began =
true; };
1238 while (!lifecycle_began) {
1239 engine->task_runner()->ProcessTasks();
1245 builder.SetDartEntrypoint(
"sendCreatePlatformViewMethod");
1249 modifier.embedder_api().RunsAOTCompiledDartCode = []() {
return false; };
1251 bool received_call =
false;
1253 auto manager = std::make_unique<MockPlatformViewManager>(
engine.get());
1254 EXPECT_CALL(*
manager, AddPlatformView)
1256 received_call =
true;
1259 modifier.SetPlatformViewPlugin(std::move(
manager));
1263 while (!received_call) {
1264 engine->task_runner()->ProcessTasks();
1274 modifier.embedder_api().RunsAOTCompiledDartCode = []() {
return false; };
1280 ASSERT_TRUE(
engine->Run());
1284 auto implicit_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1286 std::unique_ptr<FlutterWindowsView> implicit_view =
1287 engine->CreateView(std::move(implicit_window));
1292 auto second_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1294 EXPECT_DEBUG_DEATH(
engine->CreateView(std::move(second_window)),
1295 "FlutterEngineAddView returned an unexpected result");
1300 builder.SetDartEntrypoint(
"sendCreatePlatformViewMethod");
1305 modifier.embedder_api().RunsAOTCompiledDartCode = []() {
return false; };
1311 ASSERT_TRUE(
engine->Run());
1312 EXPECT_DEBUG_DEATH(
engine->RemoveView(123),
1313 "FlutterEngineRemoveView returned an unexpected result");
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
void SetLifecycleManager(std::unique_ptr< WindowsLifecycleManager > &&handler)
void SetFrameInterval(uint64_t frame_interval_nanos)
void SetEGLManager(std::unique_ptr< egl::Manager > egl_manager)
void SetStartTime(uint64_t start_time_nanos)
Reset the start_time field that is used to align vsync events.
FlutterEngineProcTable & embedder_api()
void SetImplicitView(FlutterWindowsView *view)
void UpdateSemanticsEnabled(bool enabled)
virtual void Quit(std::optional< HWND > window, std::optional< WPARAM > wparam, std::optional< LPARAM > lparam, UINT exit_code)
virtual void BeginProcessingLifecycle()
virtual void DispatchMessage(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
virtual bool IsLastWindowOfProcess()
virtual void SetLifecycleState(AppLifecycleState state)
~MockFlutterWindowsView()
MOCK_METHOD(void, NotifyWinEventWrapper,(ui::AXPlatformNodeWin *, ax::mojom::Event),(override))
MockFlutterWindowsView(FlutterWindowsEngine *engine, std::unique_ptr< WindowBindingHandler > wbh)
MOCK_METHOD(HWND, GetWindowHandle,(),(const, override))
virtual ~MockWindowsLifecycleManager()
std::function< void()> begin_processing_callback
MOCK_METHOD(void, DispatchMessage,(HWND, UINT, WPARAM, LPARAM),(override))
MOCK_METHOD(void, Quit,(std::optional< HWND >, std::optional< WPARAM >, std::optional< LPARAM >, UINT),(override))
MOCK_METHOD(void, SetLifecycleState,(AppLifecycleState),(override))
void BeginProcessingLifecycle() override
MOCK_METHOD(bool, IsLastWindowOfProcess,(),(override))
MockWindowsLifecycleManager(FlutterWindowsEngine *engine)
static MallocMapping Copy(const T *begin, const T *end)
struct _Dart_NativeArguments * Dart_NativeArguments
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
FlutterAccessibilityFeature
@ kFlutterAccessibilityFeatureHighContrast
Request that UI be rendered with darker colors.
FlutterEngineDisplaysUpdateType
@ kFlutterEngineDisplaysUpdateTypeStartup
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
@ kDisplay
Suitable for threads which generate data for the display.
@ kNormal
Default priority level.
@ kRaster
Suitable for thread which raster data.
@ kFlutterSemanticsActionDismiss
A request that the node should be dismissed.
#define FLUTTER_ENGINE_VERSION
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Dart_NativeFunction function
SK_API GrDirectContext * GetContext(const SkImage *src)
TEST_F(DisplayListTest, Defaults)
std::unique_ptr< FlutterDesktopEngine, EngineDeleter > EnginePtr
std::unique_ptr< FlutterDesktopViewController, ViewControllerDeleter > ViewControllerPtr
void MockEmbedderApiForKeyboard(EngineModifier &modifier, std::shared_ptr< MockKeyResponseController > response_controller)
constexpr int64_t kImplicitViewId
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
static void ScheduleFrame(JNIEnv *env, jobject jcaller, jlong shell_holder)
SIN Vec< N, float > floor(const Vec< N, float > &x)
#define MOCK_ENGINE_PROC(proc, mock_impl)
FlutterEngineDisplayId display_id
FlutterEngineScheduleFrameFnPtr ScheduleFrame
FlutterEnginePlatformMessageReleaseResponseHandleFnPtr PlatformMessageReleaseResponseHandle
FlutterEngineUpdateLocalesFnPtr UpdateLocales
FlutterEngineRunsAOTCompiledDartCodeFnPtr RunsAOTCompiledDartCode
FlutterEngineSetNextFrameCallbackFnPtr SetNextFrameCallback
FlutterEngineShutdownFnPtr Shutdown
FlutterEngineOnVsyncFnPtr OnVsync
FlutterEngineGetCurrentTimeFnPtr GetCurrentTime
FlutterEngineDispatchSemanticsActionFnPtr DispatchSemanticsAction
FlutterEngineNotifyDisplayUpdateFnPtr NotifyDisplayUpdate
FlutterEngineSendPlatformMessageFnPtr SendPlatformMessage
FlutterEnginePlatformMessageCreateResponseHandleFnPtr PlatformMessageCreateResponseHandle
FlutterEngineRunFnPtr Run
FlutterEngineUpdateAccessibilityFeaturesFnPtr UpdateAccessibilityFeatures
FlutterEnginePostRenderThreadTaskFnPtr PostRenderThreadTask
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef controller)
#define CREATE_NATIVE_ENTRY(native_entry)
#define EXPECT_TRUE(handle)