aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Chen Liang <chliang@google.com>2018-06-29 11:39:45 -0700
committerGravatar GitHub <noreply@github.com>2018-06-29 11:39:45 -0700
commit5e1472b49283e8c2374529ce89edb65ee0e8ea0b (patch)
tree571a2b4132f2e4c92a5081d4c7f6cb606d6296c5 /Example
parent7c34f464d8b1d530bba08a3adc5191112adb4ff1 (diff)
Fix the race condition of global data flag and fcm auto init enabled flag (#1466)
Diffstat (limited to 'Example')
-rw-r--r--Example/Messaging/Tests/FIRMessagingTest.m15
1 files changed, 11 insertions, 4 deletions
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 <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
+
+#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseInstanceID/FirebaseInstanceID.h>
#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);