65 {
66 XCTestExpectation* engineStartedExpectation = [self expectationWithDescription:@"Engine started"];
67
68
70 [engineStartedExpectation fulfill];
71 }];
72 [self waitForExpectationsWithTimeout:5 handler:nil];
73
74 UIApplication* application = UIApplication.sharedApplication;
75 application.delegate.window.rootViewController = rootVC;
77
78 NSMutableArray* lifecycleExpectations = [NSMutableArray arrayWithCapacity:10];
79
80
81 [lifecycleExpectations addObjectsFromArray:[self initialPresentLifecycles]];
82
83 [engine.lifecycleChannel setMessageHandler:^(id message, FlutterReply callback) {
84 if (lifecycleExpectations.count == 0) {
85 XCTFail(@"Unexpected lifecycle transition: %@", message);
86 return;
87 }
88 XCAppLifecycleTestExpectation* nextExpectation = [lifecycleExpectations objectAtIndex:0];
89 if (![[nextExpectation expectedLifecycle] isEqualToString:message]) {
90 XCTFail(@"Expected lifecycle %@ but instead received %@", [nextExpectation expectedLifecycle],
91 message);
92 return;
93 }
94
95 [nextExpectation fulfill];
96 [lifecycleExpectations removeObjectAtIndex:0];
97 }];
98
100 @autoreleasepool {
101
102
103
104 XCTestExpectation* vcShown = [self expectationWithDescription:@"present"];
106 [vcShown fulfill];
107 }];
108 [self waitForExpectationsWithTimeout:5.0 handler:nil];
109
110 [self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
111
112
113 [lifecycleExpectations addObjectsFromArray:@[
115 initForLifecycle:@"AppLifecycleState.inactive"
116 forStep:@"dismissing a FlutterViewController"],
118 initForLifecycle:@"AppLifecycleState.paused"
119 forStep:@"dismissing a FlutterViewController"]
120 ]];
121 XCTestExpectation* vcDismissed = [self expectationWithDescription:@"dismiss"];
122 [flutterVC dismissViewControllerAnimated:NO
123 completion:^{
124 [vcDismissed fulfill];
125 }];
126 [self waitForExpectationsWithTimeout:5.0 handler:nil];
127 [self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
128
129
130
131
132
133
134
135
136 [[NSNotificationCenter defaultCenter]
137 postNotificationName:UIApplicationWillResignActiveNotification
138 object:nil];
139 [[NSNotificationCenter defaultCenter]
140 postNotificationName:UIApplicationDidEnterBackgroundNotification
141 object:nil];
142 [[NSNotificationCenter defaultCenter]
143 postNotificationName:UIApplicationWillEnterForegroundNotification
144 object:nil];
145 [[NSNotificationCenter defaultCenter]
146 postNotificationName:UIApplicationDidBecomeActiveNotification
147 object:nil];
148
149 flutterVC = nil;
151 }
152
153
154
155
156
157
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"]
165 ]];
166
167 @autoreleasepool {
168 XCTestExpectation* vcShown = [self expectationWithDescription:@"present"];
170 [vcShown fulfill];
171 }];
172 [self waitForExpectationsWithTimeout:5.0 handler:nil];
173 NSLog(@"FlutterViewController instance %@ created", flutterVC);
174 [self waitForExpectations:lifecycleExpectations timeout:5 enforceOrder:YES];
175
176
177 [lifecycleExpectations addObjectsFromArray:@[
179 forStep:@"popping the FlutterViewController"],
181 initForLifecycle:@"AppLifecycleState.paused"
182 forStep:@"popping the FlutterViewController"]
183 ]];
184 XCTestExpectation* vcDismissed = [self expectationWithDescription:@"dismiss"];
185 [flutterVC dismissViewControllerAnimated:NO
186 completion:^{
187 [vcDismissed fulfill];
188 }];
189 [self waitForExpectationsWithTimeout:5.0 handler:nil];
190 flutterVC = nil;
192 }
193
194
195 [engine.lifecycleChannel setMessageHandler:nil];
196 [rootVC dismissViewControllerAnimated:NO completion:nil];
198}
void setViewController:(FlutterViewController *viewController)
FlutterViewController * showFlutter:(dispatch_block_t showCompletion)