-
Notifications
You must be signed in to change notification settings - Fork 1.6k
FCM: Fix crash on iOS 14 when multiple app delegate completion methods are called #6863
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81fbde4
Fix crash on iOS 14 when multiple completion methods are called
mikeger f56db59
Fixed lint
mikeger 2c9ff1a
Addressed the PR comments & implemented unit tests
mikeger 2710c04
Reverted auto-extracted method
mikeger 1988b4c
Re-organized tests
mikeger 1556a49
Added completion handler for FIRAuth
mikeger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1065,12 +1065,12 @@ - (void)testApplicationDidReceiveRemoteNotificationWithCompletionIsInvokedOnInte | |
id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate)); | ||
OCMExpect([interceptor application:application | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:completion]); | ||
fetchCompletionHandler:[OCMArg isNotNil]]); | ||
|
||
id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate)); | ||
OCMExpect([interceptor2 application:application | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:completion]); | ||
fetchCompletionHandler:[OCMArg isNotNil]]); | ||
|
||
GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init]; | ||
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate); | ||
|
@@ -1087,7 +1087,108 @@ - (void)testApplicationDidReceiveRemoteNotificationWithCompletionIsInvokedOnInte | |
|
||
XCTAssertEqual(testAppDelegate.application, application); | ||
XCTAssertEqual(testAppDelegate.remoteNotification, notification); | ||
XCTAssertEqual(testAppDelegate.remoteNotificationCompletionHandler, completion); | ||
} | ||
|
||
- (void)verifyCompletionCalledForObserverResult:(UIBackgroundFetchResult)observerResult1 | ||
anotherObserverResult:(UIBackgroundFetchResult)observerResult2 | ||
swizzledResult:(UIBackgroundFetchResult)swizzledResult | ||
expecredResult:(UIBackgroundFetchResult)expectedResult { | ||
NSDictionary *notification = @{}; | ||
GULApplication *application = [GULApplication sharedApplication]; | ||
|
||
XCTestExpectation *completionExpectation = | ||
[[XCTestExpectation alloc] initWithDescription:@"Completion called once"]; | ||
|
||
void (^completion)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) { | ||
XCTAssertEqual(result, expectedResult); | ||
[completionExpectation fulfill]; | ||
}; | ||
|
||
void (^onDidReceiveRemoteNotification1)(NSInvocation *invocation) = ^(NSInvocation *invocation) { | ||
void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil; | ||
[invocation getArgument:(void *)(&localCompletionHandler) atIndex:4]; | ||
XCTAssertNotNil(localCompletionHandler); | ||
localCompletionHandler(observerResult1); | ||
}; | ||
|
||
id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate)); | ||
OCMExpect([interceptor application:application | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:[OCMArg isNotNil]]) | ||
.andDo(onDidReceiveRemoteNotification1); | ||
|
||
void (^onDidReceiveRemoteNotification2)(NSInvocation *invocation) = ^(NSInvocation *invocation) { | ||
void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil; | ||
[invocation getArgument:(void *)(&localCompletionHandler) atIndex:4]; | ||
XCTAssertNotNil(localCompletionHandler); | ||
localCompletionHandler(observerResult2); | ||
}; | ||
|
||
id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate)); | ||
OCMExpect([interceptor2 application:application | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:[OCMArg isNotNil]]) | ||
.andDo(onDidReceiveRemoteNotification2); | ||
|
||
GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init]; | ||
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate); | ||
[GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods]; | ||
|
||
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor]; | ||
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor2]; | ||
|
||
[testAppDelegate application:application | ||
didReceiveRemoteNotification:notification | ||
fetchCompletionHandler:completion]; | ||
testAppDelegate.remoteNotificationCompletionHandler(swizzledResult); | ||
OCMVerifyAll(interceptor); | ||
OCMVerifyAll(interceptor2); | ||
[self waitForExpectations:@[ completionExpectation ] timeout:0.1]; | ||
} | ||
|
||
- (void)testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultNoData | ||
anotherObserverResult:UIBackgroundFetchResultNoData | ||
swizzledResult:UIBackgroundFetchResultNoData | ||
expecredResult:UIBackgroundFetchResultNoData]; | ||
} | ||
|
||
- (void) | ||
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. It would be nice to add tests for cases with different fetch results or at least add a |
||
testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleFailedState { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultFailed | ||
anotherObserverResult:UIBackgroundFetchResultFailed | ||
swizzledResult:UIBackgroundFetchResultFailed | ||
expecredResult:UIBackgroundFetchResultFailed]; | ||
} | ||
|
||
- (void)testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_NoData { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultNoData | ||
anotherObserverResult:UIBackgroundFetchResultFailed | ||
swizzledResult:UIBackgroundFetchResultFailed | ||
expecredResult:UIBackgroundFetchResultNoData]; | ||
} | ||
- (void) | ||
testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersFailed { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultNewData | ||
anotherObserverResult:UIBackgroundFetchResultFailed | ||
swizzledResult:UIBackgroundFetchResultFailed | ||
expecredResult:UIBackgroundFetchResultNewData]; | ||
} | ||
|
||
- (void) | ||
testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersNoData { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultNewData | ||
anotherObserverResult:UIBackgroundFetchResultNoData | ||
swizzledResult:UIBackgroundFetchResultNoData | ||
expecredResult:UIBackgroundFetchResultNewData]; | ||
} | ||
|
||
- (void) | ||
testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersNoDataFailed { | ||
[self verifyCompletionCalledForObserverResult:UIBackgroundFetchResultNewData | ||
anotherObserverResult:UIBackgroundFetchResultNoData | ||
swizzledResult:UIBackgroundFetchResultFailed | ||
expecredResult:UIBackgroundFetchResultNewData]; | ||
} | ||
|
||
- (void)testApplicationDidReceiveRemoteNotificationWithCompletionImplementationIsNotAdded { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation doesn't add the originally implemented method to the group. I think we should do the same for it: add enter/leave group calls and wrap the completion. Potentially we may use a single completion handler wrapper to be passed to all interceptors and the original implementations.