@@ -295,16 +295,70 @@ TEST_F(FlutterWindowsEngineTest, PlatformMessageRoundTrip) {
295
295
binary_messenger->Send (
296
296
channel, reinterpret_cast <uint8_t *>(payload), 5 ,
297
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 ' ));
298
+ EXPECT_EQ (reply_size, 5 );
299
+ EXPECT_EQ (reply[0 ], static_cast <uint8_t >(' h ' ));
300
300
did_call_reply = true ;
301
301
});
302
302
// Rely on timeout mechanism in CI.
303
- while (!did_call_callback && !did_call_reply && !did_call_dart_reply) {
303
+ while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
304
304
engine->task_runner ()->ProcessTasks ();
305
305
}
306
306
}
307
307
308
+ TEST_F (FlutterWindowsEngineTest, PlatformMessageRespondOnDifferentThread) {
309
+ FlutterDesktopEngineProperties properties = {};
310
+ properties.assets_path = GetContext ().GetAssetsPath ().c_str ();
311
+ properties.icu_data_path = GetContext ().GetIcuDataPath ().c_str ();
312
+ properties.dart_entrypoint = " hiPlatformChannels" ;
313
+
314
+ FlutterProjectBundle project (properties);
315
+ auto engine = std::make_unique<FlutterWindowsEngine>(project);
316
+
317
+ EngineModifier modifier (engine.get ());
318
+ modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
319
+
320
+ auto binary_messenger =
321
+ std::make_unique<BinaryMessengerImpl>(engine->messenger ());
322
+
323
+ engine->Run ();
324
+ bool did_call_callback = false ;
325
+ bool did_call_reply = false ;
326
+ bool did_call_dart_reply = false ;
327
+ std::string channel = " hi" ;
328
+ std::unique_ptr<std::thread> reply_thread;
329
+ binary_messenger->SetMessageHandler (
330
+ channel,
331
+ [&did_call_callback, &did_call_dart_reply, &reply_thread](
332
+ const uint8_t * message, size_t message_size, BinaryReply reply) {
333
+ if (message_size == 5 ) {
334
+ EXPECT_EQ (message[0 ], static_cast <uint8_t >(' h' ));
335
+ reply_thread.reset (new std::thread ([reply = std::move (reply)]() {
336
+ char response[] = {' b' , ' y' , ' e' };
337
+ reply (reinterpret_cast <uint8_t *>(response), 3 );
338
+ }));
339
+ did_call_callback = true ;
340
+ } else {
341
+ EXPECT_EQ (message_size, 3 );
342
+ EXPECT_EQ (message[0 ], static_cast <uint8_t >(' b' ));
343
+ did_call_dart_reply = true ;
344
+ }
345
+ });
346
+ char payload[] = {' h' , ' e' , ' l' , ' l' , ' o' };
347
+ binary_messenger->Send (
348
+ channel, reinterpret_cast <uint8_t *>(payload), 5 ,
349
+ [&did_call_reply](const uint8_t * reply, size_t reply_size) {
350
+ EXPECT_EQ (reply_size, 5 );
351
+ EXPECT_EQ (reply[0 ], static_cast <uint8_t >(' h' ));
352
+ did_call_reply = true ;
353
+ });
354
+ // Rely on timeout mechanism in CI.
355
+ while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
356
+ engine->task_runner ()->ProcessTasks ();
357
+ }
358
+ ASSERT_TRUE (reply_thread);
359
+ reply_thread->join ();
360
+ }
361
+
308
362
TEST_F (FlutterWindowsEngineTest, SendPlatformMessageWithResponse) {
309
363
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine ();
310
364
EngineModifier modifier (engine.get ());
0 commit comments