Skip to content
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

Wrap diagnostics notification in collection flag check. #1979

Merged
merged 3 commits into from Oct 23, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -690,8 +690,6 @@ - (void)testGlobalDataCollectionClearedAfterDelete {
}

- (void)testGlobalDataCollectionNoDiagnosticsSent {
[FIRApp configure];

// Add an observer for the diagnostics notification - both with and without an object to ensure it
// catches it either way. Currently no object is sent, but in the future that could change.
[self.notificationCenter addMockObserver:self.observerMock
@@ -707,6 +705,9 @@ - (void)testGlobalDataCollectionNoDiagnosticsSent {
OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
.andReturn(@NO);

// Ensure configure doesn't fire a notification.
[FIRApp configure];

NSError *error = [NSError errorWithDomain:@"com.firebase" code:42 userInfo:nil];
[[FIRApp defaultApp] sendLogsWithServiceName:@"Service" version:@"Version" error:error];

@@ -715,6 +716,28 @@ - (void)testGlobalDataCollectionNoDiagnosticsSent {
OCMVerifyAll(self.observerMock);
}

- (void)testGlobalDataCollectionNoDiagnosticsSentForNoOptions {
// Add an observer for the diagnostics notification - both with and without an object to ensure it
// catches it either way. Currently no object is sent, but in the future that could change.
[self.notificationCenter addMockObserver:self.observerMock
name:kFIRAppDiagnosticsNotification
object:nil];
[self.notificationCenter addMockObserver:self.observerMock
name:kFIRAppDiagnosticsNotification
object:OCMOCK_ANY];

This comment has been minimized.

Copy link
@paulb777

paulb777 Oct 22, 2018

Member

Does OCMOCK_ANY include nil?

This comment has been minimized.

Copy link
@ryanwilson

ryanwilson Oct 22, 2018

Author Member

Will test to see if that's the case!

This comment has been minimized.

Copy link
@ryanwilson

ryanwilson Oct 22, 2018

Author Member

Good call, it does include nil. I'll make sure we don't duplicate this elsewhere in a different PR (grabbed this from a different location).

This comment has been minimized.

Copy link
@ryanwilson

ryanwilson Oct 22, 2018

Author Member

Done.


OCMStub([self.appClassMock isDataCollectionDefaultEnabled]).andReturn(@NO);

// Ensure there is no FIROptions instance, and call configure which should throw an exception and
// attempt to log a diagnostics notification.
self.optionsInstanceMock = nil;
XCTAssertThrows([FIRApp configure]);

// The observer mock is strict and will raise an exception when an unexpected notification is
// received.
OCMVerifyAll(self.observerMock);
}

#pragma mark - Analytics Flag Tests

- (void)testAnalyticsSetByGlobalDataCollectionSwitch {
@@ -107,13 +107,19 @@ @implementation FIRApp
+ (void)configure {
FIROptions *options = [FIROptions defaultOptions];
if (!options) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsErrorKey : [FIRApp errorForMissingOptions]
}];
// Read the Info.plist to see if the flag is set. At this point we can't check any user defaults
// since the app isn't configured at all, so only rely on the Info.plist value.
NSNumber *collectionEnabledPlistValue = [[self class] readDataCollectionSwitchFromPlist];
if (!collectionEnabledPlistValue || [collectionEnabledPlistValue boolValue]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsErrorKey : [FIRApp errorForMissingOptions]
}];
}

[NSException raise:kFirebaseCoreErrorDomain
format:
@"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "
@@ -274,13 +280,15 @@ + (void)addAppToAppDictionary:(FIRApp *)app {
}
if ([app configureCore]) {
sAllApps[app.name] = app;
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsFIRAppKey : app
}];
if ([app isDataCollectionDefaultEnabled]) {

This comment has been minimized.

Copy link
@paulb777

paulb777 Oct 22, 2018

Member

It seems like this should only be done in configureCore - but that could be a separate refactor?

This comment has been minimized.

Copy link
@ryanwilson

ryanwilson Oct 22, 2018

Author Member

I'll try to refactor it now.

This comment has been minimized.

Copy link
@ryanwilson

ryanwilson Oct 22, 2018

Author Member

Done.

[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsFIRAppKey : app
}];
}
} else {
[NSException raise:kFirebaseCoreErrorDomain
format:
@@ -317,7 +325,7 @@ - (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback
- (BOOL)configureCore {
[self checkExpectedBundleID];
if (![self isAppIDValid]) {
if (_options.usingOptionsFromDefaultPlist) {
if (_options.usingOptionsFromDefaultPlist && [self isDataCollectionDefaultEnabled]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.