@@ -20,10 +20,81 @@ std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
2020 properties.icu_data_path = L" C:\\ foo\\ icudtl.dat" ;
2121 properties.aot_library_path = L" C:\\ foo\\ aot.so" ;
2222 FlutterProjectBundle project (properties);
23- return std::make_unique<FlutterWindowsEngine>(project);
23+ auto engine = std::make_unique<FlutterWindowsEngine>(project);
24+
25+ EngineEmbedderApiModifier modifier (engine.get ());
26+ // Force the non-AOT path unless overridden by the test.
27+ modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
28+
29+ return engine;
2430}
2531} // namespace
2632
33+ TEST (FlutterWindowsEngine, RunDoesExpectedInitialization) {
34+ std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
35+ EngineEmbedderApiModifier modifier (engine.get ());
36+
37+ // The engine should be run with expected configuration values.
38+ bool run_called = false ;
39+ modifier.embedder_api ().Run = MOCK_ENGINE_PROC (
40+ Run, ([&run_called, engine_instance = engine.get ()](
41+ size_t version, const FlutterRendererConfig* config,
42+ const FlutterProjectArgs* args, void * user_data,
43+ FLUTTER_API_SYMBOL (FlutterEngine) * engine_out) {
44+ run_called = true ;
45+ *engine_out = reinterpret_cast <FLUTTER_API_SYMBOL (FlutterEngine)>(1 );
46+
47+ EXPECT_EQ (version, FLUTTER_ENGINE_VERSION);
48+ EXPECT_NE (config, nullptr );
49+ EXPECT_EQ (user_data, engine_instance);
50+ // Spot-check arguments.
51+ EXPECT_STREQ (args->assets_path , " C:\\ foo\\ flutter_assets" );
52+ EXPECT_STREQ (args->icu_data_path , " C:\\ foo\\ icudtl.dat" );
53+ EXPECT_EQ (args->dart_entrypoint_argc , 0 );
54+ EXPECT_NE (args->platform_message_callback , nullptr );
55+ EXPECT_NE (args->custom_task_runners , nullptr );
56+ EXPECT_EQ (args->custom_dart_entrypoint , nullptr );
57+
58+ return kSuccess ;
59+ }));
60+
61+ // It should send locale info.
62+ bool update_locales_called = false ;
63+ modifier.embedder_api ().UpdateLocales = MOCK_ENGINE_PROC (
64+ UpdateLocales,
65+ ([&update_locales_called](auto engine, const FlutterLocale** locales,
66+ size_t locales_count) {
67+ update_locales_called = true ;
68+
69+ EXPECT_GT (locales_count, 0 );
70+ EXPECT_NE (locales, nullptr );
71+
72+ return kSuccess ;
73+ }));
74+
75+ // And it should send initial settings info.
76+ bool settings_message_sent = false ;
77+ modifier.embedder_api ().SendPlatformMessage = MOCK_ENGINE_PROC (
78+ SendPlatformMessage,
79+ ([&settings_message_sent](auto engine, auto message) {
80+ if (std::string (message->channel ) == std::string (" flutter/settings" )) {
81+ settings_message_sent = true ;
82+ }
83+
84+ return kSuccess ;
85+ }));
86+
87+ engine->RunWithEntrypoint (nullptr );
88+
89+ EXPECT_TRUE (run_called);
90+ EXPECT_TRUE (update_locales_called);
91+ EXPECT_TRUE (settings_message_sent);
92+
93+ // Ensure that deallocation doesn't call the actual Shutdown with the bogus
94+ // engine pointer that the overridden Run returned.
95+ modifier.embedder_api ().Shutdown = [](auto engine) { return kSuccess ; };
96+ }
97+
2798TEST (FlutterWindowsEngine, SendPlatformMessageWithoutResponse) {
2899 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
29100 EngineEmbedderApiModifier modifier (engine.get ());
0 commit comments