-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FIRMessagingRemoteNotificationsProxy updated to use GULAppDelegateSwizzler #2683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
b2eabf2
4ab86de
1f1560a
f4a4638
9fcedce
27c8b5b
dee28d3
5821591
908b6ea
9e377d2
7861cde
b7703ac
ad1da54
2bdf353
8eafece
e5d2ce8
86ff257
79b7613
98ffccb
cd44395
3df4140
dcd0e10
18381dd
dae75d9
6dee8d3
2726e7c
63fd1f5
4a3fbb1
b390f4f
236877d
3641d35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
#import "FIRMessaging.h" | ||
#import "FIRMessagingRemoteNotificationsProxy.h" | ||
|
||
#import <GoogleUtilities/GULLogger.h> | ||
#import <GoogleUtilities/GULAppDelegateSwizzler.h> | ||
|
||
#pragma mark - Invalid App Delegate or UNNotificationCenter | ||
|
||
@interface RandomObject : NSObject | ||
|
@@ -62,6 +65,8 @@ @implementation IncompleteAppDelegate | |
@interface FakeAppDelegate : NSObject <UIApplicationDelegate> | ||
@property(nonatomic) BOOL remoteNotificationMethodWasCalled; | ||
@property(nonatomic) BOOL remoteNotificationWithFetchHandlerWasCalled; | ||
@property(nonatomic, strong) NSData *deviceToken; | ||
@property(nonatomic, strong) NSError *registerForRemoteNotificationsError; | ||
@end | ||
@implementation FakeAppDelegate | ||
#if TARGET_OS_IOS | ||
|
@@ -75,6 +80,17 @@ - (void)application:(UIApplication *)application | |
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { | ||
self.remoteNotificationWithFetchHandlerWasCalled = YES; | ||
} | ||
|
||
- (void)application:(UIApplication *)application | ||
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | ||
self.deviceToken = deviceToken; | ||
} | ||
|
||
- (void)application:(UIApplication *)application | ||
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { | ||
self.registerForRemoteNotificationsError = error; | ||
} | ||
|
||
@end | ||
|
||
#pragma mark - Incompete UNUserNotificationCenterDelegate | ||
|
@@ -107,6 +123,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
@end | ||
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 | ||
|
||
@interface GULAppDelegateSwizzler (FIRMessagingRemoteNotificationsProxyTest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider importing the private header. |
||
+ (void)resetProxyOriginalDelegateOnceToken; | ||
@end | ||
|
||
#pragma mark - Local, Per-Test Properties | ||
|
||
@interface FIRMessagingRemoteNotificationsProxyTest : XCTestCase | ||
|
@@ -123,6 +143,10 @@ @implementation FIRMessagingRemoteNotificationsProxyTest | |
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
GULLoggerForceDebug(); | ||
[GULAppDelegateSwizzler resetProxyOriginalDelegateOnceToken]; | ||
|
||
_mockSharedApplication = OCMPartialMock([UIApplication sharedApplication]); | ||
|
||
_mockMessaging = OCMClassMock([FIRMessaging class]); | ||
|
@@ -134,8 +158,7 @@ - (void)setUp { | |
OCMStub([_mockProxyClass sharedProxy]).andReturn(self.proxy); | ||
|
||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 | ||
_mockUserNotificationCenter = OCMClassMock([UNUserNotificationCenter class]); | ||
OCMStub([_mockUserNotificationCenter currentNotificationCenter]).andReturn(_mockUserNotificationCenter); | ||
_mockUserNotificationCenter = OCMPartialMock([UNUserNotificationCenter currentNotificationCenter]); | ||
#endif | ||
} | ||
|
||
|
@@ -149,6 +172,9 @@ - (void)tearDown { | |
[_mockSharedApplication stopMocking]; | ||
_mockSharedApplication = nil; | ||
|
||
[_mockUserNotificationCenter stopMocking]; | ||
_mockUserNotificationCenter = nil; | ||
|
||
_proxy = nil; | ||
[super tearDown]; | ||
} | ||
|
@@ -187,7 +213,7 @@ - (void)testIncompleteAppDelegateRemoteNotificationWithFetchHandlerMethod { | |
[self.proxy swizzleMethodsIfPossible]; | ||
|
||
SEL remoteNotificationWithFetchHandler = | ||
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:); | ||
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:); | ||
XCTAssertFalse([incompleteAppDelegate respondsToSelector:remoteNotificationWithFetchHandler]); | ||
SEL remoteNotification = @selector(application:didReceiveRemoteNotification:); | ||
XCTAssertTrue([incompleteAppDelegate respondsToSelector:remoteNotification]); | ||
|
@@ -219,14 +245,34 @@ - (void)testSwizzledAppDelegateRemoteNotificationMethods { | |
// Verify our swizzled method was called | ||
OCMExpect([self.mockMessaging appDidReceiveMessage:notification]); | ||
|
||
[appDelegate application:OCMClassMock([UIApplication class]) | ||
[appDelegate application:self.mockSharedApplication | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:^(UIBackgroundFetchResult result) {}]; | ||
|
||
// Verify our original method was called | ||
XCTAssertTrue(appDelegate.remoteNotificationWithFetchHandlerWasCalled); | ||
|
||
[self.mockMessaging verify]; | ||
|
||
// Verify application:didRegisterForRemoteNotificationsWithDeviceToken: | ||
NSData *deviceToken = [NSData data]; | ||
|
||
OCMExpect([self.mockMessaging setAPNSToken:deviceToken]); | ||
|
||
[appDelegate application:self.mockSharedApplication | ||
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; | ||
|
||
XCTAssertEqual(appDelegate.deviceToken, deviceToken); | ||
[self.mockMessaging verify]; | ||
|
||
// Verify application:didFailToRegisterForRemoteNotificationsWithError: | ||
NSError *error = [NSError errorWithDomain:@"tests" code:-1 userInfo:nil]; | ||
|
||
[appDelegate application:self.mockSharedApplication | ||
didFailToRegisterForRemoteNotificationsWithError:error]; | ||
|
||
XCTAssertEqual(appDelegate.registerForRemoteNotificationsError, error); | ||
|
||
#endif | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,17 +62,6 @@ target 'DynamicLinks_Example_iOS' do | |
pod 'OCMock' | ||
pod 'GoogleUtilities/MethodSwizzler', :path => '../' | ||
pod 'GoogleUtilities/SwizzlerTestHelpers', :path => '../' | ||
|
||
# Set define to turn on the unswizzler for the unit tests | ||
post_install do |installer_representation| | ||
installer_representation.pods_project.targets.each do |target| | ||
target.build_configurations.each do |config| | ||
if config.name != 'Release' | ||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'GUL_UNSWIZZLING_ENABLED=1'] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
@@ -272,3 +261,14 @@ target 'InstanceID_Example_tvOS' do | |
end | ||
end | ||
|
||
# Set define to turn on GUL_UNSWIZZLING and GUL_APP_DELEGATE_TESTING for the unit tests | ||
post_install do |installer_representation| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now (Cocoapods 1.6.1) there is only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, thanks! |
||
installer_representation.pods_project.targets.each do |target| | ||
target.build_configurations.each do |config| | ||
if config.name != 'Release' | ||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'GUL_UNSWIZZLING_ENABLED=1', 'GUL_APP_DELEGATE_TESTING=1'] | ||
end | ||
end | ||
end | ||
end | ||
|
Uh oh!
There was an error while loading. Please reload this page.