| 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 <XCTest/XCTest.h>
7
8 #include "flutter/common/constants.h"
9 #include "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
10 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSharedApplication.h"
11
12 FLUTTER_ASSERT_ARC
13
14 @interface FlutterSharedApplicationTest : XCTestCase
15 @end
16
17 @implementation FlutterSharedApplicationTest
18
19 - (void)testWhenNSExtensionInBundle {
20 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
21 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"]).andReturn(@{
22 @"NSExtensionPointIdentifier" : @"com.apple.share-services"
23 });
24 XCTAssertTrue(FlutterSharedApplication.isAppExtension);
25 XCTAssertFalse(FlutterSharedApplication.isAvailable);
26 [mockBundle stopMocking];
27 }
28
29 - (void)testWhenNSExtensionEmptyInBundle {
30 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
31 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"])
32 .andReturn([[NSDictionary alloc] init]);
33 XCTAssertTrue(FlutterSharedApplication.isAppExtension);
34 XCTAssertFalse(FlutterSharedApplication.isAvailable);
35 [mockBundle stopMocking];
36 }
37
38 - (void)testWhenNSExtensionNotInBundle {
39 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
40 XCTAssertFalse(FlutterSharedApplication.isAppExtension);
41 XCTAssertTrue(FlutterSharedApplication.isAvailable);
42 [mockBundle stopMocking];
43 }
44
45 - (void)testSharedApplicationNotCalledIfIsAvailableFalse {
46 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
47 OCMStub([mockBundle objectForInfoDictionaryKey:@"NSExtension"]).andReturn(@{
48 @"NSExtensionPointIdentifier" : @"com.apple.share-services"
49 });
50 id mockApplication = OCMClassMock([UIApplication class]);
51 XCTAssertFalse(FlutterSharedApplication.isAvailable);
52 OCMReject([mockApplication sharedApplication]);
53 XCTAssertNil(FlutterSharedApplication.application);
54 [mockBundle stopMocking];
55 }
56
57 - (void)testSharedApplicationCalledIfIsAvailableTrue {
58 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
59 id mockApplication = OCMClassMock([UIApplication class]);
60 XCTAssertTrue(FlutterSharedApplication.isAvailable);
61 XCTAssertNotNil(FlutterSharedApplication.application);
62 OCMVerify([mockApplication sharedApplication]);
63 [mockBundle stopMocking];
64 }
65
66 @end
FlutterMacros.h
FlutterSharedApplication.h
FlutterSharedApplication
Definition: FlutterSharedApplication.h:11
FlutterSharedApplication::application
UIApplication * application
Definition: FlutterSharedApplication.h:25
FlutterSharedApplication::isAppExtension
BOOL isAppExtension
Definition: FlutterSharedApplication.h:15
FlutterSharedApplication::isAvailable
BOOL isAvailable
Definition: FlutterSharedApplication.h:20
FlutterSharedApplicationTest
Definition: FlutterSharedApplicationTest.mm:15
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13