FIRStorageTestHelpers.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import <OCMock/OCMock.h>
  18. #import <XCTest/XCTest.h>
  19. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  20. #import "FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageConstants.h"
  21. #import "FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageMetadata.h"
  22. #import "FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageReference.h"
  23. #import "FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageTask.h"
  24. #import "FirebaseStorage/Sources/FIRStorageConstants_Private.h"
  25. #import "FirebaseStorage/Sources/FIRStorageErrors.h"
  26. #import "FirebaseStorage/Sources/FIRStorageReference_Private.h"
  27. #import "FirebaseStorage/Sources/FIRStorageTask_Private.h"
  28. #import "FirebaseStorage/Sources/FIRStorageTokenAuthorizer.h"
  29. #import "FirebaseStorage/Sources/FIRStorageUtils.h"
  30. #if SWIFT_PACKAGE
  31. @import GTMSessionFetcherCore;
  32. #else
  33. #import <GTMSessionFetcher/GTMSessionFetcher.h>
  34. #endif
  35. NS_ASSUME_NONNULL_BEGIN
  36. FOUNDATION_EXPORT NSString *const kGoogleHTTPErrorDomain;
  37. FOUNDATION_EXPORT NSString *const kHTTPVersion;
  38. FOUNDATION_EXPORT NSString *const kUnauthenticatedResponseString;
  39. FOUNDATION_EXPORT NSString *const kUnauthorizedResponseString;
  40. FOUNDATION_EXPORT NSString *const kNotFoundResponseString;
  41. FOUNDATION_EXPORT NSString *const kInvalidJSONResponseString;
  42. FOUNDATION_EXPORT NSString *const kFIRStorageValidURL;
  43. FOUNDATION_EXPORT NSString *const kFIRStorageNotFoundURL;
  44. FOUNDATION_EXPORT NSString *const kFIRStorageTestAuthToken;
  45. FOUNDATION_EXPORT NSString *const kFIRStorageAppName;
  46. /**
  47. * Standard timeout for all async tests.
  48. */
  49. static NSTimeInterval kExpectationTimeoutSeconds = 10;
  50. @interface FIRStorageTestHelpers : NSObject
  51. /**
  52. * Returns a mocked FIRApp with an injected container for interop and instance creation. No other
  53. * properties are set.
  54. */
  55. + (FIRApp *)mockedApp;
  56. /**
  57. * Returns a valid URL for an object stored.
  58. */
  59. + (NSURL *)objectURL;
  60. /**
  61. * Returns a valid URL for a bucket.
  62. */
  63. + (NSURL *)bucketURL;
  64. /**
  65. * Returns a valid URL for an object not found in the current storage bucket.
  66. */
  67. + (NSURL *)notFoundURL;
  68. /**
  69. * Returns a valid FIRStoragePath for an object stored.
  70. */
  71. + (FIRStoragePath *)objectPath;
  72. /**
  73. * Returns a valid FIRStoragePath for a bucket (no object).
  74. */
  75. + (FIRStoragePath *)bucketPath;
  76. /**
  77. * Returns a valid FIRStoragePath for an object not found in the current storage bucket.
  78. */
  79. + (FIRStoragePath *)notFoundPath;
  80. /**
  81. * Returns a FIRStorageReference that is backed by a mocked FIRApp.
  82. */
  83. + (FIRStorageReference *)rootReference;
  84. /**
  85. * Returns a successful response block.
  86. */
  87. + (GTMSessionFetcherTestBlock)successBlock;
  88. /**
  89. * Returns a successful response block that validates the provided URL.
  90. */
  91. + (GTMSessionFetcherTestBlock)successBlockWithURL:(NSString *)url;
  92. /**
  93. * Returns a successful response block containing object metadata.
  94. * @param metadata Metadata returned in the request.
  95. */
  96. + (GTMSessionFetcherTestBlock)successBlockWithMetadata:(nullable FIRStorageMetadata *)metadata;
  97. /**
  98. * Returns a unsuccessful response block due to improper authentication.
  99. */
  100. + (GTMSessionFetcherTestBlock)unauthenticatedBlock;
  101. /**
  102. * Returns a unsuccessful response block due to improper authorization.
  103. */
  104. + (GTMSessionFetcherTestBlock)unauthorizedBlock;
  105. /**
  106. * Returns a unsuccessful response block due the object not being found.
  107. */
  108. + (GTMSessionFetcherTestBlock)notFoundBlock;
  109. /**
  110. * Returns a unsuccessful response block due invalid JSON returned by the server.
  111. */
  112. + (GTMSessionFetcherTestBlock)invalidJSONBlock;
  113. /**
  114. * Waits for the given test case to time out by wrapping -waitForExpectation.
  115. */
  116. + (void)waitForExpectation:(id)test;
  117. @end
  118. NS_ASSUME_NONNULL_END