@@ -187,11 +187,10 @@ - (void)testTokenShouldBeRefreshedIfCacheTokenNeedsToBeRefreshed {
187
187
[[[self .mockInstanceID stub ] andReturn: kToken ] cachedTokenIfAvailable ];
188
188
[[[self .mockTokenManager stub ] andReturnValue: @(YES )]
189
189
checkTokenRefreshPolicyWithIID: [OCMArg any ]];
190
- [[[self .mockInstanceID stub ] andDo: ^(NSInvocation *invocation){
191
- }] tokenWithAuthorizedEntity: [OCMArg any ]
192
- scope: [OCMArg any ]
193
- options: [OCMArg any ]
194
- handler: [OCMArg any ]];
190
+ [[self .mockInstanceID stub ] tokenWithAuthorizedEntity: [OCMArg any ]
191
+ scope: [OCMArg any ]
192
+ options: [OCMArg any ]
193
+ handler: [OCMArg any ]];
195
194
[self expectInstallationsInstallationIDWithFID: kToken error: nil ];
196
195
197
196
[self .mockInstanceID didCompleteConfigure ];
@@ -202,11 +201,10 @@ - (void)testTokenShouldBeRefreshedIfCacheTokenNeedsToBeRefreshed {
202
201
- (void )testTokenShouldBeRefreshedIfNoCacheTokenButAutoInitAllowed {
203
202
[[[self .mockInstanceID stub ] andReturn: nil ] cachedTokenIfAvailable ];
204
203
[[[self .mockInstanceID stub ] andReturnValue: @(YES )] isFCMAutoInitEnabled ];
205
- [[[self .mockInstanceID stub ] andDo: ^(NSInvocation *invocation){
206
- }] tokenWithAuthorizedEntity: [OCMArg any ]
207
- scope: [OCMArg any ]
208
- options: [OCMArg any ]
209
- handler: [OCMArg any ]];
204
+ [[self .mockInstanceID stub ] tokenWithAuthorizedEntity: [OCMArg any ]
205
+ scope: [OCMArg any ]
206
+ options: [OCMArg any ]
207
+ handler: [OCMArg any ]];
210
208
211
209
[self .mockInstanceID didCompleteConfigure ];
212
210
@@ -254,11 +252,10 @@ - (void)testTokenShouldBeRefreshedIfIIDAndTokenAreNotConsistent {
254
252
255
253
- (void )testTokenIsDeletedAlongWithIdentity {
256
254
[[[self .mockInstanceID stub ] andReturnValue: @(YES )] isFCMAutoInitEnabled ];
257
- [[[self .mockInstanceID stub ] andDo: ^(NSInvocation *invocation){
258
- }] tokenWithAuthorizedEntity: [OCMArg any ]
259
- scope: [OCMArg any ]
260
- options: [OCMArg any ]
261
- handler: [OCMArg any ]];
255
+ [[self .mockInstanceID stub ] tokenWithAuthorizedEntity: [OCMArg any ]
256
+ scope: [OCMArg any ]
257
+ options: [OCMArg any ]
258
+ handler: [OCMArg any ]];
262
259
263
260
[self .mockInstanceID deleteIdentityWithHandler: ^(NSError *_Nullable error) {
264
261
XCTAssertNil ([self .mockInstanceID token ]);
@@ -452,17 +449,17 @@ - (void)testAPNSTokenIsPrefixedCorrectlyForServerType {
452
449
serverTypeKey : @(NO ),
453
450
};
454
451
455
- [[[ self .mockTokenManager stub ] andDo: ^( NSInvocation *invocation){
456
- }] fetchNewTokenWithAuthorizedEntity: kAuthorizedEntity
457
- scope: kScope
458
- instanceID: [OCMArg any ]
459
- options: [OCMArg checkWithBlock: ^BOOL (id obj) {
460
- NSDictionary *options = (NSDictionary *)obj;
461
- XCTAssertTrue ([options[APNSKey] hasPrefix: @" p_" ]);
462
- XCTAssertFalse ([options[serverTypeKey] boolValue ]);
463
- return YES ;
464
- }]
465
- handler: OCMOCK_ANY];
452
+ [[self .mockTokenManager stub ]
453
+ fetchNewTokenWithAuthorizedEntity: kAuthorizedEntity
454
+ scope: kScope
455
+ instanceID: [OCMArg any ]
456
+ options: [OCMArg checkWithBlock: ^BOOL (id obj) {
457
+ NSDictionary *options = (NSDictionary *)obj;
458
+ XCTAssertTrue ([options[APNSKey] hasPrefix: @" p_" ]);
459
+ XCTAssertFalse ([options[serverTypeKey] boolValue ]);
460
+ return YES ;
461
+ }]
462
+ handler: OCMOCK_ANY];
466
463
467
464
[self .instanceID tokenWithAuthorizedEntity: kAuthorizedEntity
468
465
scope: kScope
@@ -638,7 +635,8 @@ - (void)testDefaultToken_callbackInvokedForUnchangedToken {
638
635
// will change. Normal stubbing will always return the initial pointer,
639
636
// which in this case is 0x0 (nil).
640
637
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
641
- [invocation setReturnValue: &cachedTokenInfo];
638
+ __autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
639
+ [invocation setReturnValue: &tokenInfo];
642
640
}] cachedTokenInfoWithAuthorizedEntity: kAuthorizedEntity scope: kFIRInstanceIDDefaultTokenScope ];
643
641
644
642
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
@@ -705,7 +703,8 @@ - (void)testDefaultTokenFetch_returnValidToken {
705
703
// will change. Normal stubbing will always return the initial pointer,
706
704
// which in this case is 0x0 (nil).
707
705
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
708
- [invocation setReturnValue: &cachedTokenInfo];
706
+ __autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
707
+ [invocation setReturnValue: &tokenInfo];
709
708
}] cachedTokenInfoWithAuthorizedEntity: kAuthorizedEntity scope: kFIRInstanceIDDefaultTokenScope ];
710
709
711
710
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
@@ -764,7 +763,8 @@ - (void)testDefaultTokenFetch_retryFetchToken {
764
763
// will change. Normal stubbing will always return the initial pointer,
765
764
// which in this case is 0x0 (nil).
766
765
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
767
- [invocation setReturnValue: &cachedTokenInfo];
766
+ __autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
767
+ [invocation setReturnValue: &tokenInfo];
768
768
}] cachedTokenInfoWithAuthorizedEntity: kAuthorizedEntity scope: kFIRInstanceIDDefaultTokenScope ];
769
769
770
770
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
@@ -841,7 +841,8 @@ - (void)testDefaultToken_multipleInvocations {
841
841
// will change. Normal stubbing will always return the initial pointer,
842
842
// which in this case is 0x0 (nil).
843
843
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
844
- [invocation setReturnValue: &cachedTokenInfo];
844
+ __autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
845
+ [invocation setReturnValue: &tokenInfo];
845
846
}] cachedTokenInfoWithAuthorizedEntity: kAuthorizedEntity scope: kFIRInstanceIDDefaultTokenScope ];
846
847
847
848
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
@@ -949,7 +950,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_Success {
949
950
__block FIRInstanceIDTokenHandler tokenHandler;
950
951
951
952
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
952
- [invocation getArgument: &tokenHandler atIndex: 6 ];
953
+ __unsafe_unretained FIRInstanceIDTokenHandler handler;
954
+ [invocation getArgument: &handler atIndex: 6 ];
955
+ tokenHandler = handler;
953
956
[fetchNewTokenExpectation fulfill ];
954
957
}] fetchNewTokenWithAuthorizedEntity: kAuthorizedEntity
955
958
scope: kFIRInstanceIDDefaultTokenScope
@@ -1005,7 +1008,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_RetrySuccess {
1005
1008
__block FIRInstanceIDTokenHandler tokenHandler;
1006
1009
1007
1010
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
1008
- [invocation getArgument: &tokenHandler atIndex: 6 ];
1011
+ __unsafe_unretained FIRInstanceIDTokenHandler handler;
1012
+ [invocation getArgument: &handler atIndex: 6 ];
1013
+ tokenHandler = handler;
1009
1014
[fetchNewTokenExpectations[fetchNewTokenCallCount] fulfill ];
1010
1015
fetchNewTokenCallCount += 1 ;
1011
1016
}] fetchNewTokenWithAuthorizedEntity: kAuthorizedEntity
@@ -1070,7 +1075,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_RetryFailure {
1070
1075
__block FIRInstanceIDTokenHandler tokenHandler;
1071
1076
1072
1077
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
1073
- [invocation getArgument: &tokenHandler atIndex: 6 ];
1078
+ __unsafe_unretained FIRInstanceIDTokenHandler handler;
1079
+ [invocation getArgument: &handler atIndex: 6 ];
1080
+ tokenHandler = handler;
1074
1081
[fetchNewTokenExpectations[fetchNewTokenCallCount] fulfill ];
1075
1082
fetchNewTokenCallCount += 1 ;
1076
1083
}] fetchNewTokenWithAuthorizedEntity: kAuthorizedEntity
@@ -1166,7 +1173,7 @@ - (void)testTokenFetchAPNSServerTypeIsIncludedIfAPNSTokenProvided {
1166
1173
1167
1174
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
1168
1175
// Inspect
1169
- NSDictionary *options;
1176
+ __unsafe_unretained NSDictionary *options;
1170
1177
[invocation getArgument: &options atIndex: 5 ];
1171
1178
if (options[kFIRInstanceIDTokenOptionsAPNSIsSandboxKey ] != nil ) {
1172
1179
[apnsServerTypeExpectation fulfill ];
@@ -1205,12 +1212,6 @@ - (void)testTokenFetch_ignoresCacheIfAPNSInfoDifferent {
1205
1212
// This token is |kToken|, but we will simulate that a fetch will return another token
1206
1213
NSString *oldCachedToken = kToken ;
1207
1214
NSString *fetchedToken = @" abcd123_newtoken" ;
1208
- __block FIRInstanceIDTokenInfo *cachedTokenInfo =
1209
- [[FIRInstanceIDTokenInfo alloc ] initWithAuthorizedEntity: kAuthorizedEntity
1210
- scope: kFIRInstanceIDDefaultTokenScope
1211
- token: oldCachedToken
1212
- appVersion: @" 1.0"
1213
- firebaseAppID: @" firebaseAppID" ];
1214
1215
1215
1216
[self stubInstallationsToReturnValidID ];
1216
1217
@@ -1223,7 +1224,13 @@ - (void)testTokenFetch_ignoresCacheIfAPNSInfoDifferent {
1223
1224
// will change. Normal stubbing will always return the initial pointer,
1224
1225
// which in this case is 0x0 (nil).
1225
1226
[[[self .mockTokenManager stub ] andDo: ^(NSInvocation *invocation) {
1226
- [invocation setReturnValue: &cachedTokenInfo];
1227
+ __autoreleasing FIRInstanceIDTokenInfo *tokenInfo =
1228
+ [[FIRInstanceIDTokenInfo alloc ] initWithAuthorizedEntity: kAuthorizedEntity
1229
+ scope: kFIRInstanceIDDefaultTokenScope
1230
+ token: oldCachedToken
1231
+ appVersion: @" 1.0"
1232
+ firebaseAppID: @" firebaseAppID" ];
1233
+ [invocation setReturnValue: &tokenInfo];
1227
1234
}] cachedTokenInfoWithAuthorizedEntity: kAuthorizedEntity scope: kFIRInstanceIDDefaultTokenScope ];
1228
1235
1229
1236
// Mock the network request to return |fetchedToken|, so we can clearly see if the token is
0 commit comments