@@ -283,9 +283,16 @@ - (void)testCredentialWithVerificationID {
283283 number was provided.
284284 */
285285- (void )testVerifyEmptyPhoneNumber {
286+ id mockBundle = OCMClassMock ([NSBundle class ]);
287+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
288+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
289+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
290+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
291+
286292 // Empty phone number is checked on the client side so no backend RPC is mocked.
287293 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
288294 [_provider verifyPhoneNumber: @" "
295+ UIDelegate: nil
289296 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
290297 XCTAssertNotNil (error);
291298 XCTAssertEqual (error.code , FIRAuthErrorCodeMissingPhoneNumber);
@@ -299,6 +306,12 @@ - (void)testVerifyEmptyPhoneNumber {
299306 number was provided.
300307 */
301308- (void )testVerifyInvalidPhoneNumber {
309+ id mockBundle = OCMClassMock ([NSBundle class ]);
310+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
311+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
312+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
313+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
314+
302315 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
303316 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
304317 OCMStub ([_mockAppCredentialManager credential ])
@@ -316,6 +329,7 @@ - (void)testVerifyInvalidPhoneNumber {
316329
317330 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
318331 [_provider verifyPhoneNumber: kTestPhoneNumber
332+ UIDelegate: nil
319333 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
320334 XCTAssertTrue ([NSThread isMainThread ]);
321335 XCTAssertNil (verificationID);
@@ -332,6 +346,12 @@ - (void)testVerifyInvalidPhoneNumber {
332346 @brief Tests a successful invocation of @c verifyPhoneNumber:completion:.
333347 */
334348- (void )testVerifyPhoneNumber {
349+ id mockBundle = OCMClassMock ([NSBundle class ]);
350+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
351+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
352+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
353+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
354+
335355 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
336356 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
337357 OCMStub ([_mockAppCredentialManager credential ])
@@ -351,6 +371,7 @@ - (void)testVerifyPhoneNumber {
351371
352372 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
353373 [_provider verifyPhoneNumber: kTestPhoneNumber
374+ UIDelegate: nil
354375 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
355376 XCTAssertTrue ([NSThread isMainThread ]);
356377 XCTAssertNil (error);
@@ -368,6 +389,12 @@ - (void)testVerifyPhoneNumber {
368389 is disabled.
369390 */
370391- (void )testVerifyPhoneNumberInTestMode {
392+ id mockBundle = OCMClassMock ([NSBundle class ]);
393+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
394+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
395+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
396+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
397+
371398 // Disable app verification.
372399 FIRAuthSettings *settings = [[FIRAuthSettings alloc ] init ];
373400 settings.appVerificationDisabledForTesting = YES ;
@@ -389,6 +416,7 @@ - (void)testVerifyPhoneNumberInTestMode {
389416
390417 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
391418 [_provider verifyPhoneNumber: kTestPhoneNumber
419+ UIDelegate: nil
392420 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
393421 XCTAssertTrue ([NSThread isMainThread ]);
394422 XCTAssertNil (error);
@@ -406,6 +434,12 @@ - (void)testVerifyPhoneNumberInTestMode {
406434 is disabled.
407435 */
408436- (void )testVerifyPhoneNumberInTestModeFailure {
437+ id mockBundle = OCMClassMock ([NSBundle class ]);
438+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
439+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
440+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
441+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
442+
409443 // Disable app verification.
410444 FIRAuthSettings *settings = [[FIRAuthSettings alloc ] init ];
411445 settings.appVerificationDisabledForTesting = YES ;
@@ -425,6 +459,7 @@ - (void)testVerifyPhoneNumberInTestModeFailure {
425459
426460 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
427461 [_provider verifyPhoneNumber: kTestPhoneNumber
462+ UIDelegate: nil
428463 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
429464 XCTAssertTrue ([NSThread isMainThread ]);
430465 XCTAssertNil (verificationID);
@@ -901,10 +936,17 @@ - (void)testVerifyPhoneNumberUIDelegateRaiseException {
901936 @brief Tests returning an error for the app failing to forward notification.
902937 */
903938- (void )testNotForwardingNotification {
939+ id mockBundle = OCMClassMock ([NSBundle class ]);
940+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
941+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
942+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
943+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
944+
904945 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
905946 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (NO ); });
906947 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
907948 [_provider verifyPhoneNumber: kTestPhoneNumber
949+ UIDelegate: nil
908950 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
909951 XCTAssertTrue ([NSThread isMainThread ]);
910952 XCTAssertNil (verificationID);
@@ -919,43 +961,77 @@ - (void)testNotForwardingNotification {
919961 @brief Tests returning an error for the app failing to provide an APNS device token.
920962 */
921963- (void )testMissingAPNSToken {
964+ id mockBundle = OCMClassMock ([NSBundle class ]);
965+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
966+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
967+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
968+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
969+
970+ // Simulate missing app token error.
922971 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
923972 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
924973 OCMExpect ([_mockAppCredentialManager credential ]).andReturn (nil );
925974 OCMExpect ([_mockAPNSTokenManager getTokenWithCallback: OCMOCK_ANY])
926- .andCallBlock1 (^(FIRAuthAPNSTokenCallback callback) { callback (nil , nil ); });
927- // Expect verify client request to the backend wth empty token.
928- OCMExpect ([_mockBackend verifyClient: [OCMArg any ] callback: [OCMArg any ]])
929- .andCallBlock2 (^(FIRVerifyClientRequest *request,
930- FIRVerifyClientResponseCallback callback) {
931- XCTAssertNil (request.appToken );
975+ .andCallBlock1 (^(FIRAuthAPNSTokenCallback callback) {
976+ NSError *error = [NSError errorWithDomain: FIRAuthErrorDomain
977+ code: FIRAuthErrorCodeMissingAppToken
978+ userInfo: nil ];
979+ callback (nil , error);
980+ });
981+ OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
982+ .andCallBlock2 (^(FIRGetProjectConfigRequest *request,
983+ FIRGetProjectConfigResponseCallback callback) {
984+ XCTAssertNotNil (request);
985+ dispatch_async (FIRAuthGlobalWorkQueue (), ^() {
986+ id mockGetProjectConfigResponse = OCMClassMock ([FIRGetProjectConfigResponse class ]);
987+ OCMStub ([mockGetProjectConfigResponse authorizedDomains ]).
988+ andReturn (@[ kFakeAuthorizedDomain ]);
989+ callback (mockGetProjectConfigResponse, nil );
990+ });
991+ });
992+ id mockUIDelegate = OCMProtocolMock (@protocol (FIRAuthUIDelegate));
993+
994+ // Expect view controller presentation by UIDelegate.
995+ OCMExpect ([_mockURLPresenter presentURL: OCMOCK_ANY
996+ UIDelegate: mockUIDelegate
997+ callbackMatcher: OCMOCK_ANY
998+ completion: OCMOCK_ANY]).andDo (^(NSInvocation *invocation) {
999+ __unsafe_unretained id unretainedArgument;
1000+ // Indices 0 and 1 indicate the hidden arguments self and _cmd.
1001+ // `completion` is at index 5
1002+ [invocation getArgument: &unretainedArgument atIndex: 5 ];
1003+ FIRAuthURLPresentationCompletion completion = unretainedArgument;
9321004 dispatch_async (FIRAuthGlobalWorkQueue (), ^() {
933- // The backend is supposed to return an error.
934- callback (nil , [NSError errorWithDomain: FIRAuthErrorDomain
1005+ completion (nil , [NSError errorWithDomain: FIRAuthErrorDomain
9351006 code: FIRAuthErrorCodeMissingAppToken
9361007 userInfo: nil ]);
9371008 });
9381009 });
9391010
9401011 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
9411012 [_provider verifyPhoneNumber: kTestPhoneNumber
1013+ UIDelegate: mockUIDelegate
9421014 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
9431015 XCTAssertTrue ([NSThread isMainThread ]);
944- XCTAssertNil (verificationID);
945- XCTAssertEqualObjects (error.domain , FIRAuthErrorDomain);
9461016 XCTAssertEqual (error.code , FIRAuthErrorCodeMissingAppToken);
1017+ XCTAssertNil (verificationID);
9471018 [expectation fulfill ];
9481019 }];
9491020 [self waitForExpectationsWithTimeout: kExpectationTimeout handler: nil ];
1021+ OCMVerifyAll (_mockBackend);
9501022 OCMVerifyAll (_mockNotificationManager);
951- OCMVerifyAll (_mockAppCredentialManager);
952- OCMVerifyAll (_mockAPNSTokenManager);
9531023}
9541024
9551025/* * @fn testVerifyClient
9561026 @brief Tests verifying client before sending verification code.
9571027 */
9581028- (void )testVerifyClient {
1029+ id mockBundle = OCMClassMock ([NSBundle class ]);
1030+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
1031+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
1032+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1033+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
1034+
9591035 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
9601036 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
9611037 OCMExpect ([_mockAppCredentialManager credential ]).andReturn (nil );
@@ -1007,6 +1083,7 @@ - (void)testVerifyClient {
10071083
10081084 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
10091085 [_provider verifyPhoneNumber: kTestPhoneNumber
1086+ UIDelegate: nil
10101087 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
10111088 XCTAssertTrue ([NSThread isMainThread ]);
10121089 XCTAssertNil (error);
@@ -1024,6 +1101,12 @@ - (void)testVerifyClient {
10241101 @brief Tests failed retry after failing to send verification code.
10251102 */
10261103- (void )testSendVerificationCodeFailedRetry {
1104+ id mockBundle = OCMClassMock ([NSBundle class ]);
1105+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
1106+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
1107+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1108+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
1109+
10271110 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
10281111 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
10291112
@@ -1097,6 +1180,7 @@ - (void)testSendVerificationCodeFailedRetry {
10971180
10981181 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
10991182 [_provider verifyPhoneNumber: kTestPhoneNumber
1183+ UIDelegate: nil
11001184 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
11011185 XCTAssertTrue ([NSThread isMainThread ]);
11021186 XCTAssertNil (verificationID);
@@ -1114,6 +1198,12 @@ - (void)testSendVerificationCodeFailedRetry {
11141198 @brief Tests successful retry after failing to send verification code.
11151199 */
11161200- (void )testSendVerificationCodeSuccessFulRetry {
1201+ id mockBundle = OCMClassMock ([NSBundle class ]);
1202+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
1203+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ])
1204+ .andReturn (@[ @{ @" CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1205+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
1206+
11171207 OCMExpect ([_mockNotificationManager checkNotificationForwardingWithCallback: OCMOCK_ANY])
11181208 .andCallBlock1 (^(FIRAuthNotificationForwardingCallback callback) { callback (YES ); });
11191209
@@ -1189,6 +1279,7 @@ - (void)testSendVerificationCodeSuccessFulRetry {
11891279
11901280 XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
11911281 [_provider verifyPhoneNumber: kTestPhoneNumber
1282+ UIDelegate: nil
11921283 completion: ^(NSString *_Nullable verificationID, NSError *_Nullable error) {
11931284 XCTAssertNil (error);
11941285 XCTAssertEqualObjects (verificationID, kTestVerificationID );
0 commit comments