FIRAppTest.m 38 KB

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