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 all commits
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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7
2.7.4
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)registerObject:(id)object;

/** Registers an instance of the delegate class to be instrumented.
*
* @param proxy The instance to instrument.
*/
- (void)registerProxy:(id)proxy;

@end

/** This class allows the instrumentation of specific objects by isa swizzling specific instances
Expand Down
11 changes: 11 additions & 0 deletions FirebasePerformance/Sources/Instrumentation/FPRProxyObjectHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@
forSuperclass:(Class)superclass
varFoundHandler:(void (^)(id ivar))varFoundHandler;

/** Registers a proxy object for a given class and runs the onSuccess block whenever an ivar of the
* given class is discovered on the proxy object.
*
* @param proxy The proxy object whose ivars will be iterated.
* @param protocol The protocol all ivars will be compared against. See varFoundHandler.
* @param varFoundHandler The block to run when an ivar conformsToProtocol:protocol.
*/
+ (void)registerProxyObject:(id)proxy
forProtocol:(Protocol *)protocol
varFoundHandler:(void (^)(id ivar))varFoundHandler;

@end
11 changes: 11 additions & 0 deletions FirebasePerformance/Sources/Instrumentation/FPRProxyObjectHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ + (void)registerProxyObject:(id)proxy
}
}

+ (void)registerProxyObject:(id)proxy
forProtocol:(Protocol *)protocol
varFoundHandler:(void (^)(id ivar))varFoundHandler {
NSArray<id> *ivars = [GULSwizzler ivarObjectsForObject:proxy];
for (id ivar in ivars) {
if ([ivar conformsToProtocol:protocol]) {
varFoundHandler(ivar);
}
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "FirebasePerformance/Sources/Instrumentation/FPRClassInstrumentor.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRInstrument_Private.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRProxyObjectHelper.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.h"
#import "FirebasePerformance/Sources/Instrumentation/Network/Delegates/FPRNSURLConnectionDelegate.h"
#import "FirebasePerformance/Sources/Instrumentation/Network/FPRNetworkInstrumentHelpers.h"
Expand Down Expand Up @@ -304,4 +305,13 @@ - (void)registerObject:(id)object {
});
}

- (void)registerProxy:(id)proxy {
[FPRProxyObjectHelper registerProxyObject:proxy
forProtocol:@protocol(NSURLSessionDelegate)
varFoundHandler:^(id ivar) {
[self registerClass:[ivar class]];
[self registerObject:ivar];
}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "FirebasePerformance/Sources/Instrumentation/FPRClassInstrumentor.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRInstrument_Private.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRProxyObjectHelper.h"
#import "FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.h"
#import "FirebasePerformance/Sources/Instrumentation/Network/Delegates/FPRNSURLSessionDelegate.h"
#import "FirebasePerformance/Sources/Instrumentation/Network/FPRNetworkInstrumentHelpers.h"
Expand Down Expand Up @@ -263,4 +264,13 @@ - (void)registerObject:(id)object {
});
}

- (void)registerProxy:(id)proxy {
[FPRProxyObjectHelper registerProxyObject:proxy
forProtocol:@protocol(NSURLSessionDelegate)
varFoundHandler:^(id ivar) {
[self registerClass:[ivar class]];
[self registerObject:ivar];
}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ void InstrumentSessionWithConfigurationDelegateDelegateQueue(
ThrowExceptionBecauseInstrumentHasBeenDeallocated(selector, instrumentedClass);
}
if (delegate) {
[delegateInstrument registerClass:[delegate class]];
[delegateInstrument registerObject:delegate];

if ([delegate isProxy]) {
[delegateInstrument registerProxy:delegate];
} else {
[delegateInstrument registerClass:[delegate class]];
[delegateInstrument registerObject:delegate];
}
} else {
delegate = [[FPRNSURLSessionDelegate alloc] init];
}
Expand Down
Loading
Loading