@@ -38,17 +38,18 @@ @implementation AppLifecycleTests
38
38
- (void )setUp {
39
39
[super setUp ];
40
40
self.continueAfterFailure = NO ;
41
+ // Since this test checks for view controller and application lifecycles, the starting point
42
+ // must be well defined.
43
+ XCTAssertEqual ([UIApplication sharedApplication ].applicationState , UIApplicationStateActive);
41
44
}
42
45
43
46
- (void )testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle {
44
47
XCTestExpectation* engineStartedExpectation = [self expectationWithDescription: @" Engine started" ];
45
-
46
48
// Let the engine finish booting (at the end of which the channels are properly set-up) before
47
49
// moving onto the next step of showing the next view controller.
48
50
ScreenBeforeFlutter* rootVC = [[ScreenBeforeFlutter alloc ] initWithEngineRunCompletion: ^void () {
49
51
[engineStartedExpectation fulfill ];
50
52
}];
51
-
52
53
[self waitForExpectationsWithTimeout: 5 handler: nil ];
53
54
54
55
UIApplication* application = UIApplication.sharedApplication ;
@@ -64,16 +65,16 @@ - (void)testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle {
64
65
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
65
66
forStep: @" showing a FlutterViewController" ]
66
67
]];
67
-
68
+
68
69
[engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
69
70
if (lifecycleExpectations.count == 0 ) {
70
71
XCTFail (@" Unexpected lifecycle transition: %@ " , message);
71
72
return ;
72
73
}
73
74
XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
74
75
if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
75
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
76
- [nextExpectation expectedLifecycle ], message);
76
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " , [nextExpectation expectedLifecycle ],
77
+ message);
77
78
return ;
78
79
}
79
80
@@ -91,8 +92,6 @@ - (void)testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle {
91
92
[vcShown fulfill ];
92
93
}];
93
94
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
94
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
95
-
96
95
// The expectations list isn't dequeued by the message handler yet.
97
96
[self waitForExpectations: lifecycleExpectations timeout: 5 enforceOrder: YES ];
98
97
@@ -208,16 +207,16 @@ - (void)testVisibleFlutterViewControllerRespondsToApplicationLifecycle {
208
207
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
209
208
forStep: @" showing a FlutterViewController" ]
210
209
]];
211
-
210
+
212
211
[engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
213
212
if (lifecycleExpectations.count == 0 ) {
214
213
XCTFail (@" Unexpected lifecycle transition: %@ " , message);
215
214
return ;
216
215
}
217
216
XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
218
217
if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
219
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
220
- [nextExpectation expectedLifecycle ], message);
218
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " , [nextExpectation expectedLifecycle ],
219
+ message);
221
220
return ;
222
221
}
223
222
@@ -232,8 +231,6 @@ - (void)testVisibleFlutterViewControllerRespondsToApplicationLifecycle {
232
231
[vcShown fulfill ];
233
232
}];
234
233
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
235
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
236
-
237
234
[self waitForExpectations: lifecycleExpectations timeout: 5 ];
238
235
239
236
// Now put the FlutterViewController into background.
@@ -318,23 +315,23 @@ - (void)testFlutterViewControllerDetachingSendsApplicationLifecycle {
318
315
[[XCAppLifecycleTestExpectation alloc ] initForLifecycle: @" AppLifecycleState.resumed"
319
316
forStep: @" showing a FlutterViewController" ]
320
317
]];
321
-
318
+
322
319
[engine.lifecycleChannel setMessageHandler: ^(id message, FlutterReply callback) {
323
320
if (lifecycleExpectations.count == 0 ) {
324
321
XCTFail (@" Unexpected lifecycle transition: %@ " , message);
325
322
return ;
326
323
}
327
324
XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex: 0 ];
328
325
if (![[nextExpectation expectedLifecycle ] isEqualToString: message]) {
329
- XCTFail (@" Expected lifecycle %@ but instead received %@ " ,
330
- [nextExpectation expectedLifecycle ], message);
326
+ XCTFail (@" Expected lifecycle %@ but instead received %@ " , [nextExpectation expectedLifecycle ],
327
+ message);
331
328
return ;
332
329
}
333
330
334
331
[nextExpectation fulfill ];
335
332
[lifecycleExpectations removeObjectAtIndex: 0 ];
336
333
}];
337
-
334
+
338
335
// At the end of Flutter VC, we want to make sure it deallocs and sends detached signal.
339
336
// Using autoreleasepool will guarantee that.
340
337
FlutterViewController* flutterVC;
@@ -344,8 +341,6 @@ - (void)testFlutterViewControllerDetachingSendsApplicationLifecycle {
344
341
[vcShown fulfill ];
345
342
}];
346
343
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
347
- NSLog (@" FlutterViewController instance %@ created" , flutterVC);
348
-
349
344
[self waitForExpectations: lifecycleExpectations timeout: 5 ];
350
345
351
346
// Starts dealloc flutter VC.
0 commit comments