|
20 | 20 | #import <FirebaseCore/FIRCoreDiagnosticsConnector.h>
|
21 | 21 | #import <FirebaseCore/FIROptionsInternal.h>
|
22 | 22 |
|
| 23 | +#import <GoogleUtilities/GULAppEnvironmentUtil.h> |
| 24 | + |
23 | 25 | NSString *const kFIRTestAppName1 = @"test_app_name_1";
|
24 | 26 | NSString *const kFIRTestAppName2 = @"test-app-name-2";
|
25 | 27 |
|
@@ -214,6 +216,81 @@ - (void)testConfigureWithMultipleApps {
|
214 | 216 | XCTAssertEqualObjects(app.options.APIKey, kCustomizedAPIKey);
|
215 | 217 | }
|
216 | 218 |
|
| 219 | +- (void)testConfigureThrowsAfterConfigured { |
| 220 | + FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID |
| 221 | + GCMSenderID:kGCMSenderID]; |
| 222 | + [FIRApp configureWithOptions:options]; |
| 223 | + XCTAssertNotNil([FIRApp defaultApp]); |
| 224 | + |
| 225 | + // A second configure call should throw, since Firebase is already configured. |
| 226 | + XCTAssertThrows([FIRApp configureWithOptions:options]); |
| 227 | + |
| 228 | + // Test the same with a custom named app. |
| 229 | + [FIRApp configureWithName:kFIRTestAppName1 options:options]; |
| 230 | + XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]); |
| 231 | + |
| 232 | + // A second configure call should throw, since Firebase is already configured. |
| 233 | + XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:options]); |
| 234 | +} |
| 235 | + |
| 236 | +- (void)testConfigureDefaultAppInExtension { |
| 237 | + id environmentMock = OCMClassMock([GULAppEnvironmentUtil class]); |
| 238 | + OCMStub([environmentMock isAppExtension]).andReturn(YES); |
| 239 | + |
| 240 | + // Set up the default app like a standard app. |
| 241 | + FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID |
| 242 | + GCMSenderID:kGCMSenderID]; |
| 243 | + [FIRApp configureWithOptions:options]; |
| 244 | + XCTAssertNotNil([FIRApp defaultApp]); |
| 245 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 246 | + |
| 247 | + // Configuring with the same set of options shouldn't throw. |
| 248 | + XCTAssertNoThrow([FIRApp configureWithOptions:options]); |
| 249 | + |
| 250 | + // Only 1 app should have been configured still, the default app. |
| 251 | + XCTAssertNotNil([FIRApp defaultApp]); |
| 252 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 253 | + |
| 254 | + // Use a set of a different options to call configure again, which should throw. |
| 255 | + FIROptions *differentOptions = [[FIROptions alloc] initWithGoogleAppID:@"1:789:ios:789XYZ" |
| 256 | + GCMSenderID:kGCMSenderID]; |
| 257 | + XCTAssertThrows([FIRApp configureWithOptions:differentOptions]); |
| 258 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 259 | + |
| 260 | + // Explicily stop the environmentMock. |
| 261 | + [environmentMock stopMocking]; |
| 262 | + environmentMock = nil; |
| 263 | +} |
| 264 | + |
| 265 | +- (void)testConfigureCustomAppInExtension { |
| 266 | + id environmentMock = OCMClassMock([GULAppEnvironmentUtil class]); |
| 267 | + OCMStub([environmentMock isAppExtension]).andReturn(YES); |
| 268 | + |
| 269 | + // Set up a custom named app like a standard app. |
| 270 | + FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID |
| 271 | + GCMSenderID:kGCMSenderID]; |
| 272 | + [FIRApp configureWithName:kFIRTestAppName1 options:options]; |
| 273 | + XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]); |
| 274 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 275 | + |
| 276 | + // Configuring with the same set of options shouldn't throw. |
| 277 | + XCTAssertNoThrow([FIRApp configureWithName:kFIRTestAppName1 options:options]); |
| 278 | + |
| 279 | + // Only 1 app should have been configured still. |
| 280 | + XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]); |
| 281 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 282 | + |
| 283 | + // Use a set of a different options to call configure again, which should throw. |
| 284 | + FIROptions *differentOptions = [[FIROptions alloc] initWithGoogleAppID:@"1:789:ios:789XYZ" |
| 285 | + GCMSenderID:kGCMSenderID]; |
| 286 | + XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:differentOptions]); |
| 287 | + XCTAssertEqual([FIRApp allApps].count, 1); |
| 288 | + |
| 289 | + // Explicily stop the environmentMock. |
| 290 | + [environmentMock stopMocking]; |
| 291 | + environmentMock = nil; |
| 292 | +} |
| 293 | + |
217 | 294 | - (void)testValidName {
|
218 | 295 | XCTAssertNoThrow([FIRApp configureWithName:@"aA1_" options:[FIROptions defaultOptions]]);
|
219 | 296 | XCTAssertNoThrow([FIRApp configureWithName:@"aA1-" options:[FIROptions defaultOptions]]);
|
|
0 commit comments