From 1d65490f3fed5eefd101456f75991bf8d59cd00e Mon Sep 17 00:00:00 2001 From: chliangGoogle Date: Wed, 24 Jan 2018 14:50:48 -0800 Subject: [PATCH] add unit test for auto init function --- Example/Firebase.xcodeproj/project.pbxproj | 4 ++++ Example/Messaging/Tests/FIRMessagingTest.m | 14 ++++++++++++++ Example/Messaging/Tests/Host/AppDelegate.h | 7 +++++++ Example/Messaging/Tests/Host/AppDelegate.m | 14 ++++++++++++++ Example/Messaging/Tests/Host/main.m | 9 +++++++++ Example/Messaging/Tests/Info.plist | 2 ++ 6 files changed, 50 insertions(+) create mode 100644 Example/Messaging/Tests/Host/AppDelegate.h create mode 100644 Example/Messaging/Tests/Host/AppDelegate.m create mode 100644 Example/Messaging/Tests/Host/main.m diff --git a/Example/Firebase.xcodeproj/project.pbxproj b/Example/Firebase.xcodeproj/project.pbxproj index f34738f139d..0ce9dfe02dd 100644 --- a/Example/Firebase.xcodeproj/project.pbxproj +++ b/Example/Firebase.xcodeproj/project.pbxproj @@ -111,6 +111,7 @@ 2C8B39CFF9898AE4B29AD114 /* Pods_Auth_Tests_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1015568683E2DFCC2719C754 /* Pods_Auth_Tests_macOS.framework */; }; 2ECC6F80E47D2646FA82B940 /* Pods_Messaging_Tests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CCB3CEB7BF2E4994FBDB2E7 /* Pods_Messaging_Tests_iOS.framework */; }; 431EBDD6071EF1AE6F6DBE5F /* Pods_Core_Example_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84C51650773603D9F827CB3F /* Pods_Core_Example_macOS.framework */; }; + 519AF4702019445600EB8D64 /* Host in Resources */ = {isa = PBXBuildFile; fileRef = 519AF46F2019445500EB8D64 /* Host */; }; 5207C8D12B9830DADB85FE67 /* Pods_Auth_Tests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ABC4448E5917769098A4EEF /* Pods_Auth_Tests_iOS.framework */; }; 529BBEFBB6D7A3653B6B3874 /* Pods_Storage_Tests_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 910D7A5DE7D5AF153328D243 /* Pods_Storage_Tests_macOS.framework */; }; 6232ED3272E9C78C2A0E127F /* Pods_Storage_IntegrationTests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 979DF124E3D1146A81188F78 /* Pods_Storage_IntegrationTests_iOS.framework */; }; @@ -797,6 +798,7 @@ 4CC7C8B9E821151509BB3B64 /* Pods-Database_Example_macOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Database_Example_macOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Database_Example_macOS/Pods-Database_Example_macOS.release.xcconfig"; sourceTree = ""; }; 4D61AACC06F8E078EF051E4C /* Pods-Messaging_Example_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Messaging_Example_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Messaging_Example_iOS/Pods-Messaging_Example_iOS.debug.xcconfig"; sourceTree = ""; }; 4ECAA105379B7E664C7FF223 /* Pods-Storage_IntegrationTests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage_IntegrationTests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Storage_IntegrationTests_iOS/Pods-Storage_IntegrationTests_iOS.debug.xcconfig"; sourceTree = ""; }; + 519AF46F2019445500EB8D64 /* Host */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Host; sourceTree = ""; }; 5CA5A85B5A80F118F3247910 /* Pods-Storage_IntegrationTests_iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage_IntegrationTests_iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Storage_IntegrationTests_iOS/Pods-Storage_IntegrationTests_iOS.release.xcconfig"; sourceTree = ""; }; 5DA6361D6B54362D073F3BA5 /* Pods-Database_Example_iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Database_Example_iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Database_Example_iOS/Pods-Database_Example_iOS.release.xcconfig"; sourceTree = ""; }; 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -2002,6 +2004,7 @@ DE9315C21E8738B70083EDBF /* Tests */ = { isa = PBXGroup; children = ( + 519AF46F2019445500EB8D64 /* Host */, DE9315C81E8738B70083EDBF /* FIRMessagingFakeConnection.h */, DE9315CA1E8738B70083EDBF /* FIRMessagingFakeSocket.h */, DE9315D61E8738B70083EDBF /* FIRMessagingTestNotificationUtilities.h */, @@ -3015,6 +3018,7 @@ buildActionMask = 2147483647; files = ( DE93152B1E86C6FF0083EDBF /* GoogleService-Info.plist in Resources */, + 519AF4702019445600EB8D64 /* Host in Resources */, AFAF36F51EC28C25004BDEE5 /* Shared.xcassets in Resources */, DE9315261E86C6FF0083EDBF /* LaunchScreen.storyboard in Resources */, DE26D2131F70333E004AE1D3 /* Images.xcassets in Resources */, diff --git a/Example/Messaging/Tests/FIRMessagingTest.m b/Example/Messaging/Tests/FIRMessagingTest.m index 09cdffc353b..86ed6470ce9 100644 --- a/Example/Messaging/Tests/FIRMessagingTest.m +++ b/Example/Messaging/Tests/FIRMessagingTest.m @@ -20,6 +20,7 @@ #import "FIRMessaging.h" #import "FIRMessagingInstanceIDProxy.h" +#import "FIRMessaging_Private.h" extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption; @@ -28,6 +29,7 @@ @interface FIRMessaging () @property(nonatomic, readwrite, strong) NSString *defaultFcmToken; @property(nonatomic, readwrite, strong) NSData *apnsTokenData; @property(nonatomic, readwrite, strong) FIRMessagingInstanceIDProxy *instanceIDProxy; +@property(nonatomic, readwrite, strong) NSUserDefaults *messagingUserDefaults; - (instancetype)initPrivately; // Direct Channel Methods @@ -52,6 +54,9 @@ - (void)setUp { _mockMessaging = OCMPartialMock(self.messaging); _mockInstanceIDProxy = OCMPartialMock(self.messaging.instanceIDProxy); self.messaging.instanceIDProxy = _mockInstanceIDProxy; + [self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingSuiteName]; + self.messaging.messagingUserDefaults = + [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingSuiteName]; } - (void)tearDown { @@ -60,6 +65,15 @@ - (void)tearDown { [super tearDown]; } +- (void)testAutoInitEnableFlag { + // Should read from Info.plist + XCTAssertFalse(_messaging.isAutoInitEnabled); + + // Now set the flag should overwrite Info.plist value. + _messaging.autoInitEnabled = YES; + XCTAssertTrue(_messaging.isAutoInitEnabled); +} + #pragma mark - Direct Channel Establishment Testing // Should connect with valid token and application in foreground diff --git a/Example/Messaging/Tests/Host/AppDelegate.h b/Example/Messaging/Tests/Host/AppDelegate.h new file mode 100644 index 00000000000..77a44146b8f --- /dev/null +++ b/Example/Messaging/Tests/Host/AppDelegate.h @@ -0,0 +1,7 @@ +#import + +@interface AppDelegate : UIResponder + +@property(strong, nonatomic) UIWindow *window; + +@end diff --git a/Example/Messaging/Tests/Host/AppDelegate.m b/Example/Messaging/Tests/Host/AppDelegate.m new file mode 100644 index 00000000000..fecf055365c --- /dev/null +++ b/Example/Messaging/Tests/Host/AppDelegate.m @@ -0,0 +1,14 @@ +#import "third_party/firebase/ios/Source/FirebaseMessaging/Tests/Host/AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + return YES; +} + +@end diff --git a/Example/Messaging/Tests/Host/main.m b/Example/Messaging/Tests/Host/main.m new file mode 100644 index 00000000000..ccfa52cf0bc --- /dev/null +++ b/Example/Messaging/Tests/Host/main.m @@ -0,0 +1,9 @@ +#import + +#import "third_party/firebase/ios/Source/FirebaseMessaging/Tests/Host/AppDelegate.h" + +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/Example/Messaging/Tests/Info.plist b/Example/Messaging/Tests/Info.plist index ba72822e872..4df9372a691 100644 --- a/Example/Messaging/Tests/Info.plist +++ b/Example/Messaging/Tests/Info.plist @@ -20,5 +20,7 @@ ???? CFBundleVersion 1 + FirebaseMessagingAutoInitEnabled +