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