aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
Diffstat (limited to 'Example')
-rw-r--r--Example/Auth/ApiTests/FirebaseAuthApiTests.m16
-rw-r--r--Example/Core/Tests/FIRAppTest.m130
-rw-r--r--Example/Core/Tests/FIROptionsTest.m10
-rw-r--r--Example/Firebase.xcodeproj/project.pbxproj40
-rw-r--r--Example/Messaging/Tests/FIRMessagingTest.m40
5 files changed, 228 insertions, 8 deletions
diff --git a/Example/Auth/ApiTests/FirebaseAuthApiTests.m b/Example/Auth/ApiTests/FirebaseAuthApiTests.m
index 741814c..d4f4da2 100644
--- a/Example/Auth/ApiTests/FirebaseAuthApiTests.m
+++ b/Example/Auth/ApiTests/FirebaseAuthApiTests.m
@@ -130,7 +130,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"Created account with email and password."];
[auth createUserWithEmail:kTestingEmailToCreateUser
password:@"password"
- completion:^(FIRUser *user, NSError *error) {
+ completion:^(FIRAuthDataResult *result, NSError *error) {
if (error) {
NSLog(@"createUserWithEmail has error: %@", error);
}
@@ -163,7 +163,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"Created account with email and password."];
[auth createUserWithEmail:kTestingEmailToCreateUser
password:@"password"
- completion:^(FIRUser *user, NSError *error) {
+ completion:^(FIRAuthDataResult *user, NSError *error) {
apiError = error;
[expectation fulfill];
}];
@@ -240,7 +240,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"Signed in existing account with email and password."];
[auth signInWithEmail:kExistingTestingEmailToSignIn
password:@"password"
- completion:^(FIRUser *user, NSError *error) {
+ completion:^(FIRAuthDataResult *user, NSError *error) {
if (error) {
NSLog(@"Signing in existing account has error: %@", error);
}
@@ -277,7 +277,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"CustomAuthToken sign-in finished."];
[auth signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
if (error) {
NSLog(@"Valid token sign in error: %@", error);
}
@@ -314,7 +314,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
__block NSError *apiError;
[auth signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
if (error) {
apiError = error;
}
@@ -349,7 +349,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"CustomAuthToken sign-in finished."];
__block NSError *rpcError;
[auth signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
if (error) {
rpcError = error;
}
@@ -390,7 +390,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
[self expectationWithDescription:@"Invalid CustomAuthToken sign-in finished."];
[auth signInWithCustomToken:kInvalidCustomToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
XCTAssertEqualObjects(error.localizedDescription, kInvalidTokenErrorMessage);
[expectation fulfill];
@@ -583,7 +583,7 @@ static NSTimeInterval const kExpectationsTimeout = 10;
XCTestExpectation *expectation =
[self expectationWithDescription:@"Anonymousy sign-in finished."];
- [auth signInAnonymouslyWithCompletion:^(FIRUser *user, NSError *error) {
+ [auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult *result, NSError *error) {
if (error) {
NSLog(@"Anonymousy sign in error: %@", error);
}
diff --git a/Example/Core/Tests/FIRAppTest.m b/Example/Core/Tests/FIRAppTest.m
index 6825e6a..abf1d38 100644
--- a/Example/Core/Tests/FIRAppTest.m
+++ b/Example/Core/Tests/FIRAppTest.m
@@ -42,6 +42,9 @@ NSString *const kFIRTestAppName2 = @"test-app-name-2";
+ (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version;
+ (BOOL)validateAppIDFingerprint:(NSString *)appID withVersion:(NSString *)version;
++ (nullable NSNumber *)readDataCollectionSwitchFromPlist;
++ (nullable NSNumber *)readDataCollectionSwitchFromUserDefaultsForApp:(FIRApp *)app;
+
@end
@interface FIRAppTest : FIRTestCase
@@ -552,6 +555,133 @@ NSString *const kFIRTestAppName2 = @"test-app-name-2";
[FIRApp validateAppIDFingerprint:@"1:1337:ios:deadbeef:ab" withVersion:kGoodVersionV1]);
}
+#pragma mark - Automatic Data Collection Tests
+
+- (void)testGlobalDataCollectionNoFlags {
+ // Test: No flags set.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(nil);
+
+ XCTAssertTrue([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionPlistSetEnabled {
+ // Test: Plist set to enabled, no override.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(nil);
+
+ XCTAssertTrue([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionPlistSetDisabled {
+ // Test: Plist set to disabled, no override.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(nil);
+
+ XCTAssertFalse([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionUserSpecifiedEnabled {
+ // Test: User specified as enabled, no plist value.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(@YES);
+
+ XCTAssertTrue([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionUserSpecifiedDisabled {
+ // Test: User specified as disabled, no plist value.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(@NO);
+
+ XCTAssertFalse([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionUserOverriddenEnabled {
+ // Test: User specified as enabled, with plist set as disabled.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(@YES);
+
+ XCTAssertTrue([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionUserOverriddenDisabled {
+ // Test: User specified as disabled, with plist set as enabled.
+ [FIRApp configure];
+ OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(@NO);
+
+ XCTAssertFalse([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionWriteToDefaults {
+ id defaultsMock = OCMPartialMock([NSUserDefaults standardUserDefaults]);
+ [FIRApp configure];
+
+ FIRApp *app = [FIRApp defaultApp];
+ app.automaticDataCollectionEnabled = YES;
+ NSString *key =
+ [NSString stringWithFormat:kFIRGlobalAppDataCollectionEnabledDefaultsKeyFormat, app.name];
+ OCMVerify([defaultsMock setObject:@YES forKey:key]);
+
+ [FIRApp defaultApp].automaticDataCollectionEnabled = NO;
+ OCMVerify([defaultsMock setObject:@NO forKey:key]);
+
+ [defaultsMock stopMocking];
+}
+
+- (void)testGlobalDataCollectionClearedAfterDelete {
+ // Configure and disable data collection for the default FIRApp.
+ [FIRApp configure];
+ FIRApp *app = [FIRApp defaultApp];
+ app.automaticDataCollectionEnabled = NO;
+ XCTAssertFalse(app.isAutomaticDataCollectionEnabled);
+
+ // Delete the app, and verify that the switch was reset.
+ XCTestExpectation *deleteFinished =
+ [self expectationWithDescription:@"The app should successfully delete."];
+ [app deleteApp:^(BOOL success) {
+ if (success) {
+ [deleteFinished fulfill];
+ }
+ }];
+
+ // Wait for the delete to complete.
+ [self waitForExpectations:@[ deleteFinished ] timeout:1];
+
+ // Set up the default app again, and check the data collection flag.
+ [FIRApp configure];
+ XCTAssertTrue([FIRApp defaultApp].isAutomaticDataCollectionEnabled);
+}
+
+- (void)testGlobalDataCollectionNoDiagnosticsSent {
+ [FIRApp configure];
+
+ // Stub out reading from user defaults since stubbing out the BOOL has issues. If the data
+ // collection switch is disabled, the `sendLogs` call should return immediately and not fire a
+ // notification.
+ OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
+ .andReturn(@NO);
+ OCMReject([self.notificationCenterMock postNotificationName:kFIRAppDiagnosticsNotification
+ object:OCMOCK_ANY
+ userInfo:OCMOCK_ANY]);
+ NSError *error = [NSError errorWithDomain:@"com.firebase" code:42 userInfo:nil];
+ [[FIRApp defaultApp] sendLogsWithServiceName:@"Service" version:@"Version" error:error];
+}
+
#pragma mark - Internal Methods
- (void)testAuthGetUID {
diff --git a/Example/Core/Tests/FIROptionsTest.m b/Example/Core/Tests/FIROptionsTest.m
index 20aec94..064745a 100644
--- a/Example/Core/Tests/FIROptionsTest.m
+++ b/Example/Core/Tests/FIROptionsTest.m
@@ -17,6 +17,7 @@
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRBundleUtil.h>
#import <FirebaseCore/FIROptionsInternal.h>
+#import <FirebaseCore/FIRVersion.h>
extern NSString *const kFIRIsMeasurementEnabled;
extern NSString *const kFIRIsAnalyticsCollectionEnabled;
@@ -437,4 +438,13 @@ extern NSString *const kFIRLibraryVersionID;
XCTAssertEqual(numberOfMatches, 1, @"Incorrect library version format.");
}
+- (void)testVersionConsistency {
+ const char *versionString = [kFIRLibraryVersionID UTF8String];
+ int major = versionString[0] - '0';
+ int minor = (versionString[1] - '0') * 10 + versionString[2] - '0';
+ int patch = (versionString[3] - '0') * 10 + versionString[4] - '0';
+ NSString *str = [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch];
+ XCTAssertEqualObjects(str, [NSString stringWithUTF8String:(const char *)FIRCoreVersionString]);
+}
+
@end
diff --git a/Example/Firebase.xcodeproj/project.pbxproj b/Example/Firebase.xcodeproj/project.pbxproj
index 26e0c33..f924ed4 100644
--- a/Example/Firebase.xcodeproj/project.pbxproj
+++ b/Example/Firebase.xcodeproj/project.pbxproj
@@ -4707,6 +4707,10 @@
INFOPLIST_FILE = "Messaging/Sample/iOS/Messaging-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.google.FirebaseMessagingSample.dev;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -4732,6 +4736,10 @@
INFOPLIST_FILE = "Messaging/Sample/iOS/Messaging-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.google.FirebaseMessagingSample.dev;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -5929,6 +5937,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Database/App/iOS/Database-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Database-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -5948,6 +5960,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Database/App/iOS/Database-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Database-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -6047,6 +6063,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Auth/App/iOS/Auth-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Auth-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -6069,6 +6089,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Auth/App/iOS/Auth-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Auth-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -6461,6 +6485,10 @@
);
INFOPLIST_FILE = "$(SRCROOT)/Storage/App/iOS/Storage-Info.plist";
MODULE_NAME = ExampleApp;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Storage-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
@@ -6482,6 +6510,10 @@
);
INFOPLIST_FILE = "$(SRCROOT)/Storage/App/iOS/Storage-Info.plist";
MODULE_NAME = ExampleApp;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Storage-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
@@ -6543,6 +6575,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Core/App/iOS/Core-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Core-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -6560,6 +6596,10 @@
INFOPLIST_FILE = "$(SRCROOT)/Core/App/iOS/Core-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-all_load",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Core-Example-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};
diff --git a/Example/Messaging/Tests/FIRMessagingTest.m b/Example/Messaging/Tests/FIRMessagingTest.m
index adc830d..61ff136 100644
--- a/Example/Messaging/Tests/FIRMessagingTest.m
+++ b/Example/Messaging/Tests/FIRMessagingTest.m
@@ -75,6 +75,46 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption;
XCTAssertTrue(_messaging.isAutoInitEnabled);
}
+- (void)testAutoInitEnableFlagOverrideGlobalTrue {
+ OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES);
+ id bundleMock = OCMPartialMock([NSBundle mainBundle]);
+ OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil);
+ XCTAssertTrue(self.messaging.isAutoInitEnabled);
+
+ self.messaging.autoInitEnabled = NO;
+ XCTAssertFalse(self.messaging.isAutoInitEnabled);
+ [bundleMock stopMocking];
+}
+
+- (void)testAutoInitEnableFlagOverrideGlobalFalse {
+ OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES);
+ id bundleMock = OCMPartialMock([NSBundle mainBundle]);
+ OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil);
+ XCTAssertTrue(self.messaging.isAutoInitEnabled);
+
+ self.messaging.autoInitEnabled = NO;
+ XCTAssertFalse(self.messaging.isAutoInitEnabled);
+ [bundleMock stopMocking];
+}
+
+- (void)testAutoInitEnableGlobalDefaultTrue {
+ OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES);
+ id bundleMock = OCMPartialMock([NSBundle mainBundle]);
+ OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil);
+
+ XCTAssertTrue(self.messaging.isAutoInitEnabled);
+ [bundleMock stopMocking];
+}
+
+- (void)testAutoInitEnableGlobalDefaultFalse {
+ OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(NO);
+ id bundleMock = OCMPartialMock([NSBundle mainBundle]);
+ OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil);
+
+ XCTAssertFalse(self.messaging.isAutoInitEnabled);
+ [bundleMock stopMocking];
+}
+
#pragma mark - Direct Channel Establishment Testing
// Should connect with valid token and application in foreground