FPRNSURLConnectionInstrumentTestDelegates.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTestDelegates.h"
  15. #import "FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.h"
  16. @implementation FPRNSURLConnectionDidReceiveDataDelegate
  17. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  18. self.connectionDidReceiveDataCalled = YES;
  19. }
  20. // Is required to cause connection:didReceiveData: to be called.
  21. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  22. self.connectionDidFinishLoadingCalled = YES;
  23. }
  24. @end
  25. @implementation FPRNSURLConnectionTestDelegate
  26. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  27. self.connectionDidFailWithErrorCalled = YES;
  28. }
  29. - (NSURLRequest *)connection:(NSURLConnection *)connection
  30. willSendRequest:(nonnull NSURLRequest *)request
  31. redirectResponse:(nullable NSURLResponse *)response {
  32. self.connectionWillSendRequestRedirectResponseCalled = YES;
  33. return request;
  34. }
  35. - (void)connectionDidFinishDownloading:(NSURLConnection *)connection
  36. destinationURL:(NSURL *)destinationURL {
  37. self.connectionDidFinishDownloadingDestinationURLCalled = YES;
  38. }
  39. @end
  40. @implementation FPRNSURLConnectionOperationTestDelegate
  41. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  42. self.connectionDidFailWithErrorCalled = YES;
  43. }
  44. - (NSURLRequest *)connection:(NSURLConnection *)connection
  45. willSendRequest:(nonnull NSURLRequest *)request
  46. redirectResponse:(nullable NSURLResponse *)response {
  47. self.connectionWillSendRequestRedirectResponseCalled = YES;
  48. return request;
  49. }
  50. - (void)connectionDidFinishDownloading:(NSURLConnection *)connection
  51. destinationURL:(NSURL *)destinationURL {
  52. self.connectionDidFinishDownloadingDestinationURLCalled = YES;
  53. }
  54. @end
  55. @implementation FPRNSURLConnectionDataTestDelegate
  56. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  57. self.connectionDidFinishLoadingCalled = YES;
  58. }
  59. @end
  60. @implementation FPRNSURLConnectionDownloadTestDelegate
  61. - (void)connectionDidFinishDownloading:(NSURLConnection *)connection
  62. destinationURL:(NSURL *)destinationURL {
  63. self.connectionDidFinishDownloadingDestinationURLCalled = YES;
  64. }
  65. @end
  66. @implementation FPRNSURLConnectionCompleteTestDelegate
  67. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  68. self.connectionDidFailWithErrorCalled = YES;
  69. }
  70. - (NSURLRequest *)connection:(NSURLConnection *)connection
  71. willSendRequest:(nonnull NSURLRequest *)request
  72. redirectResponse:(nullable NSURLResponse *)response {
  73. // If response is nil, this is being called by iOS for URL canonicalization, not for a redirect.
  74. if (response) {
  75. self.connectionWillSendRequestRedirectResponseCalled = YES;
  76. }
  77. return request;
  78. }
  79. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  80. self.connectionDidReceiveResponseCalled = YES;
  81. }
  82. - (void)connection:(NSURLConnection *)connection
  83. didSendBodyData:(NSInteger)bytesWritten
  84. totalBytesWritten:(NSInteger)totalBytesWritten
  85. totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
  86. self.connectionDidSendBodyDataTotalBytesWrittenTotalBytesExpectedToWriteCalled = YES;
  87. }
  88. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  89. self.connectionDidFinishLoadingCalled = YES;
  90. }
  91. - (void)connection:(NSURLConnection *)connection
  92. didWriteData:(long long)bytesWritten
  93. totalBytesWritten:(long long)totalBytesWritten
  94. expectedTotalBytes:(long long)expectedTotalBytes {
  95. self.connectionDidWriteDataTotalBytesWrittenExpectedTotalBytesCalled = YES;
  96. }
  97. - (void)connectionDidFinishDownloading:(NSURLConnection *)connection
  98. destinationURL:(NSURL *)destinationURL {
  99. self.connectionDidFinishDownloadingDestinationURLCalled = YES;
  100. }
  101. @end