Skip to content
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

FIRMessagingRemoteNotificationsProxy updated to use GULAppDelegateSwizzler #2683

Merged
merged 31 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b2eabf2
FIRAuthAppDelegateProxy: implementation updated to use GULAppDelegate…
maksymmalyhin Mar 26, 2019
4ab86de
GULAppDelegateSwizzler - make sure subclass name is unique.
maksymmalyhin Mar 27, 2019
1f1560a
GoogleUtilities: enable code coverage
maksymmalyhin Mar 27, 2019
f4a4638
Merge branch 'master'
maksymmalyhin Mar 27, 2019
9fcedce
GULAppDelegateSwizzler: Add support of remote notification methods
maksymmalyhin Mar 27, 2019
27c8b5b
GULAppDelegateSwizzler - tests for remote notification methods
maksymmalyhin Mar 27, 2019
dee28d3
Revert "FIRAuthAppDelegateProxy: implementation updated to use GULApp…
maksymmalyhin Mar 27, 2019
5821591
FIRMessaging: prepare to use GULAppDelegateSwizzler [WIP]
maksymmalyhin Mar 27, 2019
908b6ea
FIRMessagingRemoteNotificationsProxy - use GULAppDelegateSwizzler [WIP]
maksymmalyhin Mar 28, 2019
9e377d2
FIRMessagingRemoteNotificationsProxy - AppDelegate proxy - test only …
maksymmalyhin Mar 28, 2019
7861cde
FIRMessagingRemoteNotificationsProxy test only public API with no imp…
maksymmalyhin Mar 28, 2019
b7703ac
Cleanup
maksymmalyhin Mar 28, 2019
ad1da54
Cleanup
maksymmalyhin Mar 28, 2019
2bdf353
Merge branch 'master'
maksymmalyhin Mar 28, 2019
8eafece
Merge branch 'mm/messaging-tests'
maksymmalyhin Mar 28, 2019
e5d2ce8
Merge branch 'master'
maksymmalyhin Mar 29, 2019
86ff257
Cocoapods 1.6.1: Podfile supports only single post_install hook. It i…
maksymmalyhin Mar 29, 2019
79b7613
FIRMessagingRemoteNotificationsProxyTest: [GULAppDelegateSwizzler res…
maksymmalyhin Mar 29, 2019
98ffccb
FIRMessagingRemoteNotificationsProxy: app delegate missing methods te…
maksymmalyhin Mar 29, 2019
cd44395
GULAppDelegateSwizzler: don't swizzle invalid application delegate
maksymmalyhin Mar 29, 2019
3df4140
Cleanup
maksymmalyhin Mar 29, 2019
dcd0e10
Run ./scripts/check.sh
maksymmalyhin Mar 29, 2019
18381dd
Merge branch 'master'
maksymmalyhin Apr 1, 2019
dae75d9
GoogleUtilities/GULAppDelegateSwizzler - tvOS support
maksymmalyhin Apr 1, 2019
6dee8d3
style.sh generated changes
maksymmalyhin Apr 1, 2019
2726e7c
FirebaseMessaging - missing dependencies added
maksymmalyhin Apr 1, 2019
63fd1f5
FCM data channel messages - pass data to [FIRMessaging appDidReceiveM…
maksymmalyhin Apr 1, 2019
4a3fbb1
FIRMessagingRemoteNotificationsProxyTest - remove GULLoggerForceDebug()
maksymmalyhin Apr 2, 2019
b390f4f
GULAppDelegateSwizzler - add deprecated `application:didReceiveRemote…
maksymmalyhin Apr 2, 2019
236877d
Merge branch 'master'
maksymmalyhin Apr 3, 2019
3641d35
Merge branch 'master'
maksymmalyhin Apr 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/Firebase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7613,6 +7613,7 @@
"$(inherited)",
"COCOAPODS=1",
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
"GUL_APP_DELEGATE_TESTING=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
Expand Down
54 changes: 50 additions & 4 deletions Example/Messaging/Tests/FIRMessagingRemoteNotificationsProxyTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#import "FIRMessaging.h"
#import "FIRMessagingRemoteNotificationsProxy.h"

#import <GoogleUtilities/GULLogger.h>
charlotteliang marked this conversation as resolved.
Show resolved Hide resolved
#import <GoogleUtilities/GULAppDelegateSwizzler.h>

#pragma mark - Invalid App Delegate or UNNotificationCenter

@interface RandomObject : NSObject
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -107,6 +123,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
@end
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

@interface GULAppDelegateSwizzler (FIRMessagingRemoteNotificationsProxyTest)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand All @@ -123,6 +143,10 @@ @implementation FIRMessagingRemoteNotificationsProxyTest

- (void)setUp {
[super setUp];

GULLoggerForceDebug();
[GULAppDelegateSwizzler resetProxyOriginalDelegateOnceToken];

_mockSharedApplication = OCMPartialMock([UIApplication sharedApplication]);

_mockMessaging = OCMClassMock([FIRMessaging class]);
Expand All @@ -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
}

Expand All @@ -149,6 +172,9 @@ - (void)tearDown {
[_mockSharedApplication stopMocking];
_mockSharedApplication = nil;

[_mockUserNotificationCenter stopMocking];
_mockUserNotificationCenter = nil;

_proxy = nil;
[super tearDown];
}
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 11 additions & 11 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now (Cocoapods 1.6.1) there is only post_install hook supported for entire Podfile. It affects all targets anyways, so I moved it to the upper level to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Loading