22
22
#import " FIRMessaging.h"
23
23
#import " FIRMessagingExtensionHelper.h"
24
24
25
+ API_AVAILABLE (ios(10.0 ))
25
26
typedef void (^FIRMessagingContentHandler)(UNNotificationContent *content);
26
27
28
+ #if TARGET_OS_IOS
27
29
static NSString *const kFCMPayloadOptionsName = @" fcm_options" ;
28
30
static NSString *const kFCMPayloadOptionsImageURLName = @" image" ;
29
31
static NSString *const kValidImageURL =
30
32
@" https://firebasestorage.googleapis.com/v0/b/fcm-ios-f7f9c.appspot.com/o/"
31
33
@" chubbyBunny.jpg?alt=media&token=d6c56a57-c007-4b27-b20f-f267cc83e9e5" ;
34
+ #endif
32
35
33
36
@interface FIRMessagingExtensionHelper (ExposedForTest)
34
37
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@@ -46,67 +49,72 @@ @implementation FIRMessagingExtensionHelperTest
46
49
47
50
- (void )setUp {
48
51
[super setUp ];
49
- FIRMessagingExtensionHelper *extensionHelper = [FIRMessaging extensionHelper ];
50
- _mockExtensionHelper = OCMPartialMock (extensionHelper);
52
+ if (@available (iOS 10.0 , *)) {
53
+ FIRMessagingExtensionHelper *extensionHelper = [FIRMessaging extensionHelper ];
54
+ _mockExtensionHelper = OCMPartialMock (extensionHelper);
55
+ } else {
56
+ // Fallback on earlier versions
57
+ }
51
58
}
52
59
53
60
- (void )tearDown {
54
61
[_mockExtensionHelper stopMocking ];
55
62
}
56
63
57
- #if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
64
+ #if TARGET_OS_IOS
58
65
#ifdef COCOAPODS
59
66
// This test requires internet access.
60
67
- (void )testModifyNotificationWithValidPayloadData {
61
- XCTestExpectation *validPayloadExpectation =
62
- [ self expectationWithDescription: @" Test payload is valid. " ];
63
-
64
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
65
- content.userInfo = @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : kValidImageURL }};
66
- FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
67
- [validPayloadExpectation fulfill ];
68
- };
69
- [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
70
-
71
- OCMVerify ([_mockExtensionHelper loadAttachmentForURL : [OCMArg any ]
72
- completionHandler: [OCMArg any ]]) ;
73
- [ self waitForExpectationsWithTimeout: 1.0 handler: nil ];
68
+ if (@ available (iOS 10.0 , *)) {
69
+ XCTestExpectation *validPayloadExpectation =
70
+ [ self expectationWithDescription: @" Test payload is valid. " ];
71
+ UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
72
+ content.userInfo = @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : kValidImageURL }};
73
+ FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
74
+ [validPayloadExpectation fulfill ];
75
+ };
76
+ [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
77
+ OCMVerify ([_mockExtensionHelper loadAttachmentForURL: [OCMArg any ]
78
+ completionHandler : [OCMArg any ]]);
79
+ [ self waitForExpectationsWithTimeout: 1.0 handler: nil ] ;
80
+ }
74
81
}
75
82
#endif
76
83
77
84
- (void )testModifyNotificationWithInvalidPayloadData {
78
- XCTestExpectation *validPayloadExpectation =
79
- [self expectationWithDescription: @" Test payload is valid." ];
80
-
81
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
82
- content.userInfo =
83
- @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : @" a invalid URL" }};
84
- FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
85
- [validPayloadExpectation fulfill ];
86
- };
87
- [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
88
-
89
- OCMReject ([_mockExtensionHelper loadAttachmentForURL: [OCMArg any ]
90
- completionHandler: [OCMArg any ]]);
91
- [self waitForExpectationsWithTimeout: 1.0 handler: nil ];
85
+ if (@available (iOS 10.0 , *)) {
86
+ XCTestExpectation *validPayloadExpectation =
87
+ [self expectationWithDescription: @" Test payload is valid." ];
88
+ UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
89
+ content.userInfo =
90
+ @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : @" a invalid URL" }};
91
+ FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
92
+ [validPayloadExpectation fulfill ];
93
+ };
94
+ [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
95
+
96
+ OCMReject ([_mockExtensionHelper loadAttachmentForURL: [OCMArg any ]
97
+ completionHandler: [OCMArg any ]]);
98
+ [self waitForExpectationsWithTimeout: 1.0 handler: nil ];
99
+ }
92
100
}
93
101
94
102
- (void )testModifyNotificationWithEmptyPayloadData {
95
- XCTestExpectation *validPayloadExpectation =
96
- [ self expectationWithDescription: @" Test payload is valid. " ];
97
-
98
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
99
- content.userInfo =
100
- @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : @" a invalid URL" }};
101
- FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
102
- [validPayloadExpectation fulfill ];
103
- };
104
- [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
105
-
106
- OCMReject ([_mockExtensionHelper loadAttachmentForURL : [OCMArg any ]
107
- completionHandler: [OCMArg any ]]) ;
108
- [ self waitForExpectationsWithTimeout: 1.0 handler: nil ];
103
+ if (@ available (iOS 10.0 , *)) {
104
+ XCTestExpectation *validPayloadExpectation =
105
+ [ self expectationWithDescription: @" Test payload is valid. " ];
106
+ UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc ] init ];
107
+ content.userInfo =
108
+ @{kFCMPayloadOptionsName : @{kFCMPayloadOptionsImageURLName : @" a invalid URL" }};
109
+ FIRMessagingContentHandler handler = ^(UNNotificationContent *content) {
110
+ [validPayloadExpectation fulfill ];
111
+ };
112
+ [_mockExtensionHelper populateNotificationContent: content withContentHandler: handler];
113
+ OCMReject ([_mockExtensionHelper loadAttachmentForURL: [OCMArg any ]
114
+ completionHandler : [OCMArg any ]]);
115
+ [ self waitForExpectationsWithTimeout: 1.0 handler: nil ] ;
116
+ }
109
117
}
110
- #endif
118
+ #endif // TARGET_OS_IOS
111
119
112
120
@end
0 commit comments