8
8
#include " flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
9
9
#include " flutter/shell/platform/windows/testing/engine_modifier.h"
10
10
#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"
11
13
#include " gtest/gtest.h"
12
14
13
15
// winbase.h defines GetCurrentTime as a macro.
@@ -40,7 +42,9 @@ std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
40
42
}
41
43
} // namespace
42
44
43
- TEST (FlutterWindowsEngine, RunDoesExpectedInitialization) {
45
+ class FlutterWindowsEngineTest : public WindowsTest {};
46
+
47
+ TEST_F (FlutterWindowsEngineTest, RunDoesExpectedInitialization) {
44
48
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
45
49
EngineModifier modifier (engine.get ());
46
50
@@ -148,7 +152,7 @@ TEST(FlutterWindowsEngine, RunDoesExpectedInitialization) {
148
152
modifier.ReleaseSurfaceManager ();
149
153
}
150
154
151
- TEST (FlutterWindowsEngine , ConfiguresFrameVsync) {
155
+ TEST_F (FlutterWindowsEngineTest , ConfiguresFrameVsync) {
152
156
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
153
157
EngineModifier modifier (engine.get ());
154
158
bool on_vsync_called = false ;
@@ -174,7 +178,7 @@ TEST(FlutterWindowsEngine, ConfiguresFrameVsync) {
174
178
EXPECT_TRUE (on_vsync_called);
175
179
}
176
180
177
- TEST (FlutterWindowsEngine , RunWithoutANGLEUsesSoftware) {
181
+ TEST_F (FlutterWindowsEngineTest , RunWithoutANGLEUsesSoftware) {
178
182
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
179
183
EngineModifier modifier (engine.get ());
180
184
@@ -226,7 +230,7 @@ TEST(FlutterWindowsEngine, RunWithoutANGLEUsesSoftware) {
226
230
modifier.embedder_api ().Shutdown = [](auto engine) { return kSuccess ; };
227
231
}
228
232
229
- TEST (FlutterWindowsEngine , SendPlatformMessageWithoutResponse) {
233
+ TEST_F (FlutterWindowsEngineTest , SendPlatformMessageWithoutResponse) {
230
234
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
231
235
EngineModifier modifier (engine.get ());
232
236
@@ -252,7 +256,48 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithoutResponse) {
252
256
EXPECT_TRUE (called);
253
257
}
254
258
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) {
256
301
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
257
302
EngineModifier modifier (engine.get ());
258
303
@@ -310,7 +355,7 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
310
355
EXPECT_TRUE (send_message_called);
311
356
}
312
357
313
- TEST (FlutterWindowsEngine , DispatchSemanticsAction) {
358
+ TEST_F (FlutterWindowsEngineTest , DispatchSemanticsAction) {
314
359
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
315
360
EngineModifier modifier (engine.get ());
316
361
@@ -334,7 +379,7 @@ TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
334
379
EXPECT_TRUE (called);
335
380
}
336
381
337
- TEST (FlutterWindowsEngine , SetsThreadPriority) {
382
+ TEST_F (FlutterWindowsEngineTest , SetsThreadPriority) {
338
383
WindowsPlatformThreadPrioritySetter (FlutterThreadPriority::kBackground );
339
384
EXPECT_EQ (GetThreadPriority (GetCurrentThread ()),
340
385
THREAD_PRIORITY_BELOW_NORMAL);
@@ -355,7 +400,7 @@ TEST(FlutterWindowsEngine, SetsThreadPriority) {
355
400
EXPECT_EQ (GetThreadPriority (GetCurrentThread ()), THREAD_PRIORITY_NORMAL);
356
401
}
357
402
358
- TEST (FlutterWindowsEngine , AddPluginRegistrarDestructionCallback) {
403
+ TEST_F (FlutterWindowsEngineTest , AddPluginRegistrarDestructionCallback) {
359
404
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
360
405
EngineModifier modifier (engine.get ());
361
406
@@ -385,7 +430,7 @@ TEST(FlutterWindowsEngine, AddPluginRegistrarDestructionCallback) {
385
430
EXPECT_EQ (result2, 2 );
386
431
}
387
432
388
- TEST (FlutterWindowsEngine , ScheduleFrame) {
433
+ TEST_F (FlutterWindowsEngineTest , ScheduleFrame) {
389
434
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
390
435
EngineModifier modifier (engine.get ());
391
436
@@ -400,7 +445,7 @@ TEST(FlutterWindowsEngine, ScheduleFrame) {
400
445
EXPECT_TRUE (called);
401
446
}
402
447
403
- TEST (FlutterWindowsEngine , SetNextFrameCallback) {
448
+ TEST_F (FlutterWindowsEngineTest , SetNextFrameCallback) {
404
449
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
405
450
EngineModifier modifier (engine.get ());
406
451
@@ -415,14 +460,14 @@ TEST(FlutterWindowsEngine, SetNextFrameCallback) {
415
460
EXPECT_TRUE (called);
416
461
}
417
462
418
- TEST (FlutterWindowsEngine , GetExecutableName) {
463
+ TEST_F (FlutterWindowsEngineTest , GetExecutableName) {
419
464
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
420
465
EXPECT_EQ (engine->GetExecutableName (), " flutter_windows_unittests.exe" );
421
466
}
422
467
423
468
// Ensure that after setting or resetting the high contrast feature,
424
469
// the corresponding status flag can be retrieved from the engine.
425
- TEST (FlutterWindowsEngine , UpdateHighContrastFeature) {
470
+ TEST_F (FlutterWindowsEngineTest , UpdateHighContrastFeature) {
426
471
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
427
472
EngineModifier modifier (engine.get ());
428
473
@@ -447,7 +492,7 @@ TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
447
492
EXPECT_FALSE (engine->high_contrast_enabled ());
448
493
}
449
494
450
- TEST (FlutterWindowsEngine , PostRasterThreadTask) {
495
+ TEST_F (FlutterWindowsEngineTest , PostRasterThreadTask) {
451
496
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
452
497
EngineModifier modifier (engine.get ());
453
498
0 commit comments