FIRInstallationsIDControllerTests.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import <OCMock/OCMock.h>
  18. #import <FirebaseCore/FIRAppInternal.h>
  19. #import "FBLPromise+Testing.h"
  20. #import "FIRInstallationsErrorUtil+Tests.h"
  21. #import "FIRInstallationsItem+Tests.h"
  22. #import "FIRInstallations.h"
  23. #import "FIRInstallationsAPIService.h"
  24. #import "FIRInstallationsErrorUtil.h"
  25. #import "FIRInstallationsIDController.h"
  26. #import "FIRInstallationsIIDStore.h"
  27. #import "FIRInstallationsStore.h"
  28. #import "FIRInstallationsStoredAuthToken.h"
  29. @interface FIRInstallationsIDController (Tests)
  30. - (instancetype)initWithGoogleAppID:(NSString *)appID
  31. appName:(NSString *)appName
  32. installationsStore:(FIRInstallationsStore *)installationsStore
  33. APIService:(FIRInstallationsAPIService *)APIService
  34. IIDStore:(FIRInstallationsIIDStore *)IIDStore;
  35. @end
  36. @interface FIRInstallationsIDControllerTests : XCTestCase
  37. @property(nonatomic) FIRInstallationsIDController *controller;
  38. @property(nonatomic) id mockInstallationsStore;
  39. @property(nonatomic) id mockAPIService;
  40. @property(nonatomic) id mockIIDStore;
  41. @property(nonatomic) NSString *appID;
  42. @property(nonatomic) NSString *appName;
  43. @end
  44. @implementation FIRInstallationsIDControllerTests
  45. - (void)setUp {
  46. [self setUpWithAppName:kFIRDefaultAppName];
  47. }
  48. - (void)setUpWithAppName:(NSString *)appName {
  49. self.appID = @"appID";
  50. self.appName = appName;
  51. self.mockInstallationsStore = OCMStrictClassMock([FIRInstallationsStore class]);
  52. self.mockAPIService = OCMStrictClassMock([FIRInstallationsAPIService class]);
  53. self.mockIIDStore = OCMStrictClassMock([FIRInstallationsIIDStore class]);
  54. self.controller =
  55. [[FIRInstallationsIDController alloc] initWithGoogleAppID:self.appID
  56. appName:self.appName
  57. installationsStore:self.mockInstallationsStore
  58. APIService:self.mockAPIService
  59. IIDStore:self.mockIIDStore];
  60. }
  61. - (void)tearDown {
  62. self.controller = nil;
  63. self.mockIIDStore = nil;
  64. self.mockAPIService = nil;
  65. self.mockInstallationsStore = nil;
  66. self.appID = nil;
  67. self.appName = nil;
  68. }
  69. #pragma mark - Get Installation
  70. - (void)testGetInstallationItem_WhenFIDExists_ThenItIsReturned {
  71. FIRInstallationsItem *storedInstallations =
  72. [FIRInstallationsItem createRegisteredInstallationItem];
  73. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  74. .andReturn([FBLPromise resolvedWith:storedInstallations]);
  75. // Don't expect FIRInstallationIDDidChangeNotification to be sent.
  76. XCTestExpectation *notificationExpectation =
  77. [self installationIDDidChangeNotificationExpectation];
  78. notificationExpectation.inverted = YES;
  79. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getInstallationItem];
  80. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  81. XCTAssertNil(promise.error);
  82. XCTAssertEqual(promise.value, storedInstallations);
  83. OCMVerifyAll(self.mockInstallationsStore);
  84. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  85. }
  86. - (void)testGetInstallationItem_WhenNoFIDAndNoIID_ThenFIDIsCreatedAndRegistered {
  87. // 1. Stub store get installation.
  88. [self expectInstallationsStoreGetInstallationNotFound];
  89. // 2. Stub store save installation.
  90. __block FIRInstallationsItem *createdInstallation;
  91. OCMExpect([self.mockInstallationsStore
  92. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  93. [self assertValidCreatedInstallation:obj];
  94. createdInstallation = obj;
  95. return YES;
  96. }]])
  97. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  98. // 3. Stub API register installation.
  99. // 3.1. Verify installation to be registered.
  100. id registerInstallationValidation = [OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  101. [self assertValidCreatedInstallation:obj];
  102. XCTAssertEqual(obj.firebaseInstallationID.length, 22);
  103. return YES;
  104. }];
  105. // 3.2. Expect for `registerInstallation` to be called.
  106. FBLPromise<FIRInstallationsItem *> *registerPromise = [FBLPromise pendingPromise];
  107. OCMExpect([self.mockAPIService registerInstallation:registerInstallationValidation])
  108. .andReturn(registerPromise);
  109. // 4. Expect IIDStore to be checked for existing IID.
  110. FBLPromise *rejectedPromise = [FBLPromise pendingPromise];
  111. [rejectedPromise reject:[FIRInstallationsErrorUtil keychainErrorWithFunction:@"" status:-1]];
  112. OCMExpect([self.mockIIDStore existingIID]).andReturn(rejectedPromise);
  113. // 5. Call get installation and check.
  114. FBLPromise<FIRInstallationsItem *> *getInstallationPromise =
  115. [self.controller getInstallationItem];
  116. // 5.1. Wait for the stored item to be read and saved.
  117. OCMVerifyAllWithDelay(self.mockInstallationsStore, 0.5);
  118. // 5.2. Wait for `registerInstallation` to be called.
  119. OCMVerifyAllWithDelay(self.mockAPIService, 0.5);
  120. // 5.3. Expect for the registered installation to be saved.
  121. FIRInstallationsItem *registeredInstallation = [FIRInstallationsItem
  122. createRegisteredInstallationItemWithAppID:createdInstallation.appID
  123. appName:createdInstallation.firebaseAppName];
  124. OCMExpect([self.mockInstallationsStore
  125. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  126. XCTAssertEqual(registeredInstallation, obj);
  127. return YES;
  128. }]])
  129. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  130. // 5.5. Resolve `registerPromise` to simulate finished registration.
  131. [registerPromise fulfill:registeredInstallation];
  132. // 5.4. Wait for the task to complete.
  133. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  134. XCTAssertNil(getInstallationPromise.error);
  135. // We expect the initially created installation to be returned - must not wait for registration to
  136. // complete here.
  137. XCTAssertEqual(getInstallationPromise.value, createdInstallation);
  138. // 5.5. Verify registered installation was saved.
  139. OCMVerifyAll(self.mockInstallationsStore);
  140. OCMVerifyAll(self.mockIIDStore);
  141. }
  142. - (void)testGetInstallationItem_WhenThereIsIIDAndNoFID_ThenFIDIsCreatedAndRegistered {
  143. // 0. Configure controller with not default app.
  144. NSString *appName = @"appName";
  145. [self setUpWithAppName:appName];
  146. // 1. Stub store get installation.
  147. [self expectInstallationsStoreGetInstallationNotFound];
  148. // 2. Don't expect IIDStore to be checked for existing IID (not default app).
  149. OCMReject([self.mockIIDStore existingIID]);
  150. // 3. Stub store save installation.
  151. __block FIRInstallationsItem *createdInstallation;
  152. OCMExpect([self.mockInstallationsStore
  153. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  154. [self assertValidCreatedInstallation:obj];
  155. createdInstallation = obj;
  156. return YES;
  157. }]])
  158. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  159. // 4. Stub API register installation.
  160. // 4.1. Verify installation to be registered.
  161. id registerInstallationValidation = [OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  162. [self assertValidCreatedInstallation:obj];
  163. return YES;
  164. }];
  165. // 4.2. Expect for `registerInstallation` to be called.
  166. FBLPromise<FIRInstallationsItem *> *registerPromise = [FBLPromise pendingPromise];
  167. OCMExpect([self.mockAPIService registerInstallation:registerInstallationValidation])
  168. .andReturn(registerPromise);
  169. // 5. Call get installation and check.
  170. FBLPromise<FIRInstallationsItem *> *getInstallationPromise =
  171. [self.controller getInstallationItem];
  172. // 5.1. Wait for the stored item to be read and saved.
  173. OCMVerifyAllWithDelay(self.mockInstallationsStore, 0.5);
  174. // 5.2. Wait for `registerInstallation` to be called.
  175. OCMVerifyAllWithDelay(self.mockAPIService, 0.5);
  176. // 5.3. Expect for the registered installation to be saved.
  177. FIRInstallationsItem *registeredInstallation = [FIRInstallationsItem
  178. createRegisteredInstallationItemWithAppID:createdInstallation.appID
  179. appName:createdInstallation.firebaseAppName];
  180. OCMExpect([self.mockInstallationsStore
  181. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  182. XCTAssertEqual(registeredInstallation, obj);
  183. return YES;
  184. }]])
  185. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  186. // 5.5. Resolve `registerPromise` to simulate finished registration.
  187. [registerPromise fulfill:registeredInstallation];
  188. // 5.4. Wait for the task to complete.
  189. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  190. XCTAssertNil(getInstallationPromise.error);
  191. // We expect the initially created installation to be returned - must not wait for registration to
  192. // complete here.
  193. XCTAssertEqual(getInstallationPromise.value, createdInstallation);
  194. // 5.5. Verify registered installation was saved.
  195. OCMVerifyAll(self.mockInstallationsStore);
  196. OCMVerifyAll(self.mockIIDStore);
  197. }
  198. - (void)testGetInstallationItem_WhenThereIsIIDAndNoFIDNotDefaultApp_ThenIIDIsUsedAsFID {
  199. // 1. Stub store get installation.
  200. [self expectInstallationsStoreGetInstallationNotFound];
  201. // 2. Expect IIDStore to be checked for existing IID.
  202. NSString *existingIID = @"existing-iid";
  203. OCMExpect([self.mockIIDStore existingIID]).andReturn([FBLPromise resolvedWith:existingIID]);
  204. // 3. Stub store save installation.
  205. __block FIRInstallationsItem *createdInstallation;
  206. OCMExpect([self.mockInstallationsStore
  207. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  208. [self assertValidCreatedInstallation:obj];
  209. XCTAssertEqualObjects(existingIID, obj.firebaseInstallationID);
  210. createdInstallation = obj;
  211. return YES;
  212. }]])
  213. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  214. // 4. Stub API register installation.
  215. // 4.1. Verify installation to be registered.
  216. id registerInstallationValidation = [OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  217. [self assertValidCreatedInstallation:obj];
  218. XCTAssertEqualObjects(existingIID, obj.firebaseInstallationID);
  219. return YES;
  220. }];
  221. // 4.2. Expect for `registerInstallation` to be called.
  222. FBLPromise<FIRInstallationsItem *> *registerPromise = [FBLPromise pendingPromise];
  223. OCMExpect([self.mockAPIService registerInstallation:registerInstallationValidation])
  224. .andReturn(registerPromise);
  225. // 5. Call get installation and check.
  226. FBLPromise<FIRInstallationsItem *> *getInstallationPromise =
  227. [self.controller getInstallationItem];
  228. // 5.1. Wait for the stored item to be read and saved.
  229. OCMVerifyAllWithDelay(self.mockInstallationsStore, 0.5);
  230. // 5.2. Wait for `registerInstallation` to be called.
  231. OCMVerifyAllWithDelay(self.mockAPIService, 0.5);
  232. // 5.3. Expect for the registered installation to be saved.
  233. FIRInstallationsItem *registeredInstallation = [FIRInstallationsItem
  234. createRegisteredInstallationItemWithAppID:createdInstallation.appID
  235. appName:createdInstallation.firebaseAppName];
  236. OCMExpect([self.mockInstallationsStore
  237. saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *obj) {
  238. XCTAssertEqual(registeredInstallation, obj);
  239. return YES;
  240. }]])
  241. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  242. // 5.5. Resolve `registerPromise` to simulate finished registration.
  243. [registerPromise fulfill:registeredInstallation];
  244. // 5.4. Wait for the task to complete.
  245. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  246. XCTAssertNil(getInstallationPromise.error);
  247. // We expect the initially created installation to be returned - must not wait for registration to
  248. // complete here.
  249. XCTAssertEqual(getInstallationPromise.value, createdInstallation);
  250. // 5.5. Verify registered installation was saved.
  251. OCMVerifyAll(self.mockInstallationsStore);
  252. OCMVerifyAll(self.mockIIDStore);
  253. }
  254. - (void)testGetInstallationItem_WhenCalledSeveralTimes_OnlyOneOperationIsPerformed {
  255. // 1. Expect the installation to be requested from the store only once.
  256. FIRInstallationsItem *storedInstallation1 =
  257. [FIRInstallationsItem createRegisteredInstallationItem];
  258. FBLPromise<FIRInstallationsItem *> *pendingStorePromise = [FBLPromise pendingPromise];
  259. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  260. .andReturn(pendingStorePromise);
  261. // 3. Request installation n times
  262. NSInteger requestCount = 10;
  263. NSMutableArray *installationPromises = [NSMutableArray arrayWithCapacity:requestCount];
  264. for (NSInteger i = 0; i < requestCount; i++) {
  265. [installationPromises addObject:[self.controller getInstallationItem]];
  266. }
  267. // 4. Resolve store promise.
  268. [pendingStorePromise fulfill:storedInstallation1];
  269. // 5. Wait for operation to be completed and check.
  270. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  271. for (FBLPromise<FIRInstallationsItem *> *installationPromise in installationPromises) {
  272. XCTAssertNil(installationPromise.error);
  273. XCTAssertEqual(installationPromise.value, storedInstallation1);
  274. }
  275. OCMVerifyAll(self.mockInstallationsStore);
  276. OCMVerifyAll(self.mockAPIService);
  277. // 6. Check that a new request is performed once previous finished.
  278. FIRInstallationsItem *storedInstallation2 =
  279. [FIRInstallationsItem createRegisteredInstallationItem];
  280. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  281. .andReturn([FBLPromise resolvedWith:storedInstallation2]);
  282. FBLPromise<FIRInstallationsItem *> *installationPromise = [self.controller getInstallationItem];
  283. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  284. XCTAssertNil(installationPromise.error);
  285. XCTAssertEqual(installationPromise.value, storedInstallation2);
  286. OCMVerifyAll(self.mockInstallationsStore);
  287. OCMVerifyAll(self.mockAPIService);
  288. }
  289. #pragma mark - Get Auth Token
  290. - (void)testGetAuthToken_WhenValidInstallationExists_ThenItIsReturned {
  291. // 1. Expect installation to be requested from the store.
  292. FIRInstallationsItem *storedInstallation =
  293. [FIRInstallationsItem createRegisteredInstallationItem];
  294. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  295. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  296. // 2. Request auth token.
  297. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:NO];
  298. // 3. Wait for the promise to resolve.
  299. FBLWaitForPromisesWithTimeout(0.5);
  300. // 4. Check.
  301. OCMVerifyAll(self.mockInstallationsStore);
  302. OCMVerifyAll(self.mockAPIService);
  303. XCTAssertNil(promise.error);
  304. XCTAssertNotNil(promise.value);
  305. XCTAssertEqualObjects(promise.value.authToken.token, storedInstallation.authToken.token);
  306. XCTAssertEqualObjects(promise.value.authToken.expirationDate,
  307. storedInstallation.authToken.expirationDate);
  308. }
  309. - (void)testGetAuthToken_WhenValidInstallationWithExpiredTokenExists_ThenTokenRequested {
  310. // 1.1. Expect installation to be requested from the store.
  311. FIRInstallationsItem *storedInstallation =
  312. [FIRInstallationsItem createRegisteredInstallationItem];
  313. storedInstallation.authToken.expirationDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 - 1];
  314. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  315. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  316. // 1.2. Expect API request.
  317. FIRInstallationsItem *responseInstallation =
  318. [FIRInstallationsItem createRegisteredInstallationItem];
  319. responseInstallation.authToken.token =
  320. [responseInstallation.authToken.token stringByAppendingString:@"_new"];
  321. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  322. .andReturn([FBLPromise resolvedWith:responseInstallation]);
  323. // 2. Request auth token.
  324. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:NO];
  325. // 3. Wait for the promise to resolve.
  326. FBLWaitForPromisesWithTimeout(0.5);
  327. // 4. Check.
  328. OCMVerifyAll(self.mockInstallationsStore);
  329. OCMVerifyAll(self.mockAPIService);
  330. XCTAssertNil(promise.error);
  331. XCTAssertNotNil(promise.value);
  332. XCTAssertEqualObjects(promise.value.authToken.token, responseInstallation.authToken.token);
  333. XCTAssertEqualObjects(promise.value.authToken.expirationDate,
  334. responseInstallation.authToken.expirationDate);
  335. }
  336. - (void)testGetAuthTokenForcingRefresh_WhenValidInstallationExists_ThenTokenRequested {
  337. // 1.1. Expect installation to be requested from the store.
  338. FIRInstallationsItem *storedInstallation =
  339. [FIRInstallationsItem createRegisteredInstallationItem];
  340. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  341. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  342. // 1.2. Expect API request.
  343. FIRInstallationsItem *responseInstallation =
  344. [FIRInstallationsItem createRegisteredInstallationItem];
  345. responseInstallation.authToken.token =
  346. [responseInstallation.authToken.token stringByAppendingString:@"_new"];
  347. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  348. .andReturn([FBLPromise resolvedWith:responseInstallation]);
  349. // 2. Request auth token.
  350. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:YES];
  351. // 3. Wait for the promise to resolve.
  352. FBLWaitForPromisesWithTimeout(0.5);
  353. // 4. Check.
  354. OCMVerifyAll(self.mockInstallationsStore);
  355. OCMVerifyAll(self.mockAPIService);
  356. XCTAssertNil(promise.error);
  357. XCTAssertNotNil(promise.value);
  358. XCTAssertEqualObjects(promise.value.authToken.token, responseInstallation.authToken.token);
  359. XCTAssertEqualObjects(promise.value.authToken.expirationDate,
  360. responseInstallation.authToken.expirationDate);
  361. }
  362. - (void)testGetAuthToken_WhenServerResponseIsInternalError_ThenRetriesOnceAndSucceeds {
  363. // 1.1. Expect installation to be requested from the store.
  364. FIRInstallationsItem *storedInstallation =
  365. [FIRInstallationsItem createRegisteredInstallationItem];
  366. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  367. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  368. // 1.2. Expect API request called twice.
  369. // 1.2.1. Fail 1st.
  370. NSError *error500 = [FIRInstallationsErrorUtil APIErrorWithHTTPCode:500];
  371. FBLPromise *rejectedPromise = [FBLPromise pendingPromise];
  372. [rejectedPromise reject:error500];
  373. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  374. .andReturn(rejectedPromise);
  375. // 2. Request auth token.
  376. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:YES];
  377. // 3. Wait for the operation to complete.
  378. // 3.1. Wait for the 1st request to fail.
  379. OCMVerifyAllWithDelay(self.mockAPIService, 0.5);
  380. // 3.2. Expect another request and succeed.
  381. FIRInstallationsItem *responseInstallation =
  382. [FIRInstallationsItem createRegisteredInstallationItem];
  383. responseInstallation.authToken.token =
  384. [responseInstallation.authToken.token stringByAppendingString:@"_new"];
  385. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  386. .andReturn([FBLPromise resolvedWith:responseInstallation]);
  387. // 3.3. Wait for the promise to resolve.
  388. XCTAssert(FBLWaitForPromisesWithTimeout(2));
  389. // 4. Check.
  390. OCMVerifyAll(self.mockInstallationsStore);
  391. OCMVerifyAll(self.mockAPIService);
  392. XCTAssertNil(promise.error);
  393. XCTAssertNotNil(promise.value);
  394. XCTAssertEqualObjects(promise.value.authToken.token, responseInstallation.authToken.token);
  395. XCTAssertEqualObjects(promise.value.authToken.expirationDate,
  396. responseInstallation.authToken.expirationDate);
  397. }
  398. - (void)testGetAuthToken_WhenServerResponseIsInternalError_ThenRetriesOnceAndFails {
  399. // 1.1. Expect installation to be requested from the store.
  400. FIRInstallationsItem *storedInstallation =
  401. [FIRInstallationsItem createRegisteredInstallationItem];
  402. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  403. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  404. // 1.2. Expect API request called twice.
  405. NSError *error500 = [FIRInstallationsErrorUtil APIErrorWithHTTPCode:500];
  406. FBLPromise *rejectedPromise = [FBLPromise pendingPromise];
  407. [rejectedPromise reject:error500];
  408. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  409. .andReturn(rejectedPromise);
  410. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  411. .andReturn(rejectedPromise);
  412. // 2. Request auth token.
  413. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:YES];
  414. // 3. Wait for the promise to resolve.
  415. XCTAssert(FBLWaitForPromisesWithTimeout(2));
  416. // 4. Check.
  417. OCMVerifyAll(self.mockInstallationsStore);
  418. OCMVerifyAll(self.mockAPIService);
  419. XCTAssertEqualObjects(promise.error, error500);
  420. XCTAssertNil(promise.value);
  421. }
  422. - (void)testGetAuthToken_WhenCalledSeveralTimes_OnlyOneOperationIsPerformed {
  423. // 1. Expect installation to be requested from the store.
  424. FIRInstallationsItem *storedInstallation =
  425. [FIRInstallationsItem createRegisteredInstallationItem];
  426. FBLPromise *storagePendingPromise = [FBLPromise pendingPromise];
  427. // Expect the installation to be requested only once.
  428. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  429. .andReturn(storagePendingPromise);
  430. // 2. Request auth token n times.
  431. NSInteger requestCount = 10;
  432. NSMutableArray *authTokenPromises = [NSMutableArray arrayWithCapacity:requestCount];
  433. for (NSInteger i = 0; i < requestCount; i++) {
  434. [authTokenPromises addObject:[self.controller getAuthTokenForcingRefresh:NO]];
  435. }
  436. // 3. Finish the storage request.
  437. [storagePendingPromise fulfill:storedInstallation];
  438. // 4. Wait for the promise to resolve.
  439. FBLWaitForPromisesWithTimeout(0.5);
  440. // 5. Check.
  441. OCMVerifyAll(self.mockInstallationsStore);
  442. for (FBLPromise<FIRInstallationsItem *> *authPromise in authTokenPromises) {
  443. XCTAssertNil(authPromise.error);
  444. XCTAssertNotNil(authPromise.value);
  445. XCTAssertEqualObjects(authPromise.value.authToken.token, storedInstallation.authToken.token);
  446. XCTAssertEqualObjects(authPromise.value.authToken.expirationDate,
  447. storedInstallation.authToken.expirationDate);
  448. }
  449. }
  450. - (void)testGetAuthTokenForceRefresh_WhenCalledSeveralTimes_OnlyOneOperationIsPerformed {
  451. // 1.1. Expect installation to be requested from the store.
  452. FIRInstallationsItem *storedInstallation =
  453. [FIRInstallationsItem createRegisteredInstallationItem];
  454. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  455. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  456. // 1.2. Expect API request.
  457. FIRInstallationsItem *responseInstallation =
  458. [FIRInstallationsItem createRegisteredInstallationItem];
  459. responseInstallation.authToken.token =
  460. [responseInstallation.authToken.token stringByAppendingString:@"_new"];
  461. FBLPromise *pendingAPIPromise = [FBLPromise pendingPromise];
  462. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  463. .andReturn(pendingAPIPromise);
  464. // 2. Request auth token n times.
  465. NSInteger requestCount = 10;
  466. NSMutableArray *authTokenPromises = [NSMutableArray arrayWithCapacity:requestCount];
  467. for (NSInteger i = 0; i < requestCount; i++) {
  468. [authTokenPromises addObject:[self.controller getAuthTokenForcingRefresh:YES]];
  469. }
  470. // 3. Finish the API request.
  471. [pendingAPIPromise fulfill:responseInstallation];
  472. // 4. Wait for the promise to resolve.
  473. FBLWaitForPromisesWithTimeout(0.5);
  474. // 5. Check.
  475. OCMVerifyAll(self.mockInstallationsStore);
  476. for (FBLPromise<FIRInstallationsItem *> *authPromise in authTokenPromises) {
  477. XCTAssertNil(authPromise.error);
  478. XCTAssertNotNil(authPromise.value);
  479. XCTAssertEqualObjects(authPromise.value.authToken.token, responseInstallation.authToken.token);
  480. XCTAssertEqualObjects(authPromise.value.authToken.expirationDate,
  481. responseInstallation.authToken.expirationDate);
  482. }
  483. }
  484. #pragma mark - FID Deletion
  485. - (void)testDeleteRegisteredInstallation {
  486. // 1. Expect installation to be requested from the store.
  487. FIRInstallationsItem *installation = [FIRInstallationsItem createRegisteredInstallationItem];
  488. OCMExpect([self.mockInstallationsStore installationForAppID:installation.appID
  489. appName:installation.firebaseAppName])
  490. .andReturn([FBLPromise resolvedWith:installation]);
  491. // 2. Expect API request to delete installation.
  492. OCMExpect([self.mockAPIService deleteInstallation:installation])
  493. .andReturn([FBLPromise resolvedWith:installation]);
  494. // 3.1. Expect the installation to be removed from the storage.
  495. OCMExpect([self.mockInstallationsStore removeInstallationForAppID:installation.appID
  496. appName:installation.firebaseAppName])
  497. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  498. // 3.2. Expect IID to be deleted, because it is default app.
  499. OCMExpect([self.mockIIDStore deleteExistingIID])
  500. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  501. // 4. Expect FIRInstallationIDDidChangeNotification to be sent.
  502. XCTestExpectation *notificationExpectation =
  503. [self installationIDDidChangeNotificationExpectation];
  504. // 5. Call delete installation.
  505. FBLPromise<NSNull *> *promise = [self.controller deleteInstallation];
  506. // 6. Wait for operations to complete and check.
  507. FBLWaitForPromisesWithTimeout(0.5);
  508. XCTAssertNil(promise.error);
  509. XCTAssertTrue(promise.isFulfilled);
  510. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  511. OCMVerifyAll(self.mockInstallationsStore);
  512. OCMVerifyAll(self.mockAPIService);
  513. OCMVerifyAll(self.mockIIDStore);
  514. }
  515. - (void)testDeleteUnregisteredInstallation {
  516. // 1. Expect installation to be requested from the store.
  517. FIRInstallationsItem *installation = [FIRInstallationsItem createUnregisteredInstallationItem];
  518. OCMExpect([self.mockInstallationsStore installationForAppID:installation.appID
  519. appName:installation.firebaseAppName])
  520. .andReturn([FBLPromise resolvedWith:installation]);
  521. // 2. Don't expect API request to delete installation.
  522. OCMReject([self.mockAPIService deleteInstallation:[OCMArg any]]);
  523. // 3.1. Expect the installation to be removed from the storage.
  524. OCMExpect([self.mockInstallationsStore removeInstallationForAppID:installation.appID
  525. appName:installation.firebaseAppName])
  526. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  527. // 3.2. Expect IID to be deleted, because it is default app.
  528. OCMExpect([self.mockIIDStore deleteExistingIID])
  529. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  530. // 4. Expect FIRInstallationIDDidChangeNotification to be sent.
  531. XCTestExpectation *notificationExpectation =
  532. [self installationIDDidChangeNotificationExpectation];
  533. // 5. Call delete installation.
  534. FBLPromise<NSNull *> *promise = [self.controller deleteInstallation];
  535. // 6. Wait for operations to complete and check.
  536. FBLWaitForPromisesWithTimeout(0.5);
  537. XCTAssertNil(promise.error);
  538. XCTAssertTrue(promise.isFulfilled);
  539. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  540. OCMVerifyAll(self.mockInstallationsStore);
  541. OCMVerifyAll(self.mockAPIService);
  542. OCMVerifyAll(self.mockIIDStore);
  543. }
  544. - (void)testDeleteRegisteredInstallation_WhenAPIRequestFails_ThenFailsAndInstallationIsNotRemoved {
  545. // 1. Expect installation to be requested from the store.
  546. FIRInstallationsItem *installation = [FIRInstallationsItem createRegisteredInstallationItem];
  547. OCMExpect([self.mockInstallationsStore installationForAppID:installation.appID
  548. appName:installation.firebaseAppName])
  549. .andReturn([FBLPromise resolvedWith:installation]);
  550. // 2. Expect API request to delete installation.
  551. FBLPromise *rejectedAPIPromise = [FBLPromise pendingPromise];
  552. NSError *error500 = [FIRInstallationsErrorUtil APIErrorWithHTTPCode:500];
  553. [rejectedAPIPromise reject:error500];
  554. OCMExpect([self.mockAPIService deleteInstallation:installation]).andReturn(rejectedAPIPromise);
  555. // 3.1. Don't expect the installation to be removed from the storage.
  556. OCMReject([self.mockInstallationsStore removeInstallationForAppID:[OCMArg any]
  557. appName:[OCMArg any]]);
  558. // 3.2. Don't expect IID to be deleted.
  559. OCMReject([self.mockIIDStore deleteExistingIID]);
  560. // 4. Don't expect FIRInstallationIDDidChangeNotification to be sent.
  561. XCTestExpectation *notificationExpectation =
  562. [self installationIDDidChangeNotificationExpectation];
  563. notificationExpectation.inverted = YES;
  564. // 5. Call delete installation.
  565. FBLPromise<NSNull *> *promise = [self.controller deleteInstallation];
  566. // 6. Wait for operations to complete and check.
  567. FBLWaitForPromisesWithTimeout(0.5);
  568. XCTAssertEqualObjects(promise.error, error500);
  569. XCTAssertTrue(promise.isRejected);
  570. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  571. OCMVerifyAll(self.mockInstallationsStore);
  572. OCMVerifyAll(self.mockAPIService);
  573. OCMVerifyAll(self.mockIIDStore);
  574. }
  575. - (void)testDeleteRegisteredInstallation_WhenAPIFailsWithNotFound_ThenInstallationIsRemoved {
  576. // 1. Expect installation to be requested from the store.
  577. FIRInstallationsItem *installation = [FIRInstallationsItem createRegisteredInstallationItem];
  578. OCMExpect([self.mockInstallationsStore installationForAppID:installation.appID
  579. appName:installation.firebaseAppName])
  580. .andReturn([FBLPromise resolvedWith:installation]);
  581. // 2. Expect API request to delete installation.
  582. FBLPromise *rejectedAPIPromise = [FBLPromise pendingPromise];
  583. [rejectedAPIPromise reject:[FIRInstallationsErrorUtil APIErrorWithHTTPCode:404]];
  584. OCMExpect([self.mockAPIService deleteInstallation:installation]).andReturn(rejectedAPIPromise);
  585. // 3. Expect the installation to be removed from the storage.
  586. OCMExpect([self.mockInstallationsStore removeInstallationForAppID:installation.appID
  587. appName:installation.firebaseAppName])
  588. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  589. // 3.2. Expect IID to be deleted, because it is default app.
  590. OCMExpect([self.mockIIDStore deleteExistingIID])
  591. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  592. // 4. Expect FIRInstallationIDDidChangeNotification to be sent.
  593. XCTestExpectation *notificationExpectation =
  594. [self installationIDDidChangeNotificationExpectation];
  595. // 5. Call delete installation.
  596. FBLPromise<NSNull *> *promise = [self.controller deleteInstallation];
  597. // 6. Wait for operations to complete and check.
  598. FBLWaitForPromisesWithTimeout(0.5);
  599. XCTAssertNil(promise.error);
  600. XCTAssertTrue(promise.isFulfilled);
  601. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  602. OCMVerifyAll(self.mockInstallationsStore);
  603. OCMVerifyAll(self.mockAPIService);
  604. OCMVerifyAll(self.mockIIDStore);
  605. }
  606. - (void)testDeleteInstallation_WhenThereIsOngoingAuthTokenRequest_ThenUsesItsResult {
  607. // 1. Stub mocks for auth token request.
  608. // 1.1. Expect installation to be requested from the store.
  609. FIRInstallationsItem *storedInstallation =
  610. [FIRInstallationsItem createRegisteredInstallationItem];
  611. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  612. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  613. // 1.2. Expect API request.
  614. FIRInstallationsItem *responseInstallation =
  615. [FIRInstallationsItem createRegisteredInstallationItem];
  616. responseInstallation.authToken.token =
  617. [responseInstallation.authToken.token stringByAppendingString:@"_new"];
  618. FBLPromise *pendingAuthTokenAPIPromise = [FBLPromise pendingPromise];
  619. OCMExpect([self.mockAPIService refreshAuthTokenForInstallation:storedInstallation])
  620. .andReturn(pendingAuthTokenAPIPromise);
  621. // 2. Send auth token request.
  622. [self.controller getAuthTokenForcingRefresh:YES];
  623. OCMVerifyAllWithDelay(self.mockInstallationsStore, 0.5);
  624. OCMVerifyAllWithDelay(self.mockAPIService, 0.5);
  625. // 3. Delete installation.
  626. // 3.1. Don't expect installation to be requested from the store.
  627. OCMReject([self.mockInstallationsStore installationForAppID:[OCMArg any] appName:[OCMArg any]]);
  628. // 3.2. Expect API request to delete the UPDATED installation.
  629. OCMExpect([self.mockAPIService deleteInstallation:responseInstallation])
  630. .andReturn([FBLPromise resolvedWith:responseInstallation]);
  631. // 3.3. Expect the UPDATED installation to be removed from the storage.
  632. OCMExpect([self.mockInstallationsStore
  633. removeInstallationForAppID:responseInstallation.appID
  634. appName:responseInstallation.firebaseAppName])
  635. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  636. // 3.4. Expect IID to be deleted, because it is default app.
  637. OCMExpect([self.mockIIDStore deleteExistingIID])
  638. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  639. // 3.4. Call delete installation.
  640. FBLPromise<NSNull *> *deletePromise = [self.controller deleteInstallation];
  641. // 4. Fulfill auth token promise to proceed.
  642. [pendingAuthTokenAPIPromise fulfill:responseInstallation];
  643. // 5. Wait for operations to complete and check the result.
  644. FBLWaitForPromisesWithTimeout(0.5);
  645. XCTAssertNil(deletePromise.error);
  646. XCTAssertTrue(deletePromise.isFulfilled);
  647. OCMVerifyAll(self.mockInstallationsStore);
  648. OCMVerifyAll(self.mockAPIService);
  649. OCMVerifyAll(self.mockIIDStore);
  650. }
  651. - (void)testDeleteInstallation_WhenNotDefaultApp_ThenIIDIsNotDeleted {
  652. // 0. Configure controller for not default app.
  653. NSString *appName = @"appName";
  654. [self setUpWithAppName:appName];
  655. // 1. Expect installation to be requested from the store.
  656. FIRInstallationsItem *installation =
  657. [FIRInstallationsItem createRegisteredInstallationItemWithAppID:self.appID appName:appName];
  658. OCMExpect([self.mockInstallationsStore installationForAppID:installation.appID
  659. appName:installation.firebaseAppName])
  660. .andReturn([FBLPromise resolvedWith:installation]);
  661. // 2. Expect API request to delete installation.
  662. OCMExpect([self.mockAPIService deleteInstallation:installation])
  663. .andReturn([FBLPromise resolvedWith:installation]);
  664. // 3.1. Expect the installation to be removed from the storage.
  665. OCMExpect([self.mockInstallationsStore removeInstallationForAppID:installation.appID
  666. appName:installation.firebaseAppName])
  667. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  668. // 3.2. Don't expect IID to be deleted, because it is not a default app.
  669. OCMReject([self.mockIIDStore deleteExistingIID]);
  670. // 4. Expect FIRInstallationIDDidChangeNotification to be sent.
  671. XCTestExpectation *notificationExpectation =
  672. [self installationIDDidChangeNotificationExpectation];
  673. // 5. Call delete installation.
  674. FBLPromise<NSNull *> *promise = [self.controller deleteInstallation];
  675. // 6. Wait for operations to complete and check.
  676. FBLWaitForPromisesWithTimeout(0.5);
  677. XCTAssertNil(promise.error);
  678. XCTAssertTrue(promise.isFulfilled);
  679. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  680. OCMVerifyAll(self.mockInstallationsStore);
  681. OCMVerifyAll(self.mockAPIService);
  682. OCMVerifyAll(self.mockIIDStore);
  683. }
  684. // TODO: Test a single delete installation request at a time.
  685. #pragma mark - Notifications
  686. - (void)testFIDDidChangeNotificationIsSentWhenFIDCreated {
  687. // 1. Stub - no installation.
  688. // 1.2. FID store.
  689. [self expectInstallationsStoreGetInstallationNotFound];
  690. OCMStub([self.mockInstallationsStore saveInstallation:[OCMArg any]])
  691. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  692. // 1.3. IID store.
  693. FBLPromise *rejectedPromise = [FBLPromise pendingPromise];
  694. [rejectedPromise reject:[FIRInstallationsErrorUtil keychainErrorWithFunction:@"" status:-1]];
  695. OCMExpect([self.mockIIDStore existingIID]).andReturn(rejectedPromise);
  696. // 1.4. API Service.
  697. OCMExpect([self.mockAPIService registerInstallation:[OCMArg any]])
  698. .andReturn([FBLPromise resolvedWith:[FIRInstallationsItem createRegisteredInstallationItem]]);
  699. // 2. Expect FIRInstallationIDDidChangeNotification to be sent.
  700. XCTestExpectation *notificationExpectation =
  701. [self installationIDDidChangeNotificationExpectation];
  702. // 3. Request FID.
  703. FBLPromise *promise = [self.controller getInstallationItem];
  704. FBLWaitForPromisesWithTimeout(0.5);
  705. // 4. Check.
  706. XCTAssertNil(promise.error);
  707. XCTAssertNotNil(promise.value);
  708. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  709. OCMVerifyAll(self.mockInstallationsStore);
  710. OCMVerifyAll(self.mockIIDStore);
  711. OCMVerifyAll(self.mockAPIService);
  712. }
  713. - (void)testRegisterInstallation_WhenServerRespondsWithDifferentFID_ThenFIDDidChangeNotification {
  714. // 1.1. Expect installation to be requested from the store.
  715. FIRInstallationsItem *storedInstallation =
  716. [FIRInstallationsItem createUnregisteredInstallationItem];
  717. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  718. .andReturn([FBLPromise resolvedWith:storedInstallation]);
  719. // 1.2. Expect register FID to be called.
  720. FIRInstallationsItem *receivedInstallation =
  721. [FIRInstallationsItem createRegisteredInstallationItem];
  722. receivedInstallation.firebaseInstallationID =
  723. [storedInstallation.firebaseInstallationID stringByAppendingString:@"_new"];
  724. OCMExpect([self.mockAPIService registerInstallation:storedInstallation])
  725. .andReturn([FBLPromise resolvedWith:receivedInstallation]);
  726. // 1.3. Expect the received installation to be stored.
  727. OCMExpect([self.mockInstallationsStore saveInstallation:receivedInstallation])
  728. .andReturn([FBLPromise resolvedWith:[NSNull null]]);
  729. // 2. Expect FIRInstallationIDDidChangeNotification to be sent.
  730. XCTestExpectation *notificationExpectation =
  731. [self installationIDDidChangeNotificationExpectation];
  732. // 3. Request Auth Token.
  733. FBLPromise<FIRInstallationsItem *> *promise = [self.controller getAuthTokenForcingRefresh:NO];
  734. XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
  735. // 4. Check.
  736. XCTAssertNil(promise.error);
  737. XCTAssertNotNil(promise.value);
  738. XCTAssertEqualObjects(promise.value.firebaseInstallationID,
  739. receivedInstallation.firebaseInstallationID);
  740. [self waitForExpectations:@[ notificationExpectation ] timeout:0.5];
  741. OCMVerifyAll(self.mockInstallationsStore);
  742. OCMVerifyAll(self.mockAPIService);
  743. }
  744. #pragma mark - Helpers
  745. - (void)expectInstallationsStoreGetInstallationNotFound {
  746. NSError *notFoundError =
  747. [FIRInstallationsErrorUtil installationItemNotFoundForAppID:self.appID appName:self.appName];
  748. FBLPromise *installationNotFoundPromise = [FBLPromise pendingPromise];
  749. [installationNotFoundPromise reject:notFoundError];
  750. OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName])
  751. .andReturn(installationNotFoundPromise);
  752. }
  753. - (void)assertValidCreatedInstallation:(FIRInstallationsItem *)installation {
  754. XCTAssertEqualObjects([installation class], [FIRInstallationsItem class]);
  755. XCTAssertEqualObjects(installation.appID, self.appID);
  756. XCTAssertEqualObjects(installation.firebaseAppName, self.appName);
  757. XCTAssertEqual(installation.registrationStatus, FIRInstallationStatusUnregistered);
  758. XCTAssertNotNil(installation.firebaseInstallationID);
  759. }
  760. - (XCTestExpectation *)installationIDDidChangeNotificationExpectation {
  761. XCTestExpectation *notificationExpectation = [self
  762. expectationForNotification:FIRInstallationIDDidChangeNotification
  763. object:nil
  764. handler:^BOOL(NSNotification *_Nonnull notification) {
  765. XCTAssertEqualObjects(
  766. notification
  767. .userInfo[kFIRInstallationIDDidChangeNotificationAppNameKey],
  768. self.appName);
  769. return YES;
  770. }];
  771. return notificationExpectation;
  772. }
  773. @end