| Flutter iOS Embedder |

UIViewController_FlutterScreenAndSceneIfLoadedTest.mm
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 <XCTest/XCTest.h>
6
7 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8 #import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
9
10 FLUTTER_ASSERT_ARC
11
12 @interface UIViewController_FlutterViewAndSceneIfLoadedTest : XCTestCase
13 @end
14
15 @implementation UIViewController_FlutterViewAndSceneIfLoadedTest
16
17 - (void)testWindowSceneIfViewLoadedReturnsWindowSceneIfViewLoaded {
18 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
19
20 NSSet<UIScene*>* scenes = UIApplication.sharedApplication.connectedScenes;
21 XCTAssertEqual(scenes.count, 1UL, @"There must only be 1 scene for test");
22 UIScene* scene = scenes.anyObject;
23 XCTAssert([scene isKindOfClass:[UIWindowScene class]], @"Must be a window scene for test");
24 UIWindowScene* windowScene = (UIWindowScene*)scene;
25 XCTAssert(windowScene.windows.count > 0, @"There must be at least 1 window for test");
26 UIWindow* window = windowScene.windows[0];
27 [window addSubview:viewController.view];
28
29 [viewController loadView];
30 XCTAssertEqual(viewController.flutterWindowSceneIfViewLoaded, windowScene,
31 @"Must return the correct window scene when view loaded");
32 }
33
34 - (void)testWindowSceneIfViewLoadedReturnsNilIfViewNotLoaded {
35 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
36 XCTAssertNil(viewController.flutterWindowSceneIfViewLoaded,
37 @"Must return nil window scene when view not loaded");
38 }
39
40 - (void)testScreenIfViewLoadedReturnsScreenIfViewLoadedAfterIOS13 {
41 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
42
43 NSSet<UIScene*>* scenes = UIApplication.sharedApplication.connectedScenes;
44 XCTAssertEqual(scenes.count, 1UL, @"There must only be 1 scene for test");
45 UIScene* scene = scenes.anyObject;
46 XCTAssert([scene isKindOfClass:[UIWindowScene class]], @"Must be a window scene for test");
47 UIWindowScene* windowScene = (UIWindowScene*)scene;
48 XCTAssert(windowScene.windows.count > 0, @"There must be at least 1 window for test");
49 UIWindow* window = windowScene.windows[0];
50 [window addSubview:viewController.view];
51
52 [viewController loadView];
53 XCTAssertEqual(viewController.flutterScreenIfViewLoaded, windowScene.screen,
54 @"Must return the correct screen when view loaded");
55 }
56
57 - (void)testScreenIfViewLoadedReturnsNilIfViewNotLoadedAfterIOS13 {
58 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
59 XCTAssertNil(viewController.flutterScreenIfViewLoaded,
60 @"Must return nil screen when view not loaded");
61 }
62
63 @end
FlutterMacros.h
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:139
UIViewController+FlutterScreenAndSceneIfLoaded.h
UIViewController_FlutterViewAndSceneIfLoadedTest
Definition: UIViewController_FlutterScreenAndSceneIfLoadedTest.mm:13
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13