1515#import " FIRTestCase.h"
1616#import " FIRTestComponents.h"
1717
18- #import < FirebaseCoreDiagnosticsInterop/FIRCoreDiagnosticsData.h>
19- #import < FirebaseCoreDiagnosticsInterop/FIRCoreDiagnosticsInterop.h>
20-
2118#import < FirebaseCore/FIRAnalyticsConfiguration.h>
2219#import < FirebaseCore/FIRAppInternal.h>
20+ #import < FirebaseCore/FIRCoreDiagnosticsConnector.h>
2321#import < FirebaseCore/FIROptionsInternal.h>
2422
2523NSString *const kFIRTestAppName1 = @" test_app_name_1" ;
@@ -53,6 +51,7 @@ @interface FIRAppTest : FIRTestCase
5351
5452@property (nonatomic ) id appClassMock;
5553@property (nonatomic ) id observerMock;
54+ @property (nonatomic ) id mockCoreDiagnosticsConnector;
5655@property (nonatomic ) NSNotificationCenter *notificationCenter;
5756
5857@end
@@ -65,6 +64,11 @@ - (void)setUp {
6564 [FIRApp resetApps ];
6665 _appClassMock = OCMClassMock ([FIRApp class ]);
6766 _observerMock = OCMObserverMock ();
67+ _mockCoreDiagnosticsConnector = OCMClassMock ([FIRCoreDiagnosticsConnector class ]);
68+
69+ OCMStub (ClassMethod ([self .mockCoreDiagnosticsConnector logCoreTelemetryWithOptions: [OCMArg any ]]))
70+ .andDo (^(NSInvocation *invocation){
71+ });
6872
6973 // TODO: Remove all usages of defaultCenter in Core, then we can instantiate an instance here to
7074 // inject instead of using defaultCenter.
@@ -76,6 +80,7 @@ - (void)tearDown {
7680 [_notificationCenter removeObserver: _observerMock];
7781 _observerMock = nil ;
7882 _notificationCenter = nil ;
83+ _mockCoreDiagnosticsConnector = nil ;
7984
8085 [super tearDown ];
8186}
@@ -730,6 +735,24 @@ - (void)testRegisteringNonConformingLibrary {
730735 XCTAssertFalse ([[FIRApp firebaseUserAgent ] containsString: @" InvalidLibrary`/1.0.0" ]);
731736}
732737
738+ #pragma mark - Core Diagnostics
739+
740+ - (void )testCoreDiagnosticsLoggedWhenFIRAppIsConfigured {
741+ [self expectCoreDiagnosticsDataLogWithOptions: [self appOptions ]];
742+ [self createConfiguredAppWithName: NSStringFromSelector (_cmd )];
743+ OCMVerifyAll (self.mockCoreDiagnosticsConnector );
744+ }
745+
746+ - (void )testCoreDiagnosticsLoggedWhenAppDidBecomeActive {
747+ FIRApp *app = [self createConfiguredAppWithName: NSStringFromSelector (_cmd )];
748+ [self expectCoreDiagnosticsDataLogWithOptions: app.options];
749+
750+ [self .notificationCenter postNotificationName: [self appDidBecomeActiveNotificationName ]
751+ object: nil ];
752+
753+ OCMVerifyAll (self.mockCoreDiagnosticsConnector );
754+ }
755+
733756#pragma mark - private
734757
735758- (void )expectNotificationForObserver : (id )observer
@@ -749,4 +772,39 @@ - (void)expectNotificationForObserver:(id)observer
749772 };
750773}
751774
775+ - (void )expectCoreDiagnosticsDataLogWithOptions : (nullable FIROptions *)expectedOptions {
776+ [self .mockCoreDiagnosticsConnector stopMocking ];
777+ self.mockCoreDiagnosticsConnector = nil ;
778+ self.mockCoreDiagnosticsConnector = OCMClassMock ([FIRCoreDiagnosticsConnector class ]);
779+
780+ OCMExpect (ClassMethod ([self .mockCoreDiagnosticsConnector
781+ logCoreTelemetryWithOptions: [OCMArg checkWithBlock: ^BOOL (FIROptions *options) {
782+ if (!expectedOptions) {
783+ return YES ;
784+ }
785+ return [options.googleAppID isEqualToString: expectedOptions.googleAppID] &&
786+ [options.GCMSenderID isEqualToString: expectedOptions.GCMSenderID];
787+ }]]));
788+ }
789+
790+ - (NSNotificationName )appDidBecomeActiveNotificationName {
791+ #if TARGET_OS_IOS || TARGET_OS_TV
792+ return UIApplicationDidBecomeActiveNotification;
793+ #endif
794+
795+ #if TARGET_OS_OSX
796+ return NSApplicationDidBecomeActiveNotification ;
797+ #endif
798+ }
799+
800+ - (FIRApp *)createConfiguredAppWithName : (NSString *)name {
801+ FIROptions *options = [self appOptions ];
802+ [FIRApp configureWithName: name options: options];
803+ return [FIRApp appNamed: name];
804+ }
805+
806+ - (FIROptions *)appOptions {
807+ return [[FIROptions alloc ] initWithGoogleAppID: kGoogleAppID GCMSenderID: kGCMSenderID ];
808+ }
809+
752810@end
0 commit comments