@@ -1320,7 +1320,7 @@ - (void)testCanClearPersistenceAfterRestarting {
1320
1320
[self terminateFirestore: firestore];
1321
1321
[self .firestores removeObject: firestore];
1322
1322
[firestore
1323
- clearPersistenceWithCompletion: [self completionForExpectationWithName: @" Enable network " ]];
1323
+ clearPersistenceWithCompletion: [self completionForExpectationWithName: @" ClearPersistence " ]];
1324
1324
[self awaitExpectations ];
1325
1325
[self deleteApp: app];
1326
1326
@@ -1342,6 +1342,42 @@ - (void)testCanClearPersistenceAfterRestarting {
1342
1342
[self awaitExpectations ];
1343
1343
}
1344
1344
1345
+ - (void )testCanClearPersistenceOnANewFirestoreInstance {
1346
+ FIRDocumentReference *doc = [self documentRef ];
1347
+ FIRFirestore *firestore = doc.firestore ;
1348
+ FIRApp *app = firestore.app ;
1349
+ NSString *appName = app.name ;
1350
+ FIROptions *options = app.options ;
1351
+
1352
+ NSDictionary <NSString *, id > *initialData = @{@" foo" : @" 42" };
1353
+ [self writeDocumentRef: doc data: initialData];
1354
+
1355
+ [firestore terminateWithCompletion: [self completionForExpectationWithName: @" Terminate" ]];
1356
+ [self .firestores removeObject: firestore];
1357
+ [self awaitExpectations ];
1358
+ [self deleteApp: app];
1359
+
1360
+ // We restart the app with the same name and options to check that the previous instance's
1361
+ // persistent storage is actually cleared after the restart. Calling [self firestore] here would
1362
+ // create a new instance of firestore, which defeats the purpose of this test.
1363
+ [FIRApp configureWithName: appName options: options];
1364
+ FIRApp *app2 = [FIRApp appNamed: appName];
1365
+ FIRFirestore *firestore2 = [self firestoreWithApp: app2];
1366
+ [firestore2
1367
+ clearPersistenceWithCompletion: [self completionForExpectationWithName: @" ClearPersistence" ]];
1368
+ [self awaitExpectations ];
1369
+ FIRDocumentReference *docRef2 = [firestore2 documentWithPath: doc.path];
1370
+ XCTestExpectation *expectation2 = [self expectationWithDescription: @" getData" ];
1371
+ [docRef2 getDocumentWithSource: FIRFirestoreSourceCache
1372
+ completion: ^(FIRDocumentSnapshot *, NSError *_Nullable error) {
1373
+ XCTAssertNotNil (error);
1374
+ XCTAssertEqualObjects (error.domain , FIRFirestoreErrorDomain);
1375
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeUnavailable);
1376
+ [expectation2 fulfill ];
1377
+ }];
1378
+ [self awaitExpectations ];
1379
+ }
1380
+
1345
1381
- (void )testClearPersistenceWhileRunningFails {
1346
1382
FIRDocumentReference *doc = [self documentRef ];
1347
1383
FIRFirestore *firestore = doc.firestore ;
0 commit comments