2626// Test module imports
2727@import GoogleSignIn;
2828
29- #import " GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/GIDAuthorizationFlowProcessor .h"
29+ #import " GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/Fakes/GIDFakeAuthorizationFlowProcessor .h"
3030#import " GoogleSignIn/Sources/GIDEMMSupport.h"
3131#import " GoogleSignIn/Sources/GIDGoogleUser_Private.h"
3232#import " GoogleSignIn/Sources/GIDSignIn_Private.h"
3636#import " GoogleSignIn/Sources/GIDHTTPFetcher/Implementations/GIDHTTPFetcher.h"
3737#import " GoogleSignIn/Sources/GIDProfileDataFetcher/Implementations/GIDProfileDataFetcher.h"
3838
39-
4039#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
4140#import " GoogleSignIn/Sources/GIDEMMErrorHandler.h"
4241#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
@@ -203,6 +202,9 @@ @interface GIDSignInTest : XCTestCase {
203202 // Fake for |GIDHTTPFetcher|.
204203 GIDFakeHTTPFetcher *_httpFetcher;
205204
205+ // Fake for |GIDAuthorizationFlowProcessor|
206+ GIDFakeAuthorizationFlowProcessor *_authorizationFlowProcessor;
207+
206208#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
207209 // Mock |UIViewController|.
208210 id _presentingViewController;
@@ -289,14 +291,14 @@ - (void)setUp {
289291 OCMStub ([_authorization initWithAuthState: OCMOCK_ANY]).andReturn (_authorization);
290292 _user = OCMStrictClassMock ([GIDGoogleUser class ]);
291293 _oidAuthorizationService = OCMStrictClassMock ([OIDAuthorizationService class ]);
292- OCMStub ([_oidAuthorizationService
293- presentAuthorizationRequest: SAVE_TO_ARG_BLOCK (self ->_savedAuthorizationRequest)
294- #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
295- presentingViewController:SAVE_TO_ARG_BLOCK(self->_savedPresentingViewController)
296- #elif TARGET_OS_OSX
297- presentingWindow:SAVE_TO_ARG_BLOCK(self->_savedPresentingWindow)
298- #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
299- callback: COPY_TO_ARG_BLOCK (self ->_savedAuthorizationCallback)]);
294+ // OCMStub([_oidAuthorizationService
295+ // presentAuthorizationRequest:SAVE_TO_ARG_BLOCK(self->_savedAuthorizationRequest)
296+ // #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
297+ // presentingViewController:SAVE_TO_ARG_BLOCK(self->_savedPresentingViewController)
298+ // #elif TARGET_OS_OSX
299+ // presentingWindow:SAVE_TO_ARG_BLOCK(self->_savedPresentingWindow)
300+ // #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
301+ // callback:COPY_TO_ARG_BLOCK(self->_savedAuthorizationCallback)]);
300302 OCMStub ([self ->_oidAuthorizationService
301303 performTokenRequest: SAVE_TO_ARG_BLOCK (self ->_savedTokenRequest)
302304 callback: COPY_TO_ARG_BLOCK (self ->_savedTokenCallback)]);
@@ -314,15 +316,14 @@ - (void)setUp {
314316
315317 _httpFetcher = [[GIDFakeHTTPFetcher alloc ] init ];
316318
317- GIDAuthorizationFlowProcessor * authorizationFlowProcessor =
318- [[GIDAuthorizationFlowProcessor alloc ] init ];
319+ _authorizationFlowProcessor = [[GIDFakeAuthorizationFlowProcessor alloc ] init ];
319320
320321 id <GIDProfileDataFetcher> profileDataFetcher = [[GIDProfileDataFetcher alloc ] init ];
321322
322323 _signIn = [[GIDSignIn alloc ] initWithKeychainHandler: _keychainHandler
323324 httpFetcher: _httpFetcher
324325 profileDataFetcher: profileDataFetcher
325- authorizationFlowProcessor: authorizationFlowProcessor ];
326+ authorizationFlowProcessor: _authorizationFlowProcessor ];
326327
327328 _hint = nil ;
328329
@@ -343,7 +344,7 @@ - (void)tearDown {
343344 OCMVerifyAll (_tokenResponse);
344345 OCMVerifyAll (_tokenRequest);
345346 OCMVerifyAll (_user);
346- OCMVerifyAll (_oidAuthorizationService);
347+ // OCMVerifyAll(_oidAuthorizationService);
347348
348349#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
349350 OCMVerifyAll (_presentingViewController);
@@ -1215,6 +1216,34 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
12151216 refreshToken: kRefreshToken
12161217 codeVerifier: nil
12171218 additionalParameters: tokenResponse.request.additionalParameters];
1219+
1220+ // Simulate auth endpoint response
1221+ GIDAuthorizationFlowProcessorTestBlock testBlock;
1222+ if (modalCancel) {
1223+ NSError *error = [NSError errorWithDomain: OIDGeneralErrorDomain
1224+ code: OIDErrorCodeUserCanceledAuthorizationFlow
1225+ userInfo: nil ];
1226+ testBlock = ^(GIDAuthorizationFlowProcessorFakeResponseProviderBlock responseProvider) {
1227+ responseProvider (nil , error);
1228+ };
1229+ } else {
1230+ testBlock = ^(GIDAuthorizationFlowProcessorFakeResponseProviderBlock responseProvider) {
1231+ responseProvider (authResponse, nil );
1232+ };
1233+ }
1234+ _authorizationFlowProcessor.testBlock = testBlock;
1235+
1236+ // maybeFetchToken
1237+ if (!(authError || modalCancel)) {
1238+ [[[_authState expect ] andReturn: nil ] lastTokenResponse ];
1239+ #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1240+ // Corresponds to EMM support
1241+ [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1242+ #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1243+ [[[_authState expect ] andReturn: nil ] lastTokenResponse ];
1244+ [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1245+ [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1246+ }
12181247
12191248 if (restoredSignIn) {
12201249 // maybeFetchToken
@@ -1280,34 +1309,13 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
12801309 XCTAssertEqualObjects (params[@" include_granted_scopes" ], @" true" );
12811310 XCTAssertEqualObjects (params[kSDKVersionLoggingParameter ], GIDVersion ());
12821311 XCTAssertEqualObjects (params[kEnvironmentLoggingParameter ], GIDEnvironment ());
1283- XCTAssertNotNil (_savedAuthorizationCallback);
1312+ // XCTAssertNotNil(_savedAuthorizationCallback);
12841313#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
12851314 XCTAssertEqual (_savedPresentingViewController, _presentingViewController);
12861315#elif TARGET_OS_OSX
12871316 XCTAssertEqual (_savedPresentingWindow, _presentingWindow);
12881317#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
12891318
1290- // maybeFetchToken
1291- if (!(authError || modalCancel)) {
1292- [[[_authState expect ] andReturn: nil ] lastTokenResponse ];
1293- #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1294- // Corresponds to EMM support
1295- [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1296- #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1297- [[[_authState expect ] andReturn: nil ] lastTokenResponse ];
1298- [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1299- [[[_authState expect ] andReturn: authResponse] lastAuthorizationResponse ];
1300- }
1301-
1302- // Simulate auth endpoint response
1303- if (modalCancel) {
1304- NSError *error = [NSError errorWithDomain: OIDGeneralErrorDomain
1305- code: OIDErrorCodeUserCanceledAuthorizationFlow
1306- userInfo: nil ];
1307- _savedAuthorizationCallback (nil , error);
1308- } else {
1309- _savedAuthorizationCallback (authResponse, nil );
1310- }
13111319
13121320 if (authError || modalCancel) {
13131321 return ;
0 commit comments