| 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 if (@available(iOS 13.0, *)) {
19 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
20
21 NSSet<UIScene*>* scenes = UIApplication.sharedApplication.connectedScenes;
22 XCTAssertEqual(scenes.count, 1UL, @"There must only be 1 scene for test");
23 UIScene* scene = scenes.anyObject;
24 XCTAssert([scene isKindOfClass:[UIWindowScene class]], @"Must be a window scene for test");
25 UIWindowScene* windowScene = (UIWindowScene*)scene;
26 XCTAssert(windowScene.windows.count > 0, @"There must be at least 1 window for test");
27 UIWindow* window = windowScene.windows[0];
28 [window addSubview:viewController.view];
29
30 [viewController loadView];
31 XCTAssertEqual(viewController.flutterWindowSceneIfViewLoaded, windowScene,
32 @"Must return the correct window scene when view loaded");
33 }
34 }
35
36 - (void)testWindowSceneIfViewLoadedReturnsNilIfViewNotLoaded {
37 if (@available(iOS 13.0, *)) {
38 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
39 XCTAssertNil(viewController.flutterWindowSceneIfViewLoaded,
40 @"Must return nil window scene when view not loaded");
41 }
42 }
43
44 - (void)testScreenIfViewLoadedReturnsMainScreenBeforeIOS13 {
45 if (@available(iOS 13.0, *)) {
46 return;
47 }
48
49 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
50 XCTAssertEqual(viewController.flutterScreenIfViewLoaded, UIScreen.mainScreen,
51 @"Must return UIScreen.mainScreen before iOS 13");
52 }
53
54 - (void)testScreenIfViewLoadedReturnsScreenIfViewLoadedAfterIOS13 {
55 if (@available(iOS 13.0, *)) {
56 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
57
58 NSSet<UIScene*>* scenes = UIApplication.sharedApplication.connectedScenes;
59 XCTAssertEqual(scenes.count, 1UL, @"There must only be 1 scene for test");
60 UIScene* scene = scenes.anyObject;
61 XCTAssert([scene isKindOfClass:[UIWindowScene class]], @"Must be a window scene for test");
62 UIWindowScene* windowScene = (UIWindowScene*)scene;
63 XCTAssert(windowScene.windows.count > 0, @"There must be at least 1 window for test");
64 UIWindow* window = windowScene.windows[0];
65 [window addSubview:viewController.view];
66
67 [viewController loadView];
68 XCTAssertEqual(viewController.flutterScreenIfViewLoaded, windowScene.screen,
69 @"Must return the correct screen when view loaded");
70 }
71 }
72
73 - (void)testScreenIfViewLoadedReturnsNilIfViewNotLoadedAfterIOS13 {
74 if (@available(iOS 13.0, *)) {
75 UIViewController* viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
76 XCTAssertNil(viewController.flutterScreenIfViewLoaded,
77 @"Must return nil screen when view not loaded");
78 }
79 }
80
81 @end
UIViewController_FlutterViewAndSceneIfLoadedTest
Definition: UIViewController_FlutterScreenAndSceneIfLoadedTest.mm:12
FlutterMacros.h
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:92
UIViewController+FlutterScreenAndSceneIfLoaded.h
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13