FIRAppTest.m 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. // Copyright 2017 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FIRTestCase.h"
  15. #import "FIRTestComponents.h"
  16. #import <FirebaseCore/FIRAnalyticsConfiguration.h>
  17. #import <FirebaseCore/FIRAppInternal.h>
  18. #import <FirebaseCore/FIRCoreDiagnosticsConnector.h>
  19. #import <FirebaseCore/FIROptionsInternal.h>
  20. #import <GoogleUtilities/GULAppEnvironmentUtil.h>
  21. NSString *const kFIRTestAppName1 = @"test_app_name_1";
  22. NSString *const kFIRTestAppName2 = @"test-app-name-2";
  23. @interface FIRApp (TestInternal)
  24. + (void)resetApps;
  25. - (instancetype)initInstanceWithName:(NSString *)name options:(FIROptions *)options;
  26. - (BOOL)configureCore;
  27. + (NSError *)errorForInvalidAppID;
  28. - (BOOL)isAppIDValid;
  29. + (NSString *)actualBundleID;
  30. + (NSNumber *)mapFromServiceStringToTypeEnum:(NSString *)serviceString;
  31. + (NSString *)deviceModel;
  32. + (NSString *)installString;
  33. + (NSURL *)filePathURLWithName:(NSString *)fileName;
  34. + (NSString *)stringAtURL:(NSURL *)filePathURL;
  35. + (BOOL)writeString:(NSString *)string toURL:(NSURL *)filePathURL;
  36. + (void)logAppInfo:(NSNotification *)notification;
  37. + (BOOL)validateAppID:(NSString *)appID;
  38. + (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version;
  39. + (BOOL)validateAppIDFingerprint:(NSString *)appID withVersion:(NSString *)version;
  40. + (nullable NSNumber *)readDataCollectionSwitchFromPlist;
  41. + (nullable NSNumber *)readDataCollectionSwitchFromUserDefaultsForApp:(FIRApp *)app;
  42. @end
  43. @interface FIRAppTest : FIRTestCase
  44. @property(nonatomic) id appClassMock;
  45. @property(nonatomic) id observerMock;
  46. @property(nonatomic) id mockCoreDiagnosticsConnector;
  47. @property(nonatomic) NSNotificationCenter *notificationCenter;
  48. @end
  49. @implementation FIRAppTest
  50. - (void)setUp {
  51. [super setUp];
  52. [FIROptions resetDefaultOptions];
  53. [FIRApp resetApps];
  54. _appClassMock = OCMClassMock([FIRApp class]);
  55. _observerMock = OCMObserverMock();
  56. _mockCoreDiagnosticsConnector = OCMClassMock([FIRCoreDiagnosticsConnector class]);
  57. OCMStub(ClassMethod([self.mockCoreDiagnosticsConnector logCoreTelemetryWithOptions:[OCMArg any]]))
  58. .andDo(^(NSInvocation *invocation){
  59. });
  60. // TODO: Remove all usages of defaultCenter in Core, then we can instantiate an instance here to
  61. // inject instead of using defaultCenter.
  62. _notificationCenter = [NSNotificationCenter defaultCenter];
  63. }
  64. - (void)tearDown {
  65. [_appClassMock stopMocking];
  66. [_notificationCenter removeObserver:_observerMock];
  67. _observerMock = nil;
  68. _notificationCenter = nil;
  69. _mockCoreDiagnosticsConnector = nil;
  70. [super tearDown];
  71. }
  72. - (void)testConfigure {
  73. NSDictionary *expectedUserInfo = [self expectedUserInfoWithAppName:kFIRDefaultAppName
  74. isDefaultApp:YES];
  75. [self expectNotificationForObserver:self.observerMock
  76. notificationName:kFIRAppReadyToConfigureSDKNotification
  77. object:[FIRApp class]
  78. userInfo:expectedUserInfo];
  79. XCTAssertNoThrow([FIRApp configure]);
  80. OCMVerifyAll(self.observerMock);
  81. FIRApp *app = [FIRApp defaultApp];
  82. XCTAssertNotNil(app);
  83. XCTAssertEqualObjects(app.name, kFIRDefaultAppName);
  84. XCTAssertEqualObjects(app.options.clientID, kClientID);
  85. XCTAssertTrue([FIRApp allApps].count == 1);
  86. }
  87. - (void)testConfigureWithNoDefaultOptions {
  88. id optionsClassMock = OCMClassMock([FIROptions class]);
  89. OCMStub([optionsClassMock defaultOptions]).andReturn(nil);
  90. XCTAssertThrows([FIRApp configure]);
  91. }
  92. - (void)testConfigureWithOptions {
  93. #pragma clang diagnostic push
  94. #pragma clang diagnostic ignored "-Wnonnull"
  95. // Test `nil` options.
  96. XCTAssertThrows([FIRApp configureWithOptions:nil]);
  97. #pragma clang diagnostic pop
  98. XCTAssertTrue([FIRApp allApps].count == 0);
  99. NSDictionary *expectedUserInfo = [self expectedUserInfoWithAppName:kFIRDefaultAppName
  100. isDefaultApp:YES];
  101. [self expectNotificationForObserver:self.observerMock
  102. notificationName:kFIRAppReadyToConfigureSDKNotification
  103. object:[FIRApp class]
  104. userInfo:expectedUserInfo];
  105. // Use a valid instance of options.
  106. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  107. GCMSenderID:kGCMSenderID];
  108. options.clientID = kClientID;
  109. XCTAssertNoThrow([FIRApp configureWithOptions:options]);
  110. OCMVerifyAll(self.observerMock);
  111. // Verify the default app instance is created.
  112. FIRApp *app = [FIRApp defaultApp];
  113. XCTAssertNotNil(app);
  114. XCTAssertEqualObjects(app.name, kFIRDefaultAppName);
  115. XCTAssertEqualObjects(app.options.googleAppID, kGoogleAppID);
  116. XCTAssertEqualObjects(app.options.GCMSenderID, kGCMSenderID);
  117. XCTAssertEqualObjects(app.options.clientID, kClientID);
  118. XCTAssertTrue([FIRApp allApps].count == 1);
  119. }
  120. - (void)testConfigureWithNameAndOptions {
  121. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  122. GCMSenderID:kGCMSenderID];
  123. options.clientID = kClientID;
  124. #pragma clang diagnostic push
  125. #pragma clang diagnostic ignored "-Wnonnull"
  126. XCTAssertThrows([FIRApp configureWithName:nil options:options]);
  127. XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:nil]);
  128. #pragma clang diagnostic pop
  129. XCTAssertThrows([FIRApp configureWithName:@"" options:options]);
  130. XCTAssertTrue([FIRApp allApps].count == 0);
  131. NSDictionary *expectedUserInfo = [self expectedUserInfoWithAppName:kFIRTestAppName1
  132. isDefaultApp:NO];
  133. [self expectNotificationForObserver:self.observerMock
  134. notificationName:kFIRAppReadyToConfigureSDKNotification
  135. object:[FIRApp class]
  136. userInfo:expectedUserInfo];
  137. XCTAssertNoThrow([FIRApp configureWithName:kFIRTestAppName1 options:options]);
  138. OCMVerifyAll(self.observerMock);
  139. XCTAssertTrue([FIRApp allApps].count == 1);
  140. FIRApp *app = [FIRApp appNamed:kFIRTestAppName1];
  141. XCTAssertNotNil(app);
  142. XCTAssertEqualObjects(app.name, kFIRTestAppName1);
  143. XCTAssertEqualObjects(app.options.clientID, kClientID);
  144. // Configure the same app again should throw an exception.
  145. XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:options]);
  146. }
  147. - (void)testConfigureWithMultipleApps {
  148. FIROptions *options1 = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  149. GCMSenderID:kGCMSenderID];
  150. options1.deepLinkURLScheme = kDeepLinkURLScheme;
  151. // Set up notification center observer for verifying notifications.
  152. [self.notificationCenter addMockObserver:self.observerMock
  153. name:kFIRAppReadyToConfigureSDKNotification
  154. object:[FIRApp class]];
  155. NSDictionary *expectedUserInfo1 = [self expectedUserInfoWithAppName:kFIRTestAppName1
  156. isDefaultApp:NO];
  157. [[self.observerMock expect] notificationWithName:kFIRAppReadyToConfigureSDKNotification
  158. object:[FIRApp class]
  159. userInfo:expectedUserInfo1];
  160. XCTAssertNoThrow([FIRApp configureWithName:kFIRTestAppName1 options:options1]);
  161. XCTAssertTrue([FIRApp allApps].count == 1);
  162. // Configure a different app with valid customized options.
  163. FIROptions *options2 = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  164. GCMSenderID:kGCMSenderID];
  165. options2.bundleID = kBundleID;
  166. options2.APIKey = kCustomizedAPIKey;
  167. NSDictionary *expectedUserInfo2 = [self expectedUserInfoWithAppName:kFIRTestAppName2
  168. isDefaultApp:NO];
  169. [[self.observerMock expect] notificationWithName:kFIRAppReadyToConfigureSDKNotification
  170. object:[FIRApp class]
  171. userInfo:expectedUserInfo2];
  172. [self.observerMock setExpectationOrderMatters:YES];
  173. XCTAssertNoThrow([FIRApp configureWithName:kFIRTestAppName2 options:options2]);
  174. OCMVerifyAll(self.observerMock);
  175. XCTAssertTrue([FIRApp allApps].count == 2);
  176. FIRApp *app = [FIRApp appNamed:kFIRTestAppName2];
  177. XCTAssertNotNil(app);
  178. XCTAssertEqualObjects(app.name, kFIRTestAppName2);
  179. XCTAssertEqualObjects(app.options.googleAppID, kGoogleAppID);
  180. XCTAssertEqualObjects(app.options.APIKey, kCustomizedAPIKey);
  181. }
  182. - (void)testConfigureThrowsAfterConfigured {
  183. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  184. GCMSenderID:kGCMSenderID];
  185. [FIRApp configureWithOptions:options];
  186. XCTAssertNotNil([FIRApp defaultApp]);
  187. // A second configure call should throw, since Firebase is already configured.
  188. XCTAssertThrows([FIRApp configureWithOptions:options]);
  189. // Test the same with a custom named app.
  190. [FIRApp configureWithName:kFIRTestAppName1 options:options];
  191. XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]);
  192. // A second configure call should throw, since Firebase is already configured.
  193. XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:options]);
  194. }
  195. - (void)testConfigureDefaultAppInExtension {
  196. id environmentMock = OCMClassMock([GULAppEnvironmentUtil class]);
  197. OCMStub([environmentMock isAppExtension]).andReturn(YES);
  198. // Set up the default app like a standard app.
  199. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  200. GCMSenderID:kGCMSenderID];
  201. [FIRApp configureWithOptions:options];
  202. XCTAssertNotNil([FIRApp defaultApp]);
  203. XCTAssertEqual([FIRApp allApps].count, 1);
  204. // Configuring with the same set of options shouldn't throw.
  205. XCTAssertNoThrow([FIRApp configureWithOptions:options]);
  206. // Only 1 app should have been configured still, the default app.
  207. XCTAssertNotNil([FIRApp defaultApp]);
  208. XCTAssertEqual([FIRApp allApps].count, 1);
  209. // Use a set of a different options to call configure again, which should throw.
  210. FIROptions *differentOptions = [[FIROptions alloc] initWithGoogleAppID:@"1:789:ios:789XYZ"
  211. GCMSenderID:kGCMSenderID];
  212. XCTAssertThrows([FIRApp configureWithOptions:differentOptions]);
  213. XCTAssertEqual([FIRApp allApps].count, 1);
  214. // Explicily stop the environmentMock.
  215. [environmentMock stopMocking];
  216. environmentMock = nil;
  217. }
  218. - (void)testConfigureCustomAppInExtension {
  219. id environmentMock = OCMClassMock([GULAppEnvironmentUtil class]);
  220. OCMStub([environmentMock isAppExtension]).andReturn(YES);
  221. // Set up a custom named app like a standard app.
  222. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  223. GCMSenderID:kGCMSenderID];
  224. [FIRApp configureWithName:kFIRTestAppName1 options:options];
  225. XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]);
  226. XCTAssertEqual([FIRApp allApps].count, 1);
  227. // Configuring with the same set of options shouldn't throw.
  228. XCTAssertNoThrow([FIRApp configureWithName:kFIRTestAppName1 options:options]);
  229. // Only 1 app should have been configured still.
  230. XCTAssertNotNil([FIRApp appNamed:kFIRTestAppName1]);
  231. XCTAssertEqual([FIRApp allApps].count, 1);
  232. // Use a set of a different options to call configure again, which should throw.
  233. FIROptions *differentOptions = [[FIROptions alloc] initWithGoogleAppID:@"1:789:ios:789XYZ"
  234. GCMSenderID:kGCMSenderID];
  235. XCTAssertThrows([FIRApp configureWithName:kFIRTestAppName1 options:differentOptions]);
  236. XCTAssertEqual([FIRApp allApps].count, 1);
  237. // Explicily stop the environmentMock.
  238. [environmentMock stopMocking];
  239. environmentMock = nil;
  240. }
  241. - (void)testValidName {
  242. XCTAssertNoThrow([FIRApp configureWithName:@"aA1_" options:[FIROptions defaultOptions]]);
  243. XCTAssertNoThrow([FIRApp configureWithName:@"aA1-" options:[FIROptions defaultOptions]]);
  244. XCTAssertNoThrow([FIRApp configureWithName:@"aAē1_" options:[FIROptions defaultOptions]]);
  245. XCTAssertThrows([FIRApp configureWithName:@"aA1%" options:[FIROptions defaultOptions]]);
  246. XCTAssertThrows([FIRApp configureWithName:@"aA1?" options:[FIROptions defaultOptions]]);
  247. XCTAssertThrows([FIRApp configureWithName:@"aA1!" options:[FIROptions defaultOptions]]);
  248. }
  249. - (void)testDefaultApp {
  250. FIRApp *app = [FIRApp defaultApp];
  251. XCTAssertNil(app);
  252. [FIRApp configure];
  253. app = [FIRApp defaultApp];
  254. XCTAssertEqualObjects(app.name, kFIRDefaultAppName);
  255. XCTAssertEqualObjects(app.options.clientID, kClientID);
  256. }
  257. - (void)testAppNamed {
  258. FIRApp *app = [FIRApp appNamed:kFIRTestAppName1];
  259. XCTAssertNil(app);
  260. [FIRApp configureWithName:kFIRTestAppName1 options:[FIROptions defaultOptions]];
  261. app = [FIRApp appNamed:kFIRTestAppName1];
  262. XCTAssertEqualObjects(app.name, kFIRTestAppName1);
  263. XCTAssertEqualObjects(app.options.clientID, kClientID);
  264. }
  265. - (void)testDeleteApp {
  266. NSString *name = NSStringFromSelector(_cmd);
  267. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  268. GCMSenderID:kGCMSenderID];
  269. [FIRApp configureWithName:name options:options];
  270. FIRApp *app = [FIRApp appNamed:name];
  271. XCTAssertNotNil(app);
  272. XCTAssertTrue([FIRApp allApps].count == 1);
  273. [self expectNotificationForObserver:self.observerMock
  274. notificationName:kFIRAppDeleteNotification
  275. object:[FIRApp class]
  276. userInfo:[OCMArg any]];
  277. XCTestExpectation *expectation =
  278. [self expectationWithDescription:@"Deleting the app should succeed."];
  279. [app deleteApp:^(BOOL success) {
  280. XCTAssertTrue(success);
  281. [expectation fulfill];
  282. }];
  283. [self waitForExpectations:@[ expectation ] timeout:1];
  284. OCMVerifyAll(self.observerMock);
  285. XCTAssertTrue([FIRApp allApps].count == 0);
  286. }
  287. - (void)testErrorForSubspecConfigurationFailure {
  288. NSError *error = [FIRApp errorForSubspecConfigurationFailureWithDomain:kFirebaseCoreErrorDomain
  289. errorCode:-38
  290. service:@"Auth"
  291. reason:@"some reason"];
  292. XCTAssertNotNil(error);
  293. XCTAssert([error.domain isEqualToString:kFirebaseCoreErrorDomain]);
  294. XCTAssert(error.code == -38);
  295. XCTAssert([error.description containsString:@"Configuration failed for"]);
  296. }
  297. - (void)testOptionsLocking {
  298. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  299. GCMSenderID:kGCMSenderID];
  300. options.projectID = kProjectID;
  301. options.databaseURL = kDatabaseURL;
  302. // Options should not be locked before they are used to configure a `FIRApp`.
  303. XCTAssertFalse(options.isEditingLocked);
  304. // The options returned should be locked after configuring `FIRApp`.
  305. NSString *name = NSStringFromSelector(_cmd);
  306. [FIRApp configureWithName:name options:options];
  307. FIROptions *optionsCopy = [[FIRApp appNamed:name] options];
  308. XCTAssertTrue(optionsCopy.isEditingLocked);
  309. }
  310. #pragma mark - App ID v1
  311. - (void)testAppIDV1 {
  312. // Missing separator between platform:fingerprint.
  313. XCTAssertFalse([FIRApp validateAppID:@"1:1337:iosdeadbeef"]);
  314. // Wrong platform "android".
  315. XCTAssertFalse([FIRApp validateAppID:@"1:1337:android:deadbeef"]);
  316. // The fingerprint, aka 4th field, should only contain hex characters.
  317. XCTAssertFalse([FIRApp validateAppID:@"1:1337:ios:123abcxyz"]);
  318. // The fingerprint, aka 4th field, is not tested in V1, so a bad value shouldn't cause a failure.
  319. XCTAssertTrue([FIRApp validateAppID:@"1:1337:ios:deadbeef"]);
  320. }
  321. #pragma mark - App ID v2
  322. - (void)testAppIDV2 {
  323. // Missing separator between platform:fingerprint.
  324. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios5e18052ab54fbfec"]);
  325. // Unknown versions may contain anything.
  326. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:123abcxyz"]);
  327. XCTAssertTrue([FIRApp validateAppID:@"2:thisdoesn'teven_m:a:t:t:e:r_"]);
  328. // Known good fingerprint.
  329. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:5e18052ab54fbfec"]);
  330. // Unknown fingerprint, not tested so shouldn't cause a failure.
  331. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:deadbeef"]);
  332. }
  333. #pragma mark - App ID other
  334. - (void)testAppIDV3 {
  335. // Currently there is no specification for v3, so we would not expect it to fail.
  336. XCTAssertTrue([FIRApp validateAppID:@"3:1337:ios:deadbeef"]);
  337. }
  338. - (void)testAppIDEmpty {
  339. XCTAssertFalse([FIRApp validateAppID:@""]);
  340. }
  341. - (void)testAppIDValidationTrue {
  342. // Ensure that isAppIDValid matches validateAppID.
  343. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"" GCMSenderID:@""];
  344. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  345. OCMStub([self.appClassMock validateAppID:[OCMArg any]]).andReturn(YES);
  346. XCTAssertTrue([app isAppIDValid]);
  347. }
  348. - (void)testAppIDValidationFalse {
  349. // Ensure that isAppIDValid matches validateAppID.
  350. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"" GCMSenderID:@""];
  351. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  352. OCMStub([self.appClassMock validateAppID:[OCMArg any]]).andReturn(NO);
  353. XCTAssertFalse([app isAppIDValid]);
  354. }
  355. - (void)testAppIDPrefix {
  356. // Unknown numeric-character prefixes should pass.
  357. XCTAssertTrue([FIRApp validateAppID:@"0:"]);
  358. XCTAssertTrue([FIRApp validateAppID:@"01:"]);
  359. XCTAssertTrue([FIRApp validateAppID:@"10:"]);
  360. XCTAssertTrue([FIRApp validateAppID:@"010:"]);
  361. XCTAssertTrue([FIRApp validateAppID:@"3:"]);
  362. XCTAssertTrue([FIRApp validateAppID:@"123:"]);
  363. XCTAssertTrue([FIRApp validateAppID:@"999999999:"]);
  364. // Non-numeric prefixes should not pass.
  365. XCTAssertFalse([FIRApp validateAppID:@"a:"]);
  366. XCTAssertFalse([FIRApp validateAppID:@"abcsdf0:"]);
  367. XCTAssertFalse([FIRApp validateAppID:@"0aaaa:"]);
  368. XCTAssertFalse([FIRApp validateAppID:@"0aaaa0450:"]);
  369. XCTAssertFalse([FIRApp validateAppID:@"-1:"]);
  370. XCTAssertFalse([FIRApp validateAppID:@"abcsdf:"]);
  371. XCTAssertFalse([FIRApp validateAppID:@"ABDCF:"]);
  372. XCTAssertFalse([FIRApp validateAppID:@" :"]);
  373. XCTAssertFalse([FIRApp validateAppID:@"1 :"]);
  374. XCTAssertFalse([FIRApp validateAppID:@" 1:"]);
  375. XCTAssertFalse([FIRApp validateAppID:@" 123 :"]);
  376. XCTAssertFalse([FIRApp validateAppID:@"1 23:"]);
  377. XCTAssertFalse([FIRApp validateAppID:@"&($*&%(*$&:"]);
  378. XCTAssertFalse([FIRApp validateAppID:@"abCDSF$%%df:"]);
  379. // Known version prefixes should never pass without the rest of the app ID string present.
  380. XCTAssertFalse([FIRApp validateAppID:@"1:"]);
  381. // Version must include ":".
  382. XCTAssertFalse([FIRApp validateAppID:@"0"]);
  383. XCTAssertFalse([FIRApp validateAppID:@"01"]);
  384. XCTAssertFalse([FIRApp validateAppID:@"10"]);
  385. XCTAssertFalse([FIRApp validateAppID:@"010"]);
  386. XCTAssertFalse([FIRApp validateAppID:@"3"]);
  387. XCTAssertFalse([FIRApp validateAppID:@"123"]);
  388. XCTAssertFalse([FIRApp validateAppID:@"999999999"]);
  389. XCTAssertFalse([FIRApp validateAppID:@"com.google.bundleID"]);
  390. }
  391. - (void)testAppIDFormatInvalid {
  392. OCMStub([self.appClassMock actualBundleID]).andReturn(@"com.google.bundleID");
  393. // Some direct tests of the validateAppIDFormat:withVersion: method.
  394. // Sanity checks first.
  395. NSString *const kGoodAppIDV1 = @"1:1337:ios:deadbeef";
  396. NSString *const kGoodVersionV1 = @"1";
  397. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodVersionV1]);
  398. NSString *const kGoodAppIDV2 = @"2:1337:ios:5e18052ab54fbfec";
  399. NSString *const kGoodVersionV2 = @"2";
  400. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV2]);
  401. // Version mismatch.
  402. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV1]);
  403. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodVersionV2]);
  404. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:@"999:"]);
  405. // Nil or empty strings.
  406. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:nil]);
  407. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:@""]);
  408. XCTAssertFalse([FIRApp validateAppIDFormat:nil withVersion:kGoodVersionV1]);
  409. XCTAssertFalse([FIRApp validateAppIDFormat:@"" withVersion:kGoodVersionV1]);
  410. XCTAssertFalse([FIRApp validateAppIDFormat:nil withVersion:nil]);
  411. XCTAssertFalse([FIRApp validateAppIDFormat:@"" withVersion:@""]);
  412. // App ID contains only the version prefix.
  413. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodVersionV1 withVersion:kGoodVersionV1]);
  414. // The version is the entire app ID.
  415. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodAppIDV1]);
  416. // Versions digits that may make a partial match.
  417. XCTAssertFalse([FIRApp validateAppIDFormat:@"01:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  418. XCTAssertFalse([FIRApp validateAppIDFormat:@"10:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  419. XCTAssertFalse([FIRApp validateAppIDFormat:@"11:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  420. XCTAssertFalse([FIRApp validateAppIDFormat:@"21:1337:ios:5e18052ab54fbfec"
  421. withVersion:kGoodVersionV2]);
  422. XCTAssertFalse([FIRApp validateAppIDFormat:@"22:1337:ios:5e18052ab54fbfec"
  423. withVersion:kGoodVersionV2]);
  424. XCTAssertFalse([FIRApp validateAppIDFormat:@"02:1337:ios:5e18052ab54fbfec"
  425. withVersion:kGoodVersionV2]);
  426. XCTAssertFalse([FIRApp validateAppIDFormat:@"20:1337:ios:5e18052ab54fbfec"
  427. withVersion:kGoodVersionV2]);
  428. // Extra fields.
  429. XCTAssertFalse([FIRApp validateAppIDFormat:@"ab:1:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  430. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:ab:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  431. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ab:ios:deadbeef" withVersion:kGoodVersionV1]);
  432. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ios:ab:deadbeef" withVersion:kGoodVersionV1]);
  433. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ios:deadbeef:ab" withVersion:kGoodVersionV1]);
  434. }
  435. - (void)testAppIDFingerprintInvalid {
  436. OCMStub([self.appClassMock actualBundleID]).andReturn(@"com.google.bundleID");
  437. // Some direct tests of the validateAppIDFingerprint:withVersion: method.
  438. // Sanity checks first.
  439. NSString *const kGoodAppIDV1 = @"1:1337:ios:deadbeef";
  440. NSString *const kGoodVersionV1 = @"1";
  441. XCTAssertTrue([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:kGoodVersionV1]);
  442. NSString *const kGoodAppIDV2 = @"2:1337:ios:5e18052ab54fbfec";
  443. NSString *const kGoodVersionV2 = @"2";
  444. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV2]);
  445. // Nil or empty strings.
  446. XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:nil]);
  447. XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:@""]);
  448. XCTAssertFalse([FIRApp validateAppIDFingerprint:nil withVersion:kGoodVersionV1]);
  449. XCTAssertFalse([FIRApp validateAppIDFingerprint:@"" withVersion:kGoodVersionV1]);
  450. XCTAssertFalse([FIRApp validateAppIDFingerprint:nil withVersion:nil]);
  451. XCTAssertFalse([FIRApp validateAppIDFingerprint:@"" withVersion:@""]);
  452. // App ID contains only the version prefix.
  453. XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodVersionV1 withVersion:kGoodVersionV1]);
  454. // The version is the entire app ID.
  455. XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:kGoodAppIDV1]);
  456. }
  457. // Uncomment if you need to measure performance of [FIRApp validateAppID:].
  458. // It is commented because measures are heavily dependent on a build agent configuration,
  459. // so it cannot produce reliable resault on CI
  460. //- (void)testAppIDFingerprintPerfomance {
  461. // [self measureBlock:^{
  462. // for (NSInteger i = 0; i < 100; ++i) {
  463. // [self testAppIDPrefix];
  464. // }
  465. // }];
  466. //}
  467. #pragma mark - Automatic Data Collection Tests
  468. - (void)testGlobalDataCollectionNoFlags {
  469. // Test: No flags set.
  470. NSString *name = NSStringFromSelector(_cmd);
  471. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  472. GCMSenderID:kGCMSenderID];
  473. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  474. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  475. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  476. .andReturn(nil);
  477. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  478. }
  479. - (void)testGlobalDataCollectionPlistSetEnabled {
  480. // Test: Plist set to enabled, no override.
  481. NSString *name = NSStringFromSelector(_cmd);
  482. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  483. GCMSenderID:kGCMSenderID];
  484. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  485. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
  486. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  487. .andReturn(nil);
  488. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  489. }
  490. - (void)testGlobalDataCollectionPlistSetDisabled {
  491. // Test: Plist set to disabled, no override.
  492. NSString *name = NSStringFromSelector(_cmd);
  493. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  494. GCMSenderID:kGCMSenderID];
  495. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  496. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
  497. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  498. .andReturn(nil);
  499. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  500. }
  501. - (void)testGlobalDataCollectionUserSpecifiedEnabled {
  502. // Test: User specified as enabled, no plist value.
  503. NSString *name = NSStringFromSelector(_cmd);
  504. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  505. GCMSenderID:kGCMSenderID];
  506. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  507. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  508. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  509. .andReturn(@YES);
  510. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  511. }
  512. - (void)testGlobalDataCollectionUserSpecifiedDisabled {
  513. // Test: User specified as disabled, no plist value.
  514. NSString *name = NSStringFromSelector(_cmd);
  515. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  516. GCMSenderID:kGCMSenderID];
  517. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  518. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  519. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  520. .andReturn(@NO);
  521. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  522. }
  523. - (void)testGlobalDataCollectionUserOverriddenEnabled {
  524. // Test: User specified as enabled, with plist set as disabled.
  525. NSString *name = NSStringFromSelector(_cmd);
  526. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  527. GCMSenderID:kGCMSenderID];
  528. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  529. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
  530. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  531. .andReturn(@YES);
  532. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  533. }
  534. - (void)testGlobalDataCollectionUserOverriddenDisabled {
  535. // Test: User specified as disabled, with plist set as enabled.
  536. NSString *name = NSStringFromSelector(_cmd);
  537. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  538. GCMSenderID:kGCMSenderID];
  539. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  540. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
  541. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  542. .andReturn(@NO);
  543. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  544. }
  545. - (void)testGlobalDataCollectionWriteToDefaults {
  546. id defaultsMock = OCMPartialMock([NSUserDefaults standardUserDefaults]);
  547. NSString *name = NSStringFromSelector(_cmd);
  548. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  549. GCMSenderID:kGCMSenderID];
  550. [FIRApp configureWithName:name options:options];
  551. FIRApp *app = [FIRApp appNamed:name];
  552. app.dataCollectionDefaultEnabled = YES;
  553. NSString *key =
  554. [NSString stringWithFormat:kFIRGlobalAppDataCollectionEnabledDefaultsKeyFormat, app.name];
  555. OCMVerify([defaultsMock setObject:@YES forKey:key]);
  556. app.dataCollectionDefaultEnabled = NO;
  557. OCMVerify([defaultsMock setObject:@NO forKey:key]);
  558. [defaultsMock stopMocking];
  559. }
  560. - (void)testGlobalDataCollectionClearedAfterDelete {
  561. // Configure and disable data collection for the default FIRApp.
  562. NSString *name = NSStringFromSelector(_cmd);
  563. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  564. GCMSenderID:kGCMSenderID];
  565. [FIRApp configureWithName:name options:options];
  566. FIRApp *app = [FIRApp appNamed:name];
  567. app.dataCollectionDefaultEnabled = NO;
  568. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  569. // Delete the app, and verify that the switch was reset.
  570. XCTestExpectation *deleteFinished =
  571. [self expectationWithDescription:@"The app should successfully delete."];
  572. [app deleteApp:^(BOOL success) {
  573. XCTAssertTrue(success);
  574. [deleteFinished fulfill];
  575. }];
  576. // Wait for the delete to complete.
  577. [self waitForExpectations:@[ deleteFinished ] timeout:1];
  578. // Set up an app with the same name again, and check the data collection flag.
  579. [FIRApp configureWithName:name options:options];
  580. XCTAssertTrue([FIRApp appNamed:name].isDataCollectionDefaultEnabled);
  581. }
  582. - (void)testGlobalDataCollectionNoDiagnosticsSent {
  583. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  584. GCMSenderID:kGCMSenderID];
  585. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  586. app.dataCollectionDefaultEnabled = NO;
  587. // Add an observer for the diagnostics notification. Currently no object is sent, but in the
  588. // future that could change so leave it as OCMOCK_ANY.
  589. [self.notificationCenter addMockObserver:self.observerMock
  590. name:kFIRAppDiagnosticsNotification
  591. object:OCMOCK_ANY];
  592. // Stub out reading from user defaults since stubbing out the BOOL has issues. If the data
  593. // collection switch is disabled, the `sendLogs` call should return immediately and not fire a
  594. // notification.
  595. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  596. .andReturn(@NO);
  597. // Ensure configure doesn't fire a notification.
  598. [FIRApp configure];
  599. // The observer mock is strict and will raise an exception when an unexpected notification is
  600. // received.
  601. OCMVerifyAll(self.observerMock);
  602. }
  603. #pragma mark - Analytics Flag Tests
  604. - (void)testAnalyticsSetByGlobalDataCollectionSwitch {
  605. // Test that the global data collection switch triggers setting Analytics when no explicit flag is
  606. // set.
  607. id optionsMock = OCMClassMock([FIROptions class]);
  608. OCMStub([optionsMock isAnalyticsCollectionExplicitlySet]).andReturn(NO);
  609. // We need to use the default app name since Analytics only associates with the default app.
  610. FIRApp *defaultApp = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:optionsMock];
  611. id configurationMock = OCMClassMock([FIRAnalyticsConfiguration class]);
  612. OCMStub([configurationMock sharedInstance]).andReturn(configurationMock);
  613. // Ensure Analytics is set after the global flag is set. It needs to
  614. [defaultApp setDataCollectionDefaultEnabled:YES];
  615. OCMVerify([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:NO]);
  616. [defaultApp setDataCollectionDefaultEnabled:NO];
  617. OCMVerify([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:NO]);
  618. }
  619. - (void)testAnalyticsNotSetByGlobalDataCollectionSwitch {
  620. // Test that the global data collection switch doesn't override an explicitly set Analytics flag.
  621. id optionsMock = OCMClassMock([FIROptions class]);
  622. OCMStub([optionsMock isAnalyticsCollectionExplicitlySet]).andReturn(YES);
  623. FIRApp *app = [[FIRApp alloc] initInstanceWithName:@"testAnalyticsNotSet" options:optionsMock];
  624. id configurationMock = OCMClassMock([FIRAnalyticsConfiguration class]);
  625. OCMStub([configurationMock sharedInstance]).andReturn(configurationMock);
  626. // Reject any changes to Analytics when the data collection changes.
  627. OCMReject([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:YES]);
  628. OCMReject([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:NO]);
  629. [app setDataCollectionDefaultEnabled:YES];
  630. OCMReject([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:YES]);
  631. OCMReject([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:NO]);
  632. [app setDataCollectionDefaultEnabled:NO];
  633. }
  634. #pragma mark - Internal Methods
  635. - (void)testIsDefaultAppConfigured {
  636. // Ensure it's false before anything is configured.
  637. XCTAssertFalse([FIRApp isDefaultAppConfigured]);
  638. // Configure it and ensure it's configured.
  639. [FIRApp configure];
  640. XCTAssertTrue([FIRApp isDefaultAppConfigured]);
  641. // Reset the apps and ensure it's not configured anymore.
  642. [FIRApp resetApps];
  643. XCTAssertFalse([FIRApp isDefaultAppConfigured]);
  644. }
  645. - (void)testInvalidLibraryName {
  646. [FIRApp registerLibrary:@"Oops>" withVersion:@"1.0.0"];
  647. XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"Oops"]);
  648. }
  649. - (void)testInvalidLibraryVersion {
  650. NSString *originalFirebaseUserAgent = [FIRApp firebaseUserAgent];
  651. [FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0+"];
  652. XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:originalFirebaseUserAgent]);
  653. }
  654. - (void)testSingleLibrary {
  655. [FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0"];
  656. XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0"]);
  657. }
  658. - (void)testMultipleLibraries {
  659. [FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0"];
  660. [FIRApp registerLibrary:@"ValidName2" withVersion:@"2.0.0"];
  661. XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0 ValidName2/2.0.0"]);
  662. }
  663. - (void)testRegisteringConformingLibrary {
  664. Class testClass = [FIRTestClass class];
  665. [FIRApp registerInternalLibrary:testClass withName:@"ValidName" withVersion:@"1.0.0"];
  666. XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0"]);
  667. }
  668. - (void)testRegisteringNonConformingLibrary {
  669. XCTAssertThrows([FIRApp registerInternalLibrary:[NSString class]
  670. withName:@"InvalidLibrary"
  671. withVersion:@"1.0.0"]);
  672. XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"InvalidLibrary`/1.0.0"]);
  673. }
  674. - (void)testSwiftFlagWithNoSwift {
  675. XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"swift/false"]);
  676. }
  677. #pragma mark - Core Diagnostics
  678. - (void)testCoreDiagnosticsLoggedWhenFIRAppIsConfigured {
  679. [self expectCoreDiagnosticsDataLogWithOptions:[self appOptions]];
  680. [self createConfiguredAppWithName:NSStringFromSelector(_cmd)];
  681. OCMVerifyAll(self.mockCoreDiagnosticsConnector);
  682. }
  683. - (void)testCoreDiagnosticsLoggedWhenAppDidBecomeActive {
  684. FIRApp *app = [self createConfiguredAppWithName:NSStringFromSelector(_cmd)];
  685. [self expectCoreDiagnosticsDataLogWithOptions:app.options];
  686. [self.notificationCenter postNotificationName:[self appDidBecomeActiveNotificationName]
  687. object:nil];
  688. OCMVerifyAll(self.mockCoreDiagnosticsConnector);
  689. }
  690. #pragma mark - private
  691. - (void)expectNotificationForObserver:(id)observer
  692. notificationName:(NSNotificationName)name
  693. object:(nullable id)object
  694. userInfo:(nullable NSDictionary *)userInfo {
  695. [self.notificationCenter addMockObserver:observer name:name object:object];
  696. [[observer expect] notificationWithName:name object:object userInfo:userInfo];
  697. }
  698. - (NSDictionary<NSString *, NSObject *> *)expectedUserInfoWithAppName:(NSString *)name
  699. isDefaultApp:(BOOL)isDefaultApp {
  700. return @{
  701. kFIRAppNameKey : name,
  702. kFIRAppIsDefaultAppKey : [NSNumber numberWithBool:isDefaultApp],
  703. kFIRGoogleAppIDKey : kGoogleAppID
  704. };
  705. }
  706. - (void)expectCoreDiagnosticsDataLogWithOptions:(nullable FIROptions *)expectedOptions {
  707. [self.mockCoreDiagnosticsConnector stopMocking];
  708. self.mockCoreDiagnosticsConnector = nil;
  709. self.mockCoreDiagnosticsConnector = OCMClassMock([FIRCoreDiagnosticsConnector class]);
  710. OCMExpect(ClassMethod([self.mockCoreDiagnosticsConnector
  711. logCoreTelemetryWithOptions:[OCMArg checkWithBlock:^BOOL(FIROptions *options) {
  712. if (!expectedOptions) {
  713. return YES;
  714. }
  715. return [options.googleAppID isEqualToString:expectedOptions.googleAppID] &&
  716. [options.GCMSenderID isEqualToString:expectedOptions.GCMSenderID];
  717. }]]));
  718. }
  719. - (NSNotificationName)appDidBecomeActiveNotificationName {
  720. #if TARGET_OS_IOS || TARGET_OS_TV
  721. return UIApplicationDidBecomeActiveNotification;
  722. #endif
  723. #if TARGET_OS_OSX
  724. return NSApplicationDidBecomeActiveNotification;
  725. #endif
  726. }
  727. - (FIRApp *)createConfiguredAppWithName:(NSString *)name {
  728. FIROptions *options = [self appOptions];
  729. [FIRApp configureWithName:name options:options];
  730. return [FIRApp appNamed:name];
  731. }
  732. - (FIROptions *)appOptions {
  733. return [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID GCMSenderID:kGCMSenderID];
  734. }
  735. @end