Skip to content

Commit 8ed8504

Browse files
Rename ApplicationSupportDirectory in IID tests (#2553)
1 parent e524a8d commit 8ed8504

8 files changed

+45
-54
lines changed

Example/InstanceID/Tests/FIRInstanceIDAuthKeyChainTest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
static NSString *const kFIRInstanceIDTestKeychainId = @"com.google.iid-tests";
2525

2626
static NSString *const kFakeCheckinPlistName = @"com.google.test.IIDStoreTestCheckin";
27-
static NSString *const kApplicationSupportSubDirectoryName = @"FirebaseInstanceIDCheckinTest";
2827

2928
static NSString *const kAuthorizedEntity = @"test-audience";
3029
static NSString *const kScope = @"test-scope";

Example/InstanceID/Tests/FIRInstanceIDBackupExcludedPlistTest.m

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import "Firebase/InstanceID/FIRInstanceIDBackupExcludedPlist.h"
2222
#import "Firebase/InstanceID/FIRInstanceIDStore.h"
2323

24-
static NSString *const kApplicationSupportSubDirectoryName = @"FirebaseInstanceIDBackupPlistTest";
24+
static NSString *const kSubDirectoryName = @"FirebaseInstanceIDBackupPlistTest";
2525
static NSString *const kTestPlistFileName = @"com.google.test.IIDBackupExcludedPlist";
2626

2727
@interface FIRInstanceIDBackupExcludedPlist ()
@@ -38,15 +38,14 @@ @implementation FIRInstanceIDBackupExcludedPlistTest
3838

3939
- (void)setUp {
4040
[super setUp];
41-
[FIRInstanceIDStore createSubDirectory:kApplicationSupportSubDirectoryName];
42-
self.plist = [[FIRInstanceIDBackupExcludedPlist alloc]
43-
initWithFileName:kTestPlistFileName
44-
subDirectory:kApplicationSupportSubDirectoryName];
41+
[FIRInstanceIDStore createSubDirectory:kSubDirectoryName];
42+
self.plist = [[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kTestPlistFileName
43+
subDirectory:kSubDirectoryName];
4544
}
4645

4746
- (void)tearDown {
4847
[self.plist deleteFile:nil];
49-
[FIRInstanceIDStore removeSubDirectory:kApplicationSupportSubDirectoryName error:nil];
48+
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
5049
[super tearDown];
5150
}
5251

@@ -77,14 +76,14 @@ - (void)testWriteToPlistInApplicationSupportFolder {
7776
XCTAssertTrue([self.plist doesFileExist]);
7877
XCTAssertEqualObjects(plistContents, [self.plist contentAsDictionary]);
7978

80-
XCTAssertTrue([self isPlistInApplicationSupportDirectory]);
79+
XCTAssertTrue([self doesPlistFileExist]);
8180
}
8281

8382
- (void)testMovePlistToApplicationSupportDirectorySuccess {
8483
NSDictionary *plistContents = @{@"hello" : @"world", @"id" : @123};
8584
[self.plist writeDictionary:plistContents error:nil];
86-
[self.plist moveToApplicationSupportSubDirectory:kApplicationSupportSubDirectoryName];
87-
XCTAssertTrue([self isPlistInApplicationSupportDirectory]);
85+
[self.plist moveToApplicationSupportSubDirectory:kSubDirectoryName];
86+
XCTAssertTrue([self doesPlistFileExist]);
8887
XCTAssertFalse([self isPlistInDocumentsDirectory]);
8988

9089
NSDictionary *newPlistContents = @{@"world" : @"hello"};
@@ -97,19 +96,18 @@ - (void)testMovePlistToApplicationSupportDirectoryFailure {
9796
// which should only apply to iOS.
9897
#if TARGET_OS_IOS
9998
// Delete the subdirectory
100-
[FIRInstanceIDStore removeSubDirectory:kApplicationSupportSubDirectoryName error:nil];
99+
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
101100

102101
// Create a new plistl This would try to move or write to the ApplicationSupport directory
103102
// but since the subdirectory is not there anymore it will fail and rather write to the
104103
// Documents folder.
105-
self.plist = [[FIRInstanceIDBackupExcludedPlist alloc]
106-
initWithFileName:kTestPlistFileName
107-
subDirectory:kApplicationSupportSubDirectoryName];
104+
self.plist = [[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kTestPlistFileName
105+
subDirectory:kSubDirectoryName];
108106

109107
NSDictionary *plistContents = @{@"hello" : @"world", @"id" : @123};
110108
[self.plist writeDictionary:plistContents error:nil];
111109

112-
XCTAssertFalse([self isPlistInApplicationSupportDirectory]);
110+
XCTAssertFalse([self doesPlistFileExist]);
113111
XCTAssertTrue([self isPlistInDocumentsDirectory]);
114112

115113
NSDictionary *newPlistContents = @{@"world" : @"hello"};
@@ -118,36 +116,34 @@ - (void)testMovePlistToApplicationSupportDirectoryFailure {
118116
XCTAssertEqualObjects(newPlistContents, [self.plist contentAsDictionary]);
119117

120118
// The new file should still be written to the Documents folder.
121-
XCTAssertFalse([self isPlistInApplicationSupportDirectory]);
119+
XCTAssertFalse([self doesPlistFileExist]);
122120
XCTAssertTrue([self isPlistInDocumentsDirectory]);
123121
#endif
124122
}
125123

126124
#pragma mark - Private Helpers
127125

128-
- (BOOL)isPlistInApplicationSupportDirectory {
126+
- (BOOL)doesPlistFileExist {
129127
#if TARGET_OS_TV
130128
NSArray *directoryPaths =
131129
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
132130
#else
133131
NSArray *directoryPaths =
134132
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
135133
#endif
136-
NSString *applicationSupportDirPath = directoryPaths.lastObject;
137-
NSArray *components = @[
138-
applicationSupportDirPath, kApplicationSupportSubDirectoryName,
139-
[NSString stringWithFormat:@"%@.plist", kTestPlistFileName]
140-
];
134+
NSString *dirPath = directoryPaths.lastObject;
135+
NSArray *components =
136+
@[ dirPath, kSubDirectoryName, [NSString stringWithFormat:@"%@.plist", kTestPlistFileName] ];
141137
NSString *plistPath = [NSString pathWithComponents:components];
142138
return [[NSFileManager defaultManager] fileExistsAtPath:plistPath];
143139
}
144140

145141
- (BOOL)isPlistInDocumentsDirectory {
146142
NSArray *directoryPaths =
147143
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
148-
NSString *applicationSupportDirPath = directoryPaths.lastObject;
144+
NSString *documentsSupportDirPath = directoryPaths.lastObject;
149145
NSArray *components =
150-
@[ applicationSupportDirPath, [NSString stringWithFormat:@"%@.plist", kTestPlistFileName] ];
146+
@[ documentsSupportDirPath, [NSString stringWithFormat:@"%@.plist", kTestPlistFileName] ];
151147
NSString *plistPath = [NSString pathWithComponents:components];
152148
return [[NSFileManager defaultManager] fileExistsAtPath:plistPath];
153149
}

Example/InstanceID/Tests/FIRInstanceIDCheckinStoreTest.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ - (NSString *)bundleIdentifierForKeychainAccount;
3737

3838
// Testing constants
3939
static NSString *const kFakeCheckinPlistName = @"com.google.test.IIDStoreTestCheckin";
40-
static NSString *const kApplicationSupportSubDirectoryName = @"FirebaseInstanceIDCheckinTest";
40+
static NSString *const kSubDirectoryName = @"FirebaseInstanceIDCheckinTest";
4141

4242
static NSString *const kAuthorizedEntity = @"test-audience";
4343
static NSString *const kAuthID = @"test-auth-id";
@@ -56,7 +56,7 @@ @implementation FIRInstanceIDCheckinStoreTest
5656

5757
- (void)setUp {
5858
[super setUp];
59-
[FIRInstanceIDStore createSubDirectory:kApplicationSupportSubDirectoryName];
59+
[FIRInstanceIDStore createSubDirectory:kSubDirectoryName];
6060
}
6161

6262
- (void)tearDown {
@@ -65,7 +65,7 @@ - (void)tearDown {
6565
NSError *error;
6666
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
6767
}
68-
[FIRInstanceIDStore removeSubDirectory:kApplicationSupportSubDirectoryName error:nil];
68+
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
6969
[super tearDown];
7070
}
7171

@@ -75,9 +75,9 @@ - (void)tearDown {
7575
- (void)testInvalidCheckinPreferencesOnKeychainFail {
7676
XCTestExpectation *checkinInvalidExpectation = [self
7777
expectationWithDescription:@"Checkin preference should be invalid after keychain failure"];
78-
FIRInstanceIDBackupExcludedPlist *checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc]
79-
initWithFileName:kFakeCheckinPlistName
80-
subDirectory:kApplicationSupportSubDirectoryName];
78+
FIRInstanceIDBackupExcludedPlist *checkinPlist =
79+
[[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kFakeCheckinPlistName
80+
subDirectory:kSubDirectoryName];
8181

8282
FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
8383

@@ -108,9 +108,9 @@ - (void)testInvalidCheckinPreferencesOnKeychainFail {
108108
- (void)testCheckinSaveFailsOnKeychainWriteFailure {
109109
XCTestExpectation *checkinSaveFailsExpectation =
110110
[self expectationWithDescription:@"Checkin save should fail after keychain write failure"];
111-
FIRInstanceIDBackupExcludedPlist *checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc]
112-
initWithFileName:kFakeCheckinPlistName
113-
subDirectory:kApplicationSupportSubDirectoryName];
111+
FIRInstanceIDBackupExcludedPlist *checkinPlist =
112+
[[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kFakeCheckinPlistName
113+
subDirectory:kSubDirectoryName];
114114

115115
FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
116116
fakeKeychain.cannotWriteToKeychain = YES;
@@ -139,9 +139,9 @@ - (void)testCheckinMigrationMovesToNewLocationInKeychain {
139139
XCTestExpectation *checkinMigrationExpectation =
140140
[self expectationWithDescription:@"checkin migration should move to the new location"];
141141
// Create checkin store class.
142-
FIRInstanceIDBackupExcludedPlist *checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc]
143-
initWithFileName:kFakeCheckinPlistName
144-
subDirectory:kApplicationSupportSubDirectoryName];
142+
FIRInstanceIDBackupExcludedPlist *checkinPlist =
143+
[[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kFakeCheckinPlistName
144+
subDirectory:kSubDirectoryName];
145145

146146
FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
147147
FIRInstanceIDFakeKeychain *weakKeychain = fakeKeychain;

Example/InstanceID/Tests/FIRInstanceIDStoreTest.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#import "Firebase/InstanceID/FIRInstanceIDTokenStore.h"
2929
#import "Firebase/InstanceID/FIRInstanceIDUtilities.h"
3030

31-
static NSString *const kApplicationSupportSubDirectoryName = @"FirebaseInstanceIDStoreTest";
31+
static NSString *const kSubDirectoryName = @"FirebaseInstanceIDStoreTest";
3232

3333
static NSString *const kAuthorizedEntity = @"test-audience";
3434
static NSString *const kScope = @"test-scope";
@@ -74,12 +74,11 @@ @implementation FIRInstanceIDStoreTest
7474

7575
- (void)setUp {
7676
[super setUp];
77-
[FIRInstanceIDStore createSubDirectory:kApplicationSupportSubDirectoryName];
77+
[FIRInstanceIDStore createSubDirectory:kSubDirectoryName];
7878

7979
NSString *checkinPlistName = @"com.google.test.IIDStoreTestCheckin";
80-
self.checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc]
81-
initWithFileName:checkinPlistName
82-
subDirectory:kApplicationSupportSubDirectoryName];
80+
self.checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:checkinPlistName
81+
subDirectory:kSubDirectoryName];
8382

8483
// checkin store
8584
FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
@@ -103,7 +102,7 @@ - (void)setUp {
103102
- (void)tearDown {
104103
[self.instanceIDStore removeAllCachedTokensWithHandler:nil];
105104
[self.instanceIDStore removeCheckinPreferencesWithHandler:nil];
106-
[FIRInstanceIDStore removeSubDirectory:kApplicationSupportSubDirectoryName error:nil];
105+
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
107106
[_mockCheckinStore stopMocking];
108107
[_mockTokenStore stopMocking];
109108
[_mockInstanceIDStore stopMocking];

Example/InstanceID/Tests/FIRInstanceIDTokenManagerTest.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import "Firebase/InstanceID/FIRInstanceIDTokenOperation.h"
3131
#import "Firebase/InstanceID/FIRInstanceIDTokenStore.h"
3232

33-
static NSString *const kApplicationSupportSubDirectoryName = @"FirebaseInstanceIDTokenManagerTest";
33+
static NSString *const kSubDirectoryName = @"FirebaseInstanceIDTokenManagerTest";
3434

3535
static NSString *const kAuthorizedEntity = @"test-authorized-entity";
3636
static NSString *const kScope = @"test-scope";
@@ -91,12 +91,12 @@ @implementation FIRInstanceIDTokenManagerTest
9191

9292
- (void)setUp {
9393
[super setUp];
94-
[FIRInstanceIDStore createSubDirectory:kApplicationSupportSubDirectoryName];
94+
[FIRInstanceIDStore createSubDirectory:kSubDirectoryName];
9595

9696
NSString *checkinPlistFilename = @"com.google.test.IIDCheckinTest";
97-
self.checkinPlist = [[FIRInstanceIDBackupExcludedPlist alloc]
98-
initWithFileName:checkinPlistFilename
99-
subDirectory:kApplicationSupportSubDirectoryName];
97+
self.checkinPlist =
98+
[[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:checkinPlistFilename
99+
subDirectory:kSubDirectoryName];
100100

101101
// checkin store
102102
FIRInstanceIDFakeKeychain *fakeCheckinKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
@@ -123,7 +123,7 @@ - (void)tearDown {
123123
}
124124

125125
self.tokenManager = nil;
126-
[FIRInstanceIDStore removeSubDirectory:kApplicationSupportSubDirectoryName error:nil];
126+
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
127127
[super tearDown];
128128
}
129129

Firebase/InstanceID/FIRInstanceID.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ - (void)dealloc {
175175
[[NSNotificationCenter defaultCenter] removeObserver:self];
176176
}
177177

178-
- (void)stopAllRequests {
179-
[self.tokenManager stopAllTokenOperations];
180-
}
181-
182178
#pragma mark - Tokens
183179

184180
- (NSString *)token {

Firebase/InstanceID/FIRInstanceIDBackupExcludedPlist.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ - (NSDictionary *)contentAsDictionary {
111111
- (BOOL)moveToApplicationSupportSubDirectory:(NSString *)subDirectoryName {
112112
NSArray *directoryPaths =
113113
NSSearchPathForDirectoriesInDomains([self supportedDirectory], NSUserDomainMask, YES);
114+
// This only going to happen inside iOS so it is an applicationSupportDirectory.
114115
NSString *applicationSupportDirPath = directoryPaths.lastObject;
115116
NSArray *components = @[ applicationSupportDirPath, subDirectoryName ];
116117
NSString *subDirectoryPath = [NSString pathWithComponents:components];

Firebase/Messaging/FIRMessaging.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@ + (BOOL)hasSubDirectory:(NSString *)subDirectoryName {
985985
+ (NSString *)pathForSubDirectory:(NSString *)subDirectoryName {
986986
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(FIRMessagingSupportedDirectory(),
987987
NSUserDomainMask, YES);
988-
NSString *applicationSupportDirPath = directoryPaths.lastObject;
989-
NSArray *components = @[applicationSupportDirPath, subDirectoryName];
988+
NSString *dirPath = directoryPaths.lastObject;
989+
NSArray *components = @[dirPath, subDirectoryName];
990990
return [NSString pathWithComponents:components];
991991
}
992992

0 commit comments

Comments
 (0)