88#include " flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
99#include " flutter/shell/platform/windows/testing/engine_modifier.h"
1010#include " flutter/shell/platform/windows/testing/test_keyboard.h"
11+ #include " flutter/shell/platform/windows/testing/windows_test.h"
12+ #include " fml/synchronization/waitable_event.h"
1113#include " gtest/gtest.h"
1214
1315// winbase.h defines GetCurrentTime as a macro.
@@ -40,7 +42,9 @@ std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
4042}
4143} // namespace
4244
43- TEST (FlutterWindowsEngine, RunDoesExpectedInitialization) {
45+ class FlutterWindowsEngineTest : public WindowsTest {};
46+
47+ TEST_F (FlutterWindowsEngineTest, RunDoesExpectedInitialization) {
4448 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
4549 EngineModifier modifier (engine.get ());
4650
@@ -148,7 +152,7 @@ TEST(FlutterWindowsEngine, RunDoesExpectedInitialization) {
148152 modifier.ReleaseSurfaceManager ();
149153}
150154
151- TEST (FlutterWindowsEngine , ConfiguresFrameVsync) {
155+ TEST_F (FlutterWindowsEngineTest , ConfiguresFrameVsync) {
152156 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
153157 EngineModifier modifier (engine.get ());
154158 bool on_vsync_called = false ;
@@ -174,7 +178,7 @@ TEST(FlutterWindowsEngine, ConfiguresFrameVsync) {
174178 EXPECT_TRUE (on_vsync_called);
175179}
176180
177- TEST (FlutterWindowsEngine , RunWithoutANGLEUsesSoftware) {
181+ TEST_F (FlutterWindowsEngineTest , RunWithoutANGLEUsesSoftware) {
178182 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
179183 EngineModifier modifier (engine.get ());
180184
@@ -226,7 +230,7 @@ TEST(FlutterWindowsEngine, RunWithoutANGLEUsesSoftware) {
226230 modifier.embedder_api ().Shutdown = [](auto engine) { return kSuccess ; };
227231}
228232
229- TEST (FlutterWindowsEngine , SendPlatformMessageWithoutResponse) {
233+ TEST_F (FlutterWindowsEngineTest , SendPlatformMessageWithoutResponse) {
230234 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
231235 EngineModifier modifier (engine.get ());
232236
@@ -252,7 +256,48 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithoutResponse) {
252256 EXPECT_TRUE (called);
253257}
254258
255- TEST (FlutterWindowsEngine, SendPlatformMessageWithResponse) {
259+ TEST_F (FlutterWindowsEngineTest, PlatformMessageRoundTrip) {
260+ FlutterDesktopEngineProperties properties = {};
261+ properties.assets_path = GetContext ().GetAssetsPath ().c_str ();
262+ properties.icu_data_path = GetContext ().GetIcuDataPath ().c_str ();
263+ properties.dart_entrypoint = " hiPlatformChannels" ;
264+
265+ FlutterProjectBundle project (properties);
266+ auto engine = std::make_unique<FlutterWindowsEngine>(project);
267+
268+ EngineModifier modifier (engine.get ());
269+ modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
270+
271+ auto binary_messenger =
272+ std::make_unique<BinaryMessengerImpl>(engine->messenger ());
273+
274+ engine->Run ();
275+ bool did_call_callback = false ;
276+ bool did_call_reply = false ;
277+ std::string channel = " hi" ;
278+ binary_messenger->SetMessageHandler (
279+ channel, [&did_call_callback](const uint8_t * message, size_t message_size,
280+ BinaryReply reply) {
281+ EXPECT_EQ (message_size, 5 );
282+ char response[] = {' b' , ' y' , ' e' };
283+ reply (reinterpret_cast <uint8_t *>(response), 3 );
284+ did_call_callback = true ;
285+ });
286+ char payload[] = {' h' , ' e' , ' l' , ' l' , ' o' };
287+ binary_messenger->Send (
288+ channel, reinterpret_cast <uint8_t *>(payload), 5 ,
289+ [&did_call_reply](const uint8_t * reply, size_t reply_size) {
290+ EXPECT_EQ (reply_size, 3 );
291+ EXPECT_EQ (reply[0 ], static_cast <uint8_t >(' b' ));
292+ did_call_reply = true ;
293+ });
294+ // Rely on timeout mechanism in CI.
295+ while (!did_call_callback && !did_call_reply) {
296+ engine->task_runner ()->ProcessTasks ();
297+ }
298+ }
299+
300+ TEST_F (FlutterWindowsEngineTest, SendPlatformMessageWithResponse) {
256301 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
257302 EngineModifier modifier (engine.get ());
258303
@@ -310,7 +355,7 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
310355 EXPECT_TRUE (send_message_called);
311356}
312357
313- TEST (FlutterWindowsEngine , DispatchSemanticsAction) {
358+ TEST_F (FlutterWindowsEngineTest , DispatchSemanticsAction) {
314359 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
315360 EngineModifier modifier (engine.get ());
316361
@@ -334,7 +379,7 @@ TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
334379 EXPECT_TRUE (called);
335380}
336381
337- TEST (FlutterWindowsEngine , SetsThreadPriority) {
382+ TEST_F (FlutterWindowsEngineTest , SetsThreadPriority) {
338383 WindowsPlatformThreadPrioritySetter (FlutterThreadPriority::kBackground );
339384 EXPECT_EQ (GetThreadPriority (GetCurrentThread ()),
340385 THREAD_PRIORITY_BELOW_NORMAL);
@@ -355,7 +400,7 @@ TEST(FlutterWindowsEngine, SetsThreadPriority) {
355400 EXPECT_EQ (GetThreadPriority (GetCurrentThread ()), THREAD_PRIORITY_NORMAL);
356401}
357402
358- TEST (FlutterWindowsEngine , AddPluginRegistrarDestructionCallback) {
403+ TEST_F (FlutterWindowsEngineTest , AddPluginRegistrarDestructionCallback) {
359404 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
360405 EngineModifier modifier (engine.get ());
361406
@@ -385,7 +430,7 @@ TEST(FlutterWindowsEngine, AddPluginRegistrarDestructionCallback) {
385430 EXPECT_EQ (result2, 2 );
386431}
387432
388- TEST (FlutterWindowsEngine , ScheduleFrame) {
433+ TEST_F (FlutterWindowsEngineTest , ScheduleFrame) {
389434 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
390435 EngineModifier modifier (engine.get ());
391436
@@ -400,7 +445,7 @@ TEST(FlutterWindowsEngine, ScheduleFrame) {
400445 EXPECT_TRUE (called);
401446}
402447
403- TEST (FlutterWindowsEngine , SetNextFrameCallback) {
448+ TEST_F (FlutterWindowsEngineTest , SetNextFrameCallback) {
404449 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
405450 EngineModifier modifier (engine.get ());
406451
@@ -415,14 +460,14 @@ TEST(FlutterWindowsEngine, SetNextFrameCallback) {
415460 EXPECT_TRUE (called);
416461}
417462
418- TEST (FlutterWindowsEngine , GetExecutableName) {
463+ TEST_F (FlutterWindowsEngineTest , GetExecutableName) {
419464 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
420465 EXPECT_EQ (engine->GetExecutableName (), " flutter_windows_unittests.exe" );
421466}
422467
423468// Ensure that after setting or resetting the high contrast feature,
424469// the corresponding status flag can be retrieved from the engine.
425- TEST (FlutterWindowsEngine , UpdateHighContrastFeature) {
470+ TEST_F (FlutterWindowsEngineTest , UpdateHighContrastFeature) {
426471 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
427472 EngineModifier modifier (engine.get ());
428473
@@ -447,7 +492,7 @@ TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
447492 EXPECT_FALSE (engine->high_contrast_enabled ());
448493}
449494
450- TEST (FlutterWindowsEngine , PostRasterThreadTask) {
495+ TEST_F (FlutterWindowsEngineTest , PostRasterThreadTask) {
451496 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
452497 EngineModifier modifier (engine.get ());
453498
0 commit comments