@@ -64,29 +64,34 @@ - (void)testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle {
64
64
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
65
65
forStep: @" showing a FlutterViewController" ]
66
66
]];
67
+
68
+ [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
69
+ if (lifecycleExpectations.count == 0 ) {
70
+ XCTFail (@" Unexpected lifecycle transition: %@ " , message);
71
+ return ;
72
+ }
73
+ XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
74
+ if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
75
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
76
+ [nextExpectation expectedLifecycle ], message);
77
+ return ;
78
+ }
79
+
80
+ [nextExpectation fulfill ];
81
+ [lifecycleExpectations removeObjectAtIndex: 0 ];
82
+ }];
67
83
68
84
FlutterViewController* flutterVC;
69
85
@autoreleasepool {
70
86
// Holding onto this FlutterViewController is consequential here. Since a released
71
87
// FlutterViewController wouldn't keep listening to the application lifecycle events and produce
72
88
// false positives for the application lifecycle tests further below.
73
- flutterVC = [rootVC showFlutter ];
74
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
75
- [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
76
- if (lifecycleExpectations.count == 0 ) {
77
- XCTFail (@" Unexpected lifecycle transition: %@ " , message);
78
- return ;
79
- }
80
- XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
81
- if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
82
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
83
- [nextExpectation expectedLifecycle ], message);
84
- return ;
85
- }
86
-
87
- [nextExpectation fulfill ];
88
- [lifecycleExpectations removeObjectAtIndex: 0 ];
89
+ XCTestExpectation* vcShown = [self expectationWithDescription: @" present" ];
90
+ flutterVC = [rootVC showFlutter: ^{
91
+ [vcShown fulfill ];
89
92
}];
93
+ [self waitForExpectationsWithTimeout: 5.0 handler: nil ];
94
+ NSLog (@" FlutterViewController instance %@ created" , flutterVC);
90
95
91
96
// The expectations list isn't dequeued by the message handler yet.
92
97
[self waitForExpectations: lifecycleExpectations timeout: 5 enforceOrder: YES ];
@@ -147,7 +152,11 @@ - (void)testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle {
147
152
]];
148
153
149
154
@autoreleasepool {
150
- flutterVC = [rootVC showFlutter ];
155
+ XCTestExpectation* vcShown = [self expectationWithDescription: @" present" ];
156
+ flutterVC = [rootVC showFlutter: ^{
157
+ [vcShown fulfill ];
158
+ }];
159
+ [self waitForExpectationsWithTimeout: 5.0 handler: nil ];
151
160
NSLog (@" FlutterViewController instance %@ created" , flutterVC);
152
161
[self waitForExpectations: lifecycleExpectations timeout: 5 enforceOrder: YES ];
153
162
@@ -199,26 +208,31 @@ - (void)testVisibleFlutterViewControllerRespondsToApplicationLifecycle {
199
208
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
200
209
forStep: @" showing a FlutterViewController" ]
201
210
]];
211
+
212
+ [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
213
+ if (lifecycleExpectations.count == 0 ) {
214
+ XCTFail (@" Unexpected lifecycle transition: %@ " , message);
215
+ return ;
216
+ }
217
+ XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
218
+ if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
219
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
220
+ [nextExpectation expectedLifecycle ], message);
221
+ return ;
222
+ }
223
+
224
+ [nextExpectation fulfill ];
225
+ [lifecycleExpectations removeObjectAtIndex: 0 ];
226
+ }];
202
227
203
228
FlutterViewController* flutterVC;
204
229
@autoreleasepool {
205
- flutterVC = [rootVC showFlutter ];
206
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
207
- [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
208
- if (lifecycleExpectations.count == 0 ) {
209
- XCTFail (@" Unexpected lifecycle transition: %@ " , message);
210
- return ;
211
- }
212
- XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
213
- if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
214
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
215
- [nextExpectation expectedLifecycle ], message);
216
- return ;
217
- }
218
-
219
- [nextExpectation fulfill ];
220
- [lifecycleExpectations removeObjectAtIndex: 0 ];
230
+ XCTestExpectation* vcShown = [self expectationWithDescription: @" present" ];
231
+ flutterVC = [rootVC showFlutter: ^{
232
+ [vcShown fulfill ];
221
233
}];
234
+ [self waitForExpectationsWithTimeout: 5.0 handler: nil ];
235
+ NSLog (@" FlutterViewController instance %@ created" , flutterVC);
222
236
223
237
[self waitForExpectations: lifecycleExpectations timeout: 5 ];
224
238
@@ -304,27 +318,33 @@ - (void)testFlutterViewControllerDetachingSendsApplicationLifecycle {
304
318
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
305
319
forStep: @" showing a FlutterViewController" ]
306
320
]];
321
+
322
+ [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
323
+ if (lifecycleExpectations.count == 0 ) {
324
+ XCTFail (@" Unexpected lifecycle transition: %@ " , message);
325
+ return ;
326
+ }
327
+ XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
328
+ if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
329
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
330
+ [nextExpectation expectedLifecycle ], message);
331
+ return ;
332
+ }
333
+
334
+ [nextExpectation fulfill ];
335
+ [lifecycleExpectations removeObjectAtIndex: 0 ];
336
+ }];
337
+
307
338
// At the end of Flutter VC, we want to make sure it deallocs and sends detached signal.
308
339
// Using autoreleasepool will guarantee that.
309
340
FlutterViewController* flutterVC;
310
341
@autoreleasepool {
311
- flutterVC = [rootVC showFlutter ];
312
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
313
- [engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
314
- if (lifecycleExpectations.count == 0 ) {
315
- XCTFail (@" Unexpected lifecycle transition: %@ " , message);
316
- return ;
317
- }
318
- XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
319
- if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
320
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
321
- [nextExpectation expectedLifecycle ], message);
322
- return ;
323
- }
324
-
325
- [nextExpectation fulfill ];
326
- [lifecycleExpectations removeObjectAtIndex: 0 ];
342
+ XCTestExpectation* vcShown = [self expectationWithDescription: @" present" ];
343
+ flutterVC = [rootVC showFlutter: ^{
344
+ [vcShown fulfill ];
327
345
}];
346
+ [self waitForExpectationsWithTimeout: 5.0 handler: nil ];
347
+ NSLog (@" FlutterViewController instance %@ created" , flutterVC);
328
348
329
349
[self waitForExpectations: lifecycleExpectations timeout: 5 ];
330
350
0 commit comments