5#import <Flutter/Flutter.h>
6#import <XCTest/XCTest.h>
14- (instancetype)initForLifecycle:(NSString*)expectedLifecycle forStep:(NSString*)step;
22- (instancetype)initForLifecycle:(NSString*)expectedLifecycle forStep:(NSString*)step {
26 self = [
super initWithDescription:[NSString stringWithFormat:@"Expected state %@ during step %@",
27 expectedLifecycle, step]];
41 self.continueAfterFailure = NO;
45 NSMutableArray* expectations =
47 initForLifecycle:@"AppLifecycleState.inactive"
48 forStep:@"showing a FlutterViewController"]];
54 if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
56 initForLifecycle:@"AppLifecycleState.resumed"
57 forStep:@"showing a FlutterViewController"]];
60 initForLifecycle:@"AppLifecycleState.resumed"
61 forStep:@"showing a FlutterViewController"]];
66 XCTestExpectation* engineStartedExpectation = [
self expectationWithDescription:@"Engine started"];
70 [engineStartedExpectation fulfill];
72 [
self waitForExpectationsWithTimeout:5 handler:nil];
74 UIApplication* application = UIApplication.sharedApplication;
75 application.delegate.window.rootViewController = rootVC;
78 NSMutableArray* lifecycleExpectations = [NSMutableArray arrayWithCapacity:10];
83 [engine.lifecycleChannel setMessageHandler:^(id message, FlutterReply callback) {
84 if (lifecycleExpectations.count == 0) {
85 XCTFail(@"Unexpected lifecycle transition: %@", message);
88 XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex:0];
89 if (![[nextExpectation expectedLifecycle] isEqualToString:message]) {
90 XCTFail(@"Expected lifecycle %@ but instead received %@", [nextExpectation expectedLifecycle],
95 [nextExpectation fulfill];
96 [lifecycleExpectations removeObjectAtIndex:0];
104 XCTestExpectation* vcShown = [
self expectationWithDescription:@"present"];
108 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
110 [
self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
113 [lifecycleExpectations addObjectsFromArray:@[
115 initForLifecycle:@"AppLifecycleState.inactive"
116 forStep:@"dismissing a FlutterViewController"],
118 initForLifecycle:@"AppLifecycleState.paused"
119 forStep:@"dismissing a FlutterViewController"]
121 XCTestExpectation* vcDismissed = [
self expectationWithDescription:@"dismiss"];
122 [flutterVC dismissViewControllerAnimated:NO
124 [vcDismissed fulfill];
126 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
127 [
self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
136 [[NSNotificationCenter defaultCenter]
137 postNotificationName:UIApplicationWillResignActiveNotification
139 [[NSNotificationCenter defaultCenter]
140 postNotificationName:UIApplicationDidEnterBackgroundNotification
142 [[NSNotificationCenter defaultCenter]
143 postNotificationName:UIApplicationWillEnterForegroundNotification
145 [[NSNotificationCenter defaultCenter]
146 postNotificationName:UIApplicationDidBecomeActiveNotification
158 [lifecycleExpectations addObjectsFromArray:@[
160 initForLifecycle:@"AppLifecycleState.inactive"
161 forStep:@"showing a FlutterViewController a second time after backgrounding"],
163 initForLifecycle:@"AppLifecycleState.resumed"
164 forStep:@"showing a FlutterViewController a second time after backgrounding"]
168 XCTestExpectation* vcShown = [
self expectationWithDescription:@"present"];
172 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
173 NSLog(
@"FlutterViewController instance %@ created", flutterVC);
174 [
self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
177 [lifecycleExpectations addObjectsFromArray:@[
179 forStep:@"popping the FlutterViewController"],
181 initForLifecycle:@"AppLifecycleState.paused"
182 forStep:@"popping the FlutterViewController"]
184 XCTestExpectation* vcDismissed = [
self expectationWithDescription:@"dismiss"];
185 [flutterVC dismissViewControllerAnimated:NO
187 [vcDismissed fulfill];
189 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
195 [engine.lifecycleChannel setMessageHandler:nil];
196 [rootVC dismissViewControllerAnimated:NO completion:nil];
201 XCTestExpectation* engineStartedExpectation = [
self expectationWithDescription:@"Engine started"];
206 [engineStartedExpectation fulfill];
209 [
self waitForExpectationsWithTimeout:5 handler:nil];
211 UIApplication* application = UIApplication.sharedApplication;
212 application.delegate.window.rootViewController = rootVC;
215 NSMutableArray* lifecycleExpectations = [NSMutableArray arrayWithCapacity:10];
220 [engine.lifecycleChannel setMessageHandler:^(id message, FlutterReply callback) {
221 if (lifecycleExpectations.count == 0) {
222 XCTFail(@"Unexpected lifecycle transition: %@", message);
225 XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex:0];
226 if (![[nextExpectation expectedLifecycle] isEqualToString:message]) {
227 XCTFail(@"Expected lifecycle %@ but instead received %@", [nextExpectation expectedLifecycle],
232 [nextExpectation fulfill];
233 [lifecycleExpectations removeObjectAtIndex:0];
240 XCTestExpectation* vcShown = [
self expectationWithDescription:@"present"];
244 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
245 [
self waitForExpectations:lifecycleExpectations timeout:5];
248 [lifecycleExpectations addObjectsFromArray:@[
250 forStep:@"detaching a FlutterViewController"],
252 forStep:@"detaching a FlutterViewController"],
254 initForLifecycle:@"AppLifecycleState.detached"
255 forStep:@"detaching a FlutterViewController"]
257 [flutterVC dismissViewControllerAnimated:NO completion:nil];
260 [
self waitForExpectations:lifecycleExpectations timeout:5];
264 [engine.lifecycleChannel setMessageHandler:nil];
265 [rootVC dismissViewControllerAnimated:NO completion:nil];
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
void skip_testFlutterViewControllerDetachingSendsApplicationLifecycle()
NSArray * initialPresentLifecycles()
void skip_testDismissedFlutterViewControllerNotRespondingToApplicationLifecycle()
void setViewController:(FlutterViewController *viewController)
FlutterViewController * showFlutter:(dispatch_block_t showCompletion)
NSString * expectedLifecycle