Skip to content

Add a unit test to verify behavior w/ URLSession:dataTask:didReceiveResponse:completionHandler: #14489

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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Revert the changes to swizzle the additional delegate method
  • Loading branch information
tejasd committed Feb 28, 2025
commit 4e3034ca898407f72fc6dcab34f200e81ace01d2
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ - (void)URLSession:(NSURLSession *)session
[trace checkpointState:FPRNetworkTraceCheckpointStateResponseReceived];
}

//- (void)URLSession:(NSURLSession *)session
// dataTask:(NSURLSessionDataTask *)dataTask
// didReceiveResponse:(NSURLResponse *)response
// completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
// FPRNetworkTrace *trace = [FPRNetworkTrace networkTraceFromObject:dataTask];
// [trace checkpointState:FPRNetworkTraceCheckpointStateResponseReceived];
// completionHandler(NSURLSessionResponseAllow);
//}

- (void)URLSession:(NSURLSession *)session
downloadTask:(NSURLSessionDownloadTask *)downloadTask
didFinishDownloadingToURL:(NSURL *)location {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ static dispatch_queue_t GetInstrumentationQueue(void) {
return queue;
}

typedef void (^FPRDataTaskDelegateCompletionHandler)(NSURLSessionResponseDisposition);

#pragma mark - NSURLSessionTaskDelegate methods

/** Instruments URLSession:task:didCompleteWithError:.
Expand Down Expand Up @@ -126,37 +124,6 @@ void InstrumentURLSessionDataTaskDidReceiveData(FPRClassInstrumentor *instrument
}
}

/** Instruments URLSession:dataTask:didReceiveResponse:completionHandler:
*
* @param instrumentor The FPRClassInstrumentor to add the selector instrumentor to.
*/
FOUNDATION_STATIC_INLINE
NS_EXTENSION_UNAVAILABLE("Firebase Performance is not supported for extensions.")
void InstrumentURLSessionDataTaskDidReceiveResponseCompletionHandler(
FPRClassInstrumentor *instrumentor) {
SEL selector = @selector(URLSession:dataTask:didReceiveResponse:completionHandler:);
FPRSelectorInstrumentor *selectorInstrumentor =
[instrumentor instrumentorForInstanceSelector:selector];
if (selectorInstrumentor) {
IMP currentIMP = selectorInstrumentor.currentIMP;
[selectorInstrumentor
setReplacingBlock:^(id object, NSURLSession *session, NSURLSessionDataTask *task,
NSURLResponse *response,
FPRDataTaskDelegateCompletionHandler completionHandler) {
@try {
FPRNetworkTrace *trace = [FPRNetworkTrace networkTraceFromObject:task];
[trace checkpointState:FPRNetworkTraceCheckpointStateResponseReceived];
} @catch (NSException *exception) {
FPRLogWarning(kFPRNetworkTraceNotTrackable, @"Unable to track network request.");
} @finally {
typedef void (*OriginalImp)(id, SEL, NSURLSession *, NSURLSessionDataTask *,
NSURLResponse *, FPRDataTaskDelegateCompletionHandler);
((OriginalImp)currentIMP)(object, selector, session, task, response, completionHandler);
}
}];
}
}

#pragma mark - NSURLSessionDownloadDelegate methods.

/** Instruments URLSession:downloadTask:didFinishDownloadingToURL:.
Expand Down Expand Up @@ -257,8 +224,6 @@ - (void)registerClass:(Class)aClass {

// NSURLSessionDataDelegate methods.
InstrumentURLSessionDataTaskDidReceiveData(instrumentor);
// InstrumentURLSessionDataTaskDidReceiveResponseCompletionHandler(instrumentor);


// NSURLSessionDownloadDelegate methods.
InstrumentURLSessionDownloadTaskDidFinishDownloadToURL(instrumentor);
Expand All @@ -285,8 +250,6 @@ - (void)registerObject:(id)object {

// NSURLSessionDataDelegate methods.
CopySelector(@selector(URLSession:dataTask:didReceiveData:), instrumentor);
// CopySelector(@selector(URLSession:dataTask:didReceiveResponse:completionHandler:),
// instrumentor);

// NSURLSessionDownloadDelegate methods.
CopySelector(@selector(URLSession:downloadTask:didFinishDownloadingToURL:), instrumentor);
Expand Down
Loading