Flutter Engine
FlutterViewControllerTest.m
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import <Flutter/Flutter.h>
6 #import <XCTest/XCTest.h>
7 
8 #import "AppDelegate.h"
9 
11 
12 @interface FlutterViewControllerTest : XCTestCase
13 @property(nonatomic, strong) FlutterViewController* flutterViewController;
14 @end
15 
16 @implementation FlutterViewControllerTest
17 
18 - (void)setUp {
19  [super setUp];
20  self.continueAfterFailure = NO;
21 }
22 
23 - (void)tearDown {
24  if (self.flutterViewController) {
25  XCTestExpectation* vcDismissed = [self expectationWithDescription:@"dismiss"];
26  [self.flutterViewController dismissViewControllerAnimated:NO
27  completion:^{
28  [vcDismissed fulfill];
29  }];
30  [self waitForExpectationsWithTimeout:10.0 handler:nil];
31  }
32  [super tearDown];
33 }
34 
35 - (void)testFirstFrameCallback {
36  XCTestExpectation* firstFrameRendered = [self expectationWithDescription:@"firstFrameRendered"];
37 
38  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
39  [engine runWithEntrypoint:nil];
40  self.flutterViewController = [[FlutterViewController alloc] initWithEngine:engine
41  nibName:nil
42  bundle:nil];
43 
44  XCTAssertFalse(self.flutterViewController.isDisplayingFlutterUI);
45 
46  XCTestExpectation* displayingFlutterUIExpectation =
47  [self keyValueObservingExpectationForObject:self.flutterViewController
48  keyPath:@"displayingFlutterUI"
49  expectedValue:@YES];
50  displayingFlutterUIExpectation.assertForOverFulfill = YES;
51 
52  [self.flutterViewController setFlutterViewDidRenderCallback:^{
53  [firstFrameRendered fulfill];
54  }];
55 
56  AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
57  UIViewController* rootVC = appDelegate.window.rootViewController;
58  [rootVC presentViewController:self.flutterViewController animated:NO completion:nil];
59 
60  [self waitForExpectationsWithTimeout:30.0 handler:nil];
61 }
62 
63 @end
UIWindow * window
Definition: AppDelegate.h:9
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
FlutterViewController * flutterViewController
#define FLUTTER_ASSERT_ARC
Definition: FlutterMacros.h:44