From 5e1472b49283e8c2374529ce89edb65ee0e8ea0b Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Fri, 29 Jun 2018 11:39:45 -0700 Subject: Fix the race condition of global data flag and fcm auto init enabled flag (#1466) --- Example/Messaging/Tests/FIRMessagingTest.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'Example/Messaging/Tests/FIRMessagingTest.m') diff --git a/Example/Messaging/Tests/FIRMessagingTest.m b/Example/Messaging/Tests/FIRMessagingTest.m index 61ff136..92cf0f5 100644 --- a/Example/Messaging/Tests/FIRMessagingTest.m +++ b/Example/Messaging/Tests/FIRMessagingTest.m @@ -17,6 +17,8 @@ #import #import + +#import #import #import "FIRMessaging.h" @@ -44,6 +46,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; @property(nonatomic, readonly, strong) FIRMessaging *messaging; @property(nonatomic, readwrite, strong) id mockMessaging; @property(nonatomic, readwrite, strong) id mockInstanceID; +@property(nonatomic, readwrite, strong) id mockFirebaseApp; @end @@ -51,6 +54,9 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; - (void)setUp { [super setUp]; + _mockFirebaseApp = OCMClassMock([FIRApp class]); + OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp); + _messaging = [[FIRMessaging alloc] initWithInstanceID:[FIRInstanceID instanceID] userDefaults:[NSUserDefaults standardUserDefaults]]; _mockMessaging = OCMPartialMock(self.messaging); @@ -63,6 +69,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; - (void)tearDown { [_mockMessaging stopMocking]; [_mockInstanceID stopMocking]; + [_mockFirebaseApp stopMocking]; [super tearDown]; } @@ -76,7 +83,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; } - (void)testAutoInitEnableFlagOverrideGlobalTrue { - OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES); + OCMStub([_mockFirebaseApp isAutomaticDataCollectionEnabled]).andReturn(YES); id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil); XCTAssertTrue(self.messaging.isAutoInitEnabled); @@ -87,7 +94,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; } - (void)testAutoInitEnableFlagOverrideGlobalFalse { - OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES); + OCMStub([_mockFirebaseApp isAutomaticDataCollectionEnabled]).andReturn(YES); id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil); XCTAssertTrue(self.messaging.isAutoInitEnabled); @@ -98,7 +105,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; } - (void)testAutoInitEnableGlobalDefaultTrue { - OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(YES); + OCMStub([_mockFirebaseApp isAutomaticDataCollectionEnabled]).andReturn(YES); id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil); @@ -107,7 +114,7 @@ extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; } - (void)testAutoInitEnableGlobalDefaultFalse { - OCMStub([self.mockMessaging isGlobalAutomaticDataCollectionEnabled]).andReturn(NO); + OCMStub([_mockFirebaseApp isAutomaticDataCollectionEnabled]).andReturn(NO); id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled]).andReturn(nil); -- cgit v1.2.3