FIRAppTest.m 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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)validateBundleIDHashWithinAppID:(NSString *)appID forVersion:(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:hashed bundle ID.
  347. XCTAssertFalse([FIRApp validateAppID:@"1:1337:iosdeadbeef"]);
  348. // Wrong platform "android".
  349. XCTAssertFalse([FIRApp validateAppID:@"1:1337:android:deadbeef"]);
  350. // The hashed bundle ID, aka 4th field, should only contain hex characters.
  351. XCTAssertFalse([FIRApp validateAppID:@"1:1337:ios:123abcxyz"]);
  352. // The hashed bundle ID, aka 4th field, is not tested in V1, so a bad value shouldn't cause a
  353. // failure.
  354. XCTAssertTrue([FIRApp validateAppID:@"1:1337:ios:deadbeef"]);
  355. }
  356. #pragma mark - App ID v2
  357. - (void)testAppIDV2 {
  358. // Missing separator between platform:hashed bundle ID.
  359. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios5e18052ab54fbfec"]);
  360. // Unknown versions may contain anything.
  361. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:123abcxyz"]);
  362. XCTAssertTrue([FIRApp validateAppID:@"2:thisdoesn'teven_m:a:t:t:e:r_"]);
  363. // Known good hashed bundle ID.
  364. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:5e18052ab54fbfec"]);
  365. // Unknown hashed bundle ID, not tested so shouldn't cause a failure.
  366. XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:deadbeef"]);
  367. }
  368. #pragma mark - App ID other
  369. - (void)testAppIDV3 {
  370. // Currently there is no specification for v3, so we would not expect it to fail.
  371. XCTAssertTrue([FIRApp validateAppID:@"3:1337:ios:deadbeef"]);
  372. }
  373. - (void)testAppIDEmpty {
  374. XCTAssertFalse([FIRApp validateAppID:@""]);
  375. }
  376. - (void)testAppIDValidationTrue {
  377. // Ensure that isAppIDValid matches validateAppID.
  378. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"" GCMSenderID:@""];
  379. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  380. OCMStub([self.appClassMock validateAppID:[OCMArg any]]).andReturn(YES);
  381. XCTAssertTrue([app isAppIDValid]);
  382. }
  383. - (void)testAppIDValidationFalse {
  384. // Ensure that isAppIDValid matches validateAppID.
  385. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"" GCMSenderID:@""];
  386. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  387. OCMStub([self.appClassMock validateAppID:[OCMArg any]]).andReturn(NO);
  388. XCTAssertFalse([app isAppIDValid]);
  389. }
  390. - (void)testAppIDPrefix {
  391. // Unknown numeric-character prefixes should pass.
  392. XCTAssertTrue([FIRApp validateAppID:@"0:"]);
  393. XCTAssertTrue([FIRApp validateAppID:@"01:"]);
  394. XCTAssertTrue([FIRApp validateAppID:@"10:"]);
  395. XCTAssertTrue([FIRApp validateAppID:@"010:"]);
  396. XCTAssertTrue([FIRApp validateAppID:@"3:"]);
  397. XCTAssertTrue([FIRApp validateAppID:@"123:"]);
  398. XCTAssertTrue([FIRApp validateAppID:@"999999999:"]);
  399. // Non-numeric prefixes should not pass.
  400. XCTAssertFalse([FIRApp validateAppID:@"a:"]);
  401. XCTAssertFalse([FIRApp validateAppID:@"abcsdf0:"]);
  402. XCTAssertFalse([FIRApp validateAppID:@"0aaaa:"]);
  403. XCTAssertFalse([FIRApp validateAppID:@"0aaaa0450:"]);
  404. XCTAssertFalse([FIRApp validateAppID:@"-1:"]);
  405. XCTAssertFalse([FIRApp validateAppID:@"abcsdf:"]);
  406. XCTAssertFalse([FIRApp validateAppID:@"ABDCF:"]);
  407. XCTAssertFalse([FIRApp validateAppID:@" :"]);
  408. XCTAssertFalse([FIRApp validateAppID:@"1 :"]);
  409. XCTAssertFalse([FIRApp validateAppID:@" 1:"]);
  410. XCTAssertFalse([FIRApp validateAppID:@" 123 :"]);
  411. XCTAssertFalse([FIRApp validateAppID:@"1 23:"]);
  412. XCTAssertFalse([FIRApp validateAppID:@"&($*&%(*$&:"]);
  413. XCTAssertFalse([FIRApp validateAppID:@"abCDSF$%%df:"]);
  414. // Known version prefixes should never pass without the rest of the app ID string present.
  415. XCTAssertFalse([FIRApp validateAppID:@"1:"]);
  416. // Version must include ":".
  417. XCTAssertFalse([FIRApp validateAppID:@"0"]);
  418. XCTAssertFalse([FIRApp validateAppID:@"01"]);
  419. XCTAssertFalse([FIRApp validateAppID:@"10"]);
  420. XCTAssertFalse([FIRApp validateAppID:@"010"]);
  421. XCTAssertFalse([FIRApp validateAppID:@"3"]);
  422. XCTAssertFalse([FIRApp validateAppID:@"123"]);
  423. XCTAssertFalse([FIRApp validateAppID:@"999999999"]);
  424. XCTAssertFalse([FIRApp validateAppID:@"com.google.bundleID"]);
  425. }
  426. - (void)testAppIDFormatInvalid {
  427. OCMStub([self.appClassMock actualBundleID]).andReturn(@"com.google.bundleID");
  428. // Some direct tests of the validateAppIDFormat:withVersion: method.
  429. // Sanity checks first.
  430. NSString *const kGoodAppIDV1 = @"1:1337:ios:deadbeef";
  431. NSString *const kGoodVersionV1 = @"1";
  432. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodVersionV1]);
  433. NSString *const kGoodAppIDV2 = @"2:1337:ios:5e18052ab54fbfec";
  434. NSString *const kGoodVersionV2 = @"2";
  435. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV2]);
  436. // Version mismatch.
  437. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV1]);
  438. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodVersionV2]);
  439. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:@"999:"]);
  440. // Nil or empty strings.
  441. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:nil]);
  442. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:@""]);
  443. XCTAssertFalse([FIRApp validateAppIDFormat:nil withVersion:kGoodVersionV1]);
  444. XCTAssertFalse([FIRApp validateAppIDFormat:@"" withVersion:kGoodVersionV1]);
  445. XCTAssertFalse([FIRApp validateAppIDFormat:nil withVersion:nil]);
  446. XCTAssertFalse([FIRApp validateAppIDFormat:@"" withVersion:@""]);
  447. // App ID contains only the version prefix.
  448. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodVersionV1 withVersion:kGoodVersionV1]);
  449. // The version is the entire app ID.
  450. XCTAssertFalse([FIRApp validateAppIDFormat:kGoodAppIDV1 withVersion:kGoodAppIDV1]);
  451. // Versions digits that may make a partial match.
  452. XCTAssertFalse([FIRApp validateAppIDFormat:@"01:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  453. XCTAssertFalse([FIRApp validateAppIDFormat:@"10:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  454. XCTAssertFalse([FIRApp validateAppIDFormat:@"11:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  455. XCTAssertFalse([FIRApp validateAppIDFormat:@"21:1337:ios:5e18052ab54fbfec"
  456. withVersion:kGoodVersionV2]);
  457. XCTAssertFalse([FIRApp validateAppIDFormat:@"22:1337:ios:5e18052ab54fbfec"
  458. withVersion:kGoodVersionV2]);
  459. XCTAssertFalse([FIRApp validateAppIDFormat:@"02:1337:ios:5e18052ab54fbfec"
  460. withVersion:kGoodVersionV2]);
  461. XCTAssertFalse([FIRApp validateAppIDFormat:@"20:1337:ios:5e18052ab54fbfec"
  462. withVersion:kGoodVersionV2]);
  463. // Extra fields.
  464. XCTAssertFalse([FIRApp validateAppIDFormat:@"ab:1:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  465. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:ab:1337:ios:deadbeef" withVersion:kGoodVersionV1]);
  466. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ab:ios:deadbeef" withVersion:kGoodVersionV1]);
  467. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ios:ab:deadbeef" withVersion:kGoodVersionV1]);
  468. XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ios:deadbeef:ab" withVersion:kGoodVersionV1]);
  469. }
  470. - (void)testAppIDContainsInvalidBundleIDHash {
  471. OCMStub([self.appClassMock actualBundleID]).andReturn(@"com.google.bundleID");
  472. // Some direct tests of the validateBundleIDHashWithinAppID:forVersion: method.
  473. // Sanity checks first.
  474. NSString *const kGoodAppIDV1 = @"1:1337:ios:deadbeef";
  475. NSString *const kGoodVersionV1 = @"1";
  476. XCTAssertTrue([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:kGoodVersionV1]);
  477. NSString *const kGoodAppIDV2 = @"2:1337:ios:5e18052ab54fbfec";
  478. NSString *const kGoodVersionV2 = @"2";
  479. XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV2]);
  480. // Nil or empty strings.
  481. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:nil]);
  482. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:@""]);
  483. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:nil forVersion:kGoodVersionV1]);
  484. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:@"" forVersion:kGoodVersionV1]);
  485. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:nil forVersion:nil]);
  486. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:@"" forVersion:@""]);
  487. // App ID contains only the version prefix.
  488. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodVersionV1 forVersion:kGoodVersionV1]);
  489. // The version is the entire app ID.
  490. XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:kGoodAppIDV1]);
  491. }
  492. // Uncomment if you need to measure performance of [FIRApp validateAppID:].
  493. // It is commented because measures are heavily dependent on a build agent configuration,
  494. // so it cannot produce reliable resault on CI
  495. //- (void)testAppIDValidationPerfomance {
  496. // [self measureBlock:^{
  497. // for (NSInteger i = 0; i < 100; ++i) {
  498. // [self testAppIDPrefix];
  499. // }
  500. // }];
  501. //}
  502. #pragma mark - Automatic Data Collection Tests
  503. - (void)testGlobalDataCollectionNoFlags {
  504. // Test: No flags set.
  505. NSString *name = NSStringFromSelector(_cmd);
  506. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  507. GCMSenderID:kGCMSenderID];
  508. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  509. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  510. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  511. .andReturn(nil);
  512. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  513. }
  514. - (void)testGlobalDataCollectionPlistSetEnabled {
  515. // Test: Plist set to enabled, no override.
  516. NSString *name = NSStringFromSelector(_cmd);
  517. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  518. GCMSenderID:kGCMSenderID];
  519. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  520. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
  521. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  522. .andReturn(nil);
  523. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  524. }
  525. - (void)testGlobalDataCollectionPlistSetDisabled {
  526. // Test: Plist set to disabled, no override.
  527. NSString *name = NSStringFromSelector(_cmd);
  528. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  529. GCMSenderID:kGCMSenderID];
  530. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  531. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
  532. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  533. .andReturn(nil);
  534. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  535. }
  536. - (void)testGlobalDataCollectionUserSpecifiedEnabled {
  537. // Test: User specified as enabled, no plist value.
  538. NSString *name = NSStringFromSelector(_cmd);
  539. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  540. GCMSenderID:kGCMSenderID];
  541. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  542. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  543. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  544. .andReturn(@YES);
  545. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  546. }
  547. - (void)testGlobalDataCollectionUserSpecifiedDisabled {
  548. // Test: User specified as disabled, no plist value.
  549. NSString *name = NSStringFromSelector(_cmd);
  550. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  551. GCMSenderID:kGCMSenderID];
  552. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  553. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(nil);
  554. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  555. .andReturn(@NO);
  556. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  557. }
  558. - (void)testGlobalDataCollectionUserOverriddenEnabled {
  559. // Test: User specified as enabled, with plist set as disabled.
  560. NSString *name = NSStringFromSelector(_cmd);
  561. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  562. GCMSenderID:kGCMSenderID];
  563. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  564. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@NO);
  565. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  566. .andReturn(@YES);
  567. XCTAssertTrue(app.isDataCollectionDefaultEnabled);
  568. }
  569. - (void)testGlobalDataCollectionUserOverriddenDisabled {
  570. // Test: User specified as disabled, with plist set as enabled.
  571. NSString *name = NSStringFromSelector(_cmd);
  572. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  573. GCMSenderID:kGCMSenderID];
  574. FIRApp *app = [[FIRApp alloc] initInstanceWithName:name options:options];
  575. OCMStub([self.appClassMock readDataCollectionSwitchFromPlist]).andReturn(@YES);
  576. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  577. .andReturn(@NO);
  578. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  579. }
  580. - (void)testGlobalDataCollectionWriteToDefaults {
  581. id defaultsMock = OCMPartialMock([NSUserDefaults standardUserDefaults]);
  582. NSString *name = NSStringFromSelector(_cmd);
  583. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  584. GCMSenderID:kGCMSenderID];
  585. [FIRApp configureWithName:name options:options];
  586. FIRApp *app = [FIRApp appNamed:name];
  587. app.dataCollectionDefaultEnabled = YES;
  588. NSString *key =
  589. [NSString stringWithFormat:kFIRGlobalAppDataCollectionEnabledDefaultsKeyFormat, app.name];
  590. OCMVerify([defaultsMock setObject:@YES forKey:key]);
  591. app.dataCollectionDefaultEnabled = NO;
  592. OCMVerify([defaultsMock setObject:@NO forKey:key]);
  593. [defaultsMock stopMocking];
  594. }
  595. - (void)testGlobalDataCollectionClearedAfterDelete {
  596. // Configure and disable data collection for the default FIRApp.
  597. NSString *name = NSStringFromSelector(_cmd);
  598. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  599. GCMSenderID:kGCMSenderID];
  600. [FIRApp configureWithName:name options:options];
  601. FIRApp *app = [FIRApp appNamed:name];
  602. app.dataCollectionDefaultEnabled = NO;
  603. XCTAssertFalse(app.isDataCollectionDefaultEnabled);
  604. // Delete the app, and verify that the switch was reset.
  605. XCTestExpectation *deleteFinished =
  606. [self expectationWithDescription:@"The app should successfully delete."];
  607. [app deleteApp:^(BOOL success) {
  608. XCTAssertTrue(success);
  609. [deleteFinished fulfill];
  610. }];
  611. // Wait for the delete to complete.
  612. [self waitForExpectations:@[ deleteFinished ] timeout:1];
  613. // Set up an app with the same name again, and check the data collection flag.
  614. [FIRApp configureWithName:name options:options];
  615. XCTAssertTrue([FIRApp appNamed:name].isDataCollectionDefaultEnabled);
  616. }
  617. - (void)testGlobalDataCollectionNoDiagnosticsSent {
  618. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
  619. GCMSenderID:kGCMSenderID];
  620. FIRApp *app = [[FIRApp alloc] initInstanceWithName:NSStringFromSelector(_cmd) options:options];
  621. app.dataCollectionDefaultEnabled = NO;
  622. // Stub out reading from user defaults since stubbing out the BOOL has issues. If the data
  623. // collection switch is disabled, the `sendLogs` call should return immediately and not fire a
  624. // notification.
  625. OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
  626. .andReturn(@NO);
  627. // Don't expect the diagnostics data to be sent.
  628. self.assertNoLogCoreTelemetry = YES;
  629. // The diagnostics data is expected to be sent on `UIApplicationDidBecomeActiveNotification` when
  630. // data collection is enabled.
  631. [FIRApp configure];
  632. [self.notificationCenter postNotificationName:[self appDidBecomeActiveNotificationName]
  633. object:nil];
  634. // Wait for some time because diagnostics is logged asynchronously.
  635. OCMVerifyAll(self.mockHeartbeatLogger);
  636. }
  637. #pragma mark - Analytics Flag Tests
  638. - (void)testAnalyticsSetByGlobalDataCollectionSwitch {
  639. // Test that the global data collection switch triggers setting Analytics when no explicit flag is
  640. // set.
  641. id optionsMock = OCMClassMock([FIROptions class]);
  642. OCMStub([optionsMock isAnalyticsCollectionExplicitlySet]).andReturn(NO);
  643. // We need to use the default app name since Analytics only associates with the default app.
  644. FIRApp *defaultApp = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:optionsMock];
  645. id configurationMock = OCMClassMock([FIRAnalyticsConfiguration class]);
  646. OCMStub([configurationMock sharedInstance]).andReturn(configurationMock);
  647. // Ensure Analytics is set after the global flag is set. It needs to
  648. [defaultApp setDataCollectionDefaultEnabled:YES];
  649. OCMVerify([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:NO]);
  650. [defaultApp setDataCollectionDefaultEnabled:NO];
  651. OCMVerify([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:NO]);
  652. }
  653. - (void)testAnalyticsNotSetByGlobalDataCollectionSwitch {
  654. // Test that the global data collection switch doesn't override an explicitly set Analytics flag.
  655. id optionsMock = OCMClassMock([FIROptions class]);
  656. OCMStub([optionsMock isAnalyticsCollectionExplicitlySet]).andReturn(YES);
  657. FIRApp *app = [[FIRApp alloc] initInstanceWithName:@"testAnalyticsNotSet" options:optionsMock];
  658. id configurationMock = OCMClassMock([FIRAnalyticsConfiguration class]);
  659. OCMStub([configurationMock sharedInstance]).andReturn(configurationMock);
  660. // Reject any changes to Analytics when the data collection changes.
  661. OCMReject([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:YES]);
  662. OCMReject([configurationMock setAnalyticsCollectionEnabled:YES persistSetting:NO]);
  663. [app setDataCollectionDefaultEnabled:YES];
  664. OCMReject([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:YES]);
  665. OCMReject([configurationMock setAnalyticsCollectionEnabled:NO persistSetting:NO]);
  666. [app setDataCollectionDefaultEnabled:NO];
  667. }
  668. #pragma mark - Internal Methods
  669. - (void)testIsDefaultAppConfigured {
  670. // Ensure it's false before anything is configured.
  671. XCTAssertFalse([FIRApp isDefaultAppConfigured]);
  672. // Configure it and ensure it's configured.
  673. [FIRApp configure];
  674. XCTAssertTrue([FIRApp isDefaultAppConfigured]);
  675. // Reset the apps and ensure it's not configured anymore.
  676. [FIRApp resetApps];
  677. XCTAssertFalse([FIRApp isDefaultAppConfigured]);
  678. }
  679. #pragma mark - Core Telemetry
  680. - (void)testHeartbeatLogIsAttemptedWhenAppDidBecomeActive {
  681. [self createConfiguredAppWithName:NSStringFromSelector(_cmd)];
  682. OCMExpect([self.mockHeartbeatLogger log]).andDo(nil);
  683. [self.notificationCenter postNotificationName:[self appDidBecomeActiveNotificationName]
  684. object:nil];
  685. OCMVerifyAll(self.mockHeartbeatLogger);
  686. }
  687. #pragma mark - private
  688. - (XCTestExpectation *)expectNotificationNamed:(NSNotificationName)name
  689. object:(nullable id)object
  690. userInfo:(NSDictionary *)userInfo {
  691. XCTestExpectation *notificationExpectation =
  692. [self expectationForNotification:name
  693. object:object
  694. notificationCenter:self.notificationCenter
  695. handler:^BOOL(NSNotification *_Nonnull notification) {
  696. return [userInfo isEqualToDictionary:notification.userInfo];
  697. }];
  698. return notificationExpectation;
  699. }
  700. - (NSDictionary<NSString *, NSObject *> *)expectedUserInfoWithAppName:(NSString *)name
  701. isDefaultApp:(BOOL)isDefaultApp {
  702. return @{
  703. kFIRAppNameKey : name,
  704. kFIRAppIsDefaultAppKey : [NSNumber numberWithBool:isDefaultApp],
  705. kFIRGoogleAppIDKey : kGoogleAppID
  706. };
  707. }
  708. - (NSNotificationName)appDidBecomeActiveNotificationName {
  709. #if TARGET_OS_IOS || TARGET_OS_TV
  710. return UIApplicationDidBecomeActiveNotification;
  711. #elif TARGET_OS_OSX
  712. return NSApplicationDidBecomeActiveNotification;
  713. #elif TARGET_OS_WATCH
  714. // See comment in `- [FIRApp subscribeForAppDidBecomeActiveNotifications]`.
  715. if (@available(watchOS 7.0, *)) {
  716. return WKApplicationDidBecomeActiveNotification;
  717. } else {
  718. return kFIRAppReadyToConfigureSDKNotification;
  719. }
  720. #endif
  721. }
  722. - (FIRApp *)createConfiguredAppWithName:(NSString *)name {
  723. FIROptions *options = [self appOptions];
  724. [FIRApp configureWithName:name options:options];
  725. return [FIRApp appNamed:name];
  726. }
  727. - (FIROptions *)appOptions {
  728. return [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID GCMSenderID:kGCMSenderID];
  729. }
  730. - (void)registerLibrariesWithClasses:(NSArray<Class> *)classes {
  731. for (Class klass in classes) {
  732. [FIRApp registerInternalLibrary:klass withName:NSStringFromClass(klass) withVersion:@"1.0"];
  733. }
  734. }
  735. @end