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,56 @@ 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
+ bool did_call_dart_reply = false ;
278
+ std::string channel = " hi" ;
279
+ binary_messenger->SetMessageHandler (
280
+ channel,
281
+ [&did_call_callback, &did_call_dart_reply](
282
+ const uint8_t * message, size_t message_size, BinaryReply reply) {
283
+ if (message_size == 5 ) {
284
+ EXPECT_EQ (message[0 ], static_cast <uint8_t >(' h' ));
285
+ char response[] = {' b' , ' y' , ' e' };
286
+ reply (reinterpret_cast <uint8_t *>(response), 3 );
287
+ did_call_callback = true ;
288
+ } else {
289
+ EXPECT_EQ (message_size, 3 );
290
+ EXPECT_EQ (message[0 ], static_cast <uint8_t >(' b' ));
291
+ did_call_dart_reply = true ;
292
+ }
293
+ });
294
+ char payload[] = {' h' , ' e' , ' l' , ' l' , ' o' };
295
+ binary_messenger->Send (
296
+ channel, reinterpret_cast <uint8_t *>(payload), 5 ,
297
+ [&did_call_reply](const uint8_t * reply, size_t reply_size) {
298
+ EXPECT_EQ (reply_size, 3 );
299
+ EXPECT_EQ (reply[0 ], static_cast <uint8_t >(' b' ));
300
+ did_call_reply = true ;
301
+ });
302
+ // Rely on timeout mechanism in CI.
303
+ while (!did_call_callback && !did_call_reply && !did_call_dart_reply) {
304
+ engine->task_runner ()->ProcessTasks ();
305
+ }
306
+ }
307
+
308
+ TEST_F (FlutterWindowsEngineTest, SendPlatformMessageWithResponse) {
256
309
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
257
310
EngineModifier modifier (engine.get ());
258
311
@@ -310,7 +363,7 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
310
363
EXPECT_TRUE (send_message_called);
311
364
}
312
365
313
- TEST (FlutterWindowsEngine , DispatchSemanticsAction) {
366
+ TEST_F (FlutterWindowsEngineTest , DispatchSemanticsAction) {
314
367
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
315
368
EngineModifier modifier (engine.get ());
316
369
@@ -334,7 +387,7 @@ TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
334
387
EXPECT_TRUE (called);
335
388
}
336
389
337
- TEST (FlutterWindowsEngine , SetsThreadPriority) {
390
+ TEST_F (FlutterWindowsEngineTest , SetsThreadPriority) {
338
391
WindowsPlatformThreadPrioritySetter (FlutterThreadPriority::kBackground );
339
392
EXPECT_EQ (GetThreadPriority (GetCurrentThread ()),
340
393
THREAD_PRIORITY_BELOW_NORMAL);
@@ -355,7 +408,7 @@ TEST(FlutterWindowsEngine, SetsThreadPriority) {
355
408
EXPECT_EQ (GetThreadPriority (GetCurrentThread ()), THREAD_PRIORITY_NORMAL);
356
409
}
357
410
358
- TEST (FlutterWindowsEngine , AddPluginRegistrarDestructionCallback) {
411
+ TEST_F (FlutterWindowsEngineTest , AddPluginRegistrarDestructionCallback) {
359
412
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
360
413
EngineModifier modifier (engine.get ());
361
414
@@ -385,7 +438,7 @@ TEST(FlutterWindowsEngine, AddPluginRegistrarDestructionCallback) {
385
438
EXPECT_EQ (result2, 2 );
386
439
}
387
440
388
- TEST (FlutterWindowsEngine , ScheduleFrame) {
441
+ TEST_F (FlutterWindowsEngineTest , ScheduleFrame) {
389
442
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
390
443
EngineModifier modifier (engine.get ());
391
444
@@ -400,7 +453,7 @@ TEST(FlutterWindowsEngine, ScheduleFrame) {
400
453
EXPECT_TRUE (called);
401
454
}
402
455
403
- TEST (FlutterWindowsEngine , SetNextFrameCallback) {
456
+ TEST_F (FlutterWindowsEngineTest , SetNextFrameCallback) {
404
457
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
405
458
EngineModifier modifier (engine.get ());
406
459
@@ -415,14 +468,14 @@ TEST(FlutterWindowsEngine, SetNextFrameCallback) {
415
468
EXPECT_TRUE (called);
416
469
}
417
470
418
- TEST (FlutterWindowsEngine , GetExecutableName) {
471
+ TEST_F (FlutterWindowsEngineTest , GetExecutableName) {
419
472
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
420
473
EXPECT_EQ (engine->GetExecutableName (), " flutter_windows_unittests.exe" );
421
474
}
422
475
423
476
// Ensure that after setting or resetting the high contrast feature,
424
477
// the corresponding status flag can be retrieved from the engine.
425
- TEST (FlutterWindowsEngine , UpdateHighContrastFeature) {
478
+ TEST_F (FlutterWindowsEngineTest , UpdateHighContrastFeature) {
426
479
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
427
480
EngineModifier modifier (engine.get ());
428
481
@@ -447,7 +500,7 @@ TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
447
500
EXPECT_FALSE (engine->high_contrast_enabled ());
448
501
}
449
502
450
- TEST (FlutterWindowsEngine , PostRasterThreadTask) {
503
+ TEST_F (FlutterWindowsEngineTest , PostRasterThreadTask) {
451
504
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
452
505
EngineModifier modifier (engine.get ());
453
506
0 commit comments