@@ -131,20 +131,23 @@ TEST_F(WindowsTest, LaunchHeadlessEngine) {
131
131
ASSERT_NE (engine, nullptr );
132
132
133
133
std::string view_ids;
134
- fml::AutoResetWaitableEvent latch ;
134
+ bool signaled = false ;
135
135
context.AddNativeFunction (
136
136
" SignalStringValue" , CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
137
137
auto handle = Dart_GetNativeArgument (args, 0 );
138
138
ASSERT_FALSE (Dart_IsError (handle));
139
139
view_ids = tonic::DartConverter<std::string>::FromDart (handle);
140
- latch. Signal () ;
140
+ signaled = true ;
141
141
}));
142
142
143
143
ViewControllerPtr controller{builder.Run ()};
144
144
ASSERT_NE (controller, nullptr );
145
145
146
+ while (!signaled) {
147
+ PumpMessage ();
148
+ }
149
+
146
150
// Verify a headless app has the implicit view.
147
- latch.Wait ();
148
151
EXPECT_EQ (view_ids, " View IDs: [0]" );
149
152
}
150
153
@@ -214,16 +217,18 @@ TEST_F(WindowsTest, VerifyNativeFunction) {
214
217
WindowsConfigBuilder builder (context);
215
218
builder.SetDartEntrypoint (" verifyNativeFunction" );
216
219
217
- fml::AutoResetWaitableEvent latch ;
220
+ bool signaled = false ;
218
221
auto native_entry =
219
- CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) { latch. Signal () ; });
222
+ CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) { signaled = true ; });
220
223
context.AddNativeFunction (" Signal" , native_entry);
221
224
222
225
ViewControllerPtr controller{builder.Run ()};
223
226
ASSERT_NE (controller, nullptr );
224
227
225
228
// Wait until signal has been called.
226
- latch.Wait ();
229
+ while (!signaled) {
230
+ PumpMessage ();
231
+ }
227
232
}
228
233
229
234
// Verify that native functions that pass parameters can be registered and
@@ -234,19 +239,21 @@ TEST_F(WindowsTest, VerifyNativeFunctionWithParameters) {
234
239
builder.SetDartEntrypoint (" verifyNativeFunctionWithParameters" );
235
240
236
241
bool bool_value = false ;
237
- fml::AutoResetWaitableEvent latch ;
242
+ bool signaled = false ;
238
243
auto native_entry = CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
239
244
auto handle = Dart_GetNativeBooleanArgument (args, 0 , &bool_value);
240
245
ASSERT_FALSE (Dart_IsError (handle));
241
- latch. Signal () ;
246
+ signaled = true ;
242
247
});
243
248
context.AddNativeFunction (" SignalBoolValue" , native_entry);
244
249
245
250
ViewControllerPtr controller{builder.Run ()};
246
251
ASSERT_NE (controller, nullptr );
247
252
248
253
// Wait until signalBoolValue has been called.
249
- latch.Wait ();
254
+ while (!signaled) {
255
+ PumpMessage ();
256
+ }
250
257
EXPECT_TRUE (bool_value);
251
258
}
252
259
@@ -257,20 +264,22 @@ TEST_F(WindowsTest, PlatformExecutable) {
257
264
builder.SetDartEntrypoint (" readPlatformExecutable" );
258
265
259
266
std::string executable_name;
260
- fml::AutoResetWaitableEvent latch ;
267
+ bool signaled = false ;
261
268
auto native_entry = CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
262
269
auto handle = Dart_GetNativeArgument (args, 0 );
263
270
ASSERT_FALSE (Dart_IsError (handle));
264
271
executable_name = tonic::DartConverter<std::string>::FromDart (handle);
265
- latch. Signal () ;
272
+ signaled = true ;
266
273
});
267
274
context.AddNativeFunction (" SignalStringValue" , native_entry);
268
275
269
276
ViewControllerPtr controller{builder.Run ()};
270
277
ASSERT_NE (controller, nullptr );
271
278
272
279
// Wait until signalStringValue has been called.
273
- latch.Wait ();
280
+ while (!signaled) {
281
+ PumpMessage ();
282
+ }
274
283
EXPECT_EQ (executable_name, " flutter_windows_unittests.exe" );
275
284
}
276
285
@@ -282,26 +291,28 @@ TEST_F(WindowsTest, VerifyNativeFunctionWithReturn) {
282
291
builder.SetDartEntrypoint (" verifyNativeFunctionWithReturn" );
283
292
284
293
bool bool_value_to_return = true ;
285
- fml::CountDownLatch latch ( 2 ) ;
294
+ int count = 2 ;
286
295
auto bool_return_entry = CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
287
296
Dart_SetBooleanReturnValue (args, bool_value_to_return);
288
- latch. CountDown () ;
297
+ --count ;
289
298
});
290
299
context.AddNativeFunction (" SignalBoolReturn" , bool_return_entry);
291
300
292
301
bool bool_value_passed = false ;
293
302
auto bool_pass_entry = CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
294
303
auto handle = Dart_GetNativeBooleanArgument (args, 0 , &bool_value_passed);
295
304
ASSERT_FALSE (Dart_IsError (handle));
296
- latch. CountDown () ;
305
+ --count ;
297
306
});
298
307
context.AddNativeFunction (" SignalBoolValue" , bool_pass_entry);
299
308
300
309
ViewControllerPtr controller{builder.Run ()};
301
310
ASSERT_NE (controller, nullptr );
302
311
303
312
// Wait until signalBoolReturn and signalBoolValue have been called.
304
- latch.Wait ();
313
+ while (count > 0 ) {
314
+ PumpMessage ();
315
+ }
305
316
EXPECT_TRUE (bool_value_passed);
306
317
}
307
318
@@ -614,10 +625,10 @@ TEST_F(WindowsTest, AddRemoveView) {
614
625
WindowsConfigBuilder builder (context);
615
626
builder.SetDartEntrypoint (" onMetricsChangedSignalViewIds" );
616
627
617
- fml::AutoResetWaitableEvent ready_latch ;
628
+ bool ready = false ;
618
629
context.AddNativeFunction (
619
- " Signal" , CREATE_NATIVE_ENTRY (
620
- [&](Dart_NativeArguments args) { ready_latch. Signal () ; }));
630
+ " Signal" ,
631
+ CREATE_NATIVE_ENTRY ( [&](Dart_NativeArguments args) { ready = true ; }));
621
632
622
633
context.AddNativeFunction (
623
634
" SignalStringValue" , CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
@@ -632,7 +643,9 @@ TEST_F(WindowsTest, AddRemoveView) {
632
643
ViewControllerPtr first_controller{builder.Run ()};
633
644
ASSERT_NE (first_controller, nullptr );
634
645
635
- ready_latch.Wait ();
646
+ while (!ready) {
647
+ PumpMessage ();
648
+ }
636
649
637
650
// Create a second view.
638
651
FlutterDesktopEngineRef engine =
@@ -670,7 +683,6 @@ TEST_F(WindowsTest, EngineId) {
670
683
WindowsConfigBuilder builder (context);
671
684
builder.SetDartEntrypoint (" testEngineId" );
672
685
673
- fml::AutoResetWaitableEvent latch;
674
686
std::optional<int64_t > engineId;
675
687
context.AddNativeFunction (
676
688
" NotifyEngineId" , CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
@@ -679,17 +691,15 @@ TEST_F(WindowsTest, EngineId) {
679
691
const auto handle = tonic::DartConverter<int64_t >::FromDart (argument);
680
692
engineId = handle;
681
693
}
682
- latch.Signal ();
683
694
}));
684
695
// Create the implicit view.
685
696
ViewControllerPtr first_controller{builder.Run ()};
686
697
ASSERT_NE (first_controller, nullptr );
687
698
688
- latch.Wait ();
689
- EXPECT_TRUE (engineId.has_value ());
690
- if (!engineId.has_value ()) {
691
- return ;
699
+ while (!engineId.has_value ()) {
700
+ PumpMessage ();
692
701
}
702
+
693
703
auto engine = FlutterDesktopViewControllerGetEngine (first_controller.get ());
694
704
EXPECT_EQ (engine, FlutterDesktopEngineForId (*engineId));
695
705
}
0 commit comments