| Flutter iOS Embedder |

FlutterSharedApplicationTest.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 <OCMock/OCMock.h>
6 #import <UIKit/UIKit.h>
7 #import <XCTest/XCTest.h>
8
9 #include "flutter/common/constants.h"
10 #include "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
11 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSharedApplication.h"
12
13 FLUTTER_ASSERT_ARC
14
15 @interface FlutterSharedApplicationTest : XCTestCase
16 @end
17
18 @implementation FlutterSharedApplicationTest
19
20 - (void)testWhenNSExtensionInBundle {
21 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
22 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"]).andReturn(@{
23 @"NSExtensionPointIdentifier" : @"com.apple.share-services"
24 });
25 XCTAssertTrue(FlutterSharedApplication.isAppExtension);
26 XCTAssertFalse(FlutterSharedApplication.isAvailable);
27 [mockBundle stopMocking];
28 }
29
30 - (void)testWhenNSExtensionEmptyInBundle {
31 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
32 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"])
33 .andReturn([[NSDictionary alloc] init]);
34 XCTAssertTrue(FlutterSharedApplication.isAppExtension);
35 XCTAssertFalse(FlutterSharedApplication.isAvailable);
36 [mockBundle stopMocking];
37 }
38
39 - (void)testWhenNSExtensionNotInBundle {
40 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
41 XCTAssertFalse(FlutterSharedApplication.isAppExtension);
42 XCTAssertTrue(FlutterSharedApplication.isAvailable);
43 [mockBundle stopMocking];
44 }
45
46 - (void)testSharedApplicationNotCalledIfIsAvailableFalse {
47 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
48 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"]).andReturn(@{
49 @"NSExtensionPointIdentifier" : @"com.apple.share-services"
50 });
51 id mockApplication = OCMClassMock([UIApplication class]);
52 XCTAssertFalse(FlutterSharedApplication.isAvailable);
53 OCMReject([mockApplication sharedApplication]);
54 XCTAssertNil(FlutterSharedApplication.application);
55 [mockBundle stopMocking];
56 }
57
58 - (void)testSharedApplicationCalledIfIsAvailableTrue {
59 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
60 id mockApplication = OCMClassMock([UIApplication class]);
61 XCTAssertTrue(FlutterSharedApplication.isAvailable);
62 XCTAssertNotNil(FlutterSharedApplication.application);
63 OCMVerify([mockApplication sharedApplication]);
64 [mockBundle stopMocking];
65 }
66
67 - (void)testHasSceneDelegate {
68 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
69 id mockApplication = OCMClassMock([UIApplication class]);
70 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
71 XCTAssertTrue(FlutterSharedApplication.isAvailable);
72 XCTAssertNotNil(FlutterSharedApplication.application);
73
74 id mockSceneWithDelegate = OCMClassMock([UIScene class]);
75 id mockSceneDelegate = OCMProtocolMock(@protocol(UISceneDelegate));
76 OCMStub([mockSceneWithDelegate delegate]).andReturn(mockSceneDelegate);
77 NSSet<UIScene*>* connectedScenes = [NSSet setWithObjects:mockSceneWithDelegate, nil];
78 OCMStub([mockApplication connectedScenes]).andReturn(connectedScenes);
79
80 XCTAssertTrue(FlutterSharedApplication.hasSceneDelegate);
81
82 [mockBundle stopMocking];
83 }
84
85 - (void)testHasNoSceneDelegate {
86 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
87 id mockApplication = OCMClassMock([UIApplication class]);
88 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
89 XCTAssertTrue(FlutterSharedApplication.isAvailable);
90 XCTAssertNotNil(FlutterSharedApplication.application);
91
92 id mockScene = OCMClassMock([UIScene class]);
93 NSSet<UIScene*>* connectedScenes = [NSSet setWithObjects:mockScene, nil];
94 OCMStub([mockApplication connectedScenes]).andReturn(connectedScenes);
95
96 XCTAssertFalse(FlutterSharedApplication.hasSceneDelegate);
97 [mockBundle stopMocking];
98 }
99
100 - (void)testFlutterDeeplinkingEnabledWhenNil {
101 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
102 OCMStub([mockBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]).andReturn(nil);
103
104 XCTAssertTrue(FlutterSharedApplication.isFlutterDeepLinkingEnabled);
105 [mockBundle stopMocking];
106 }
107
108 - (void)testFlutterDeeplinkingEnabledWhenYes {
109 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
110 OCMStub([mockBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]).andReturn(@YES);
111
112 XCTAssertTrue(FlutterSharedApplication.isFlutterDeepLinkingEnabled);
113 [mockBundle stopMocking];
114 }
115
116 - (void)testFlutterDeeplinkingEnabledWhenNo {
117 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
118 OCMStub([mockBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]).andReturn(@NO);
119
120 XCTAssertFalse(FlutterSharedApplication.isFlutterDeepLinkingEnabled);
121 [mockBundle stopMocking];
122 }
123
124 - (void)testFlutterDeeplinkingEnabledWhenBogus {
125 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
126 OCMStub([mockBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]).andReturn(@"hello");
127
128 XCTAssertFalse(FlutterSharedApplication.isFlutterDeepLinkingEnabled);
129 [mockBundle stopMocking];
130 }
131
132 @end
FlutterMacros.h
FlutterSharedApplication.h
FlutterSharedApplication
Definition: FlutterSharedApplication.h:13
FlutterSharedApplication::application
UIApplication * application
Definition: FlutterSharedApplication.h:27
FlutterSharedApplication::hasSceneDelegate
BOOL hasSceneDelegate
Definition: FlutterSharedApplication.h:32
FlutterSharedApplication::isAppExtension
BOOL isAppExtension
Definition: FlutterSharedApplication.h:17
FlutterSharedApplication::isAvailable
BOOL isAvailable
Definition: FlutterSharedApplication.h:22
+[FlutterSharedApplication isFlutterDeepLinkingEnabled]
BOOL isFlutterDeepLinkingEnabled()
Definition: FlutterSharedApplication.mm:60
FlutterSharedApplicationTest
Definition: FlutterSharedApplicationTest.mm:16
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13