@@ -720,73 +720,67 @@ TEST_F(FirebaseAuthTest, TestWithCustomEmailAndPassword) {
720
720
}
721
721
722
722
TEST_F (FirebaseAuthTest, TestAuthPersistenceWithAnonymousSignin) {
723
- // Test is disabled on linux due to the need to unlock the keystore.
723
+ // Automated test is disabled on linux due to the need to unlock the keystore.
724
724
SKIP_TEST_ON_LINUX;
725
- if (!RunFlakyBlock ([&]() {
726
- FLAKY_WAIT_FOR_COMPLETION (auth_->SignInAnonymously (),
727
- " SignInAnonymously" );
728
- FLAKY_EXPECT_NONNULL (auth_->current_user ());
729
- FLAKY_EXPECT_TRUE (auth_->current_user ()->is_anonymous ());
730
- Terminate ();
731
- ProcessEvents (2000 );
732
- Initialize ();
733
- FLAKY_EXPECT_NONNULL (auth_);
734
- FLAKY_EXPECT_NONNULL (auth_->current_user ());
735
- FLAKY_EXPECT_TRUE (auth_->current_user ()->is_anonymous ());
736
- DeleteUser ();
737
-
738
- FLAKY_SUCCESS ();
739
- })) {
740
- FAIL () << " Test failed, see log for details." ;
741
- }
725
+
726
+ FLAKY_TEST_SECTION_BEGIN ();
727
+
728
+ WaitForCompletion (auth_->SignInAnonymously (), " SignInAnonymously" );
729
+ EXPECT_NE (auth_->current_user (), nullptr );
730
+ EXPECT_TRUE (auth_->current_user ()->is_anonymous ());
731
+ Terminate ();
732
+ ProcessEvents (2000 );
733
+ Initialize ();
734
+ EXPECT_NE (auth_, nullptr );
735
+ EXPECT_NE (auth_->current_user (), nullptr );
736
+ EXPECT_TRUE (auth_->current_user ()->is_anonymous ());
737
+ DeleteUser ();
738
+
739
+ FLAKY_TEST_SECTION_END ();
742
740
}
743
741
TEST_F (FirebaseAuthTest, TestAuthPersistenceWithEmailSignin) {
744
- // Test is disabled on linux due to the need to unlock the keystore.
742
+ // Automated test is disabled on linux due to the need to unlock the keystore.
745
743
SKIP_TEST_ON_LINUX;
746
744
747
- if (!RunFlakyBlock ([&]() {
748
- std::string email = GenerateEmailAddress ();
749
- FLAKY_WAIT_FOR_COMPLETION (
750
- auth_->CreateUserWithEmailAndPassword (email.c_str (), kTestPassword ),
751
- " CreateUserWithEmailAndPassword" );
752
- FLAKY_EXPECT_NONNULL (auth_->current_user ());
753
- FLAKY_EXPECT_FALSE (auth_->current_user ()->is_anonymous ());
754
- std::string prev_provider_id = auth_->current_user ()->provider_id ();
755
- // Save the old provider ID list so we can make sure it's the same once
756
- // it's loaded again.
757
- std::vector<std::string> prev_provider_data_ids;
758
- for (int i = 0 ; i < auth_->current_user ()->provider_data ().size ();
759
- i++) {
760
- prev_provider_data_ids.push_back (
761
- auth_->current_user ()->provider_data ()[i]->provider_id ());
762
- }
763
- Terminate ();
764
- ProcessEvents (2000 );
765
- Initialize ();
766
- FLAKY_EXPECT_NONNULL (auth_);
767
- FLAKY_EXPECT_NONNULL (auth_->current_user ());
768
- FLAKY_EXPECT_FALSE (auth_->current_user ()->is_anonymous ());
769
- // Make sure the provider IDs are the same as they were before.
770
- FLAKY_EXPECT_EQ (auth_->current_user ()->provider_id (), prev_provider_id);
771
- std::vector<std::string> loaded_provider_data_ids;
772
- for (int i = 0 ; i < auth_->current_user ()->provider_data ().size ();
773
- i++) {
774
- loaded_provider_data_ids.push_back (
775
- auth_->current_user ()->provider_data ()[i]->provider_id ());
776
- }
777
- FLAKY_EXPECT_TRUE (loaded_provider_data_ids == prev_provider_data_ids);
778
-
779
- // Cleanup, ensure we are signed in as the user so we can delete it.
780
- FLAKY_WAIT_FOR_COMPLETION (
781
- auth_->SignInWithEmailAndPassword (email.c_str (), kTestPassword ),
782
- " SignInWithEmailAndPassword" );
783
- FLAKY_EXPECT_NONNULL (auth_->current_user ());
784
- DeleteUser ();
785
-
786
- FLAKY_SUCCESS ();
787
- })) {
788
- FAIL () << " Test failed, see log for details." ;
745
+ FLAKY_TEST_SECTION_BEGIN ();
746
+
747
+ std::string email = GenerateEmailAddress ();
748
+ WaitForCompletion (
749
+ auth_->CreateUserWithEmailAndPassword (email.c_str (), kTestPassword ),
750
+ " CreateUserWithEmailAndPassword" );
751
+ EXPECT_NE (auth_->current_user (), nullptr );
752
+ EXPECT_FALSE (auth_->current_user ()->is_anonymous ());
753
+ std::string prev_provider_id = auth_->current_user ()->provider_id ();
754
+ // Save the old provider ID list so we can make sure it's the same once
755
+ // it's loaded again.
756
+ std::vector<std::string> prev_provider_data_ids;
757
+ for (int i = 0 ; i < auth_->current_user ()->provider_data ().size (); i++) {
758
+ prev_provider_data_ids.push_back (
759
+ auth_->current_user ()->provider_data ()[i]->provider_id ());
760
+ }
761
+ Terminate ();
762
+ ProcessEvents (2000 );
763
+ Initialize ();
764
+ EXPECT_NE (auth_, nullptr );
765
+ EXPECT_NE (auth_->current_user (), nullptr );
766
+ EXPECT_FALSE (auth_->current_user ()->is_anonymous ());
767
+ // Make sure the provider IDs are the same as they were before.
768
+ EXPECT_EQ (auth_->current_user ()->provider_id (), prev_provider_id);
769
+ std::vector<std::string> loaded_provider_data_ids;
770
+ for (int i = 0 ; i < auth_->current_user ()->provider_data ().size (); i++) {
771
+ loaded_provider_data_ids.push_back (
772
+ auth_->current_user ()->provider_data ()[i]->provider_id ());
789
773
}
774
+ EXPECT_TRUE (loaded_provider_data_ids == prev_provider_data_ids);
775
+
776
+ // Cleanup, ensure we are signed in as the user so we can delete it.
777
+ WaitForCompletion (
778
+ auth_->SignInWithEmailAndPassword (email.c_str (), kTestPassword ),
779
+ " SignInWithEmailAndPassword" );
780
+ EXPECT_NE (auth_->current_user (), nullptr );
781
+ DeleteUser ();
782
+
783
+ FLAKY_TEST_SECTION_END ();
790
784
}
791
785
792
786
class PhoneListener : public firebase ::auth::PhoneAuthProvider::Listener {
@@ -873,67 +867,63 @@ TEST_F(FirebaseAuthTest, TestPhoneAuth) {
873
867
// Note: This test requires interactivity on iOS, as it displays a CAPTCHA.
874
868
TEST_REQUIRES_USER_INTERACTION;
875
869
#endif // TARGET_OS_IPHONE
876
- if (!RunFlakyBlock ([&]() {
877
- {
878
- firebase::auth::PhoneAuthProvider& phone_provider =
879
- firebase::auth::PhoneAuthProvider::GetInstance (auth_);
880
- LogDebug (" Creating listener." );
881
- PhoneListener listener;
882
- LogDebug (" Calling VerifyPhoneNumber." );
883
- // Randomly choose one of the phone numbers to avoid collisions.
884
- const int random_phone_number =
885
- app_framework::GetCurrentTimeInMicroseconds () %
886
- kPhoneAuthTestNumPhoneNumbers ;
887
- phone_provider.VerifyPhoneNumber (
888
- kPhoneAuthTestPhoneNumbers [random_phone_number],
889
- kPhoneAuthTimeoutMs , nullptr , &listener);
890
- // Wait for OnCodeSent() callback.
891
- int wait_ms = 0 ;
892
- LogDebug (" Waiting for code send." );
893
- while (listener.waiting_to_send_code ()) {
894
- if (wait_ms > kPhoneAuthCodeSendWaitMs ) break ;
895
- ProcessEvents (kWaitIntervalMs );
896
- wait_ms += kWaitIntervalMs ;
897
- }
898
- FLAKY_EXPECT_EQ (listener.on_verification_failed_count (), 0 );
899
- LogDebug (" Waiting for verification ID." );
900
- // Wait for the listener to have a verification ID.
901
- wait_ms = 0 ;
902
- while (listener.waiting_for_verification_id ()) {
903
- if (wait_ms > kPhoneAuthCompletionWaitMs ) break ;
904
- ProcessEvents (kWaitIntervalMs );
905
- wait_ms += kWaitIntervalMs ;
906
- }
907
- if (listener.on_verification_complete_count () > 0 ) {
908
- LogDebug (" Signing in with automatic verification code." );
909
- FLAKY_WAIT_FOR_COMPLETION (
910
- auth_->SignInWithCredential (listener.credential ()),
911
- " SignInWithCredential(PhoneCredential) automatic" );
912
- } else if (listener.on_verification_failed_count () > 0 ) {
913
- LogError (" Automatic verification failed." );
914
- FLAKY_FAIL ();
915
- } else {
916
- // Did not automatically verify, submit verification code manually.
917
- FLAKY_EXPECT_TRUE (listener.on_code_auto_retrieval_time_out_count () >
918
- 0 );
919
- FLAKY_EXPECT_NE (listener.verification_id (), " " );
920
- LogDebug (" Signing in with verification code." );
921
- const firebase::auth::Credential phone_credential =
922
- phone_provider.GetCredential (listener.verification_id ().c_str (),
923
- kPhoneAuthTestVerificationCode );
924
-
925
- FLAKY_WAIT_FOR_COMPLETION (
926
- auth_->SignInWithCredential (phone_credential),
927
- " SignInWithCredential(PhoneCredential)" );
928
- }
929
- }
930
- ProcessEvents (1000 );
931
- DeleteUser ();
932
870
933
- FLAKY_SUCCESS ();
934
- })) {
935
- FAIL () << " Phone auth failed, see log for details." ;
871
+ FLAKY_TEST_SECTION_BEGIN ();
872
+
873
+ firebase::auth::PhoneAuthProvider& phone_provider =
874
+ firebase::auth::PhoneAuthProvider::GetInstance (auth_);
875
+ LogDebug (" Creating listener." );
876
+ PhoneListener listener;
877
+ LogDebug (" Calling VerifyPhoneNumber." );
878
+ // Randomly choose one of the phone numbers to avoid collisions.
879
+ const int random_phone_number =
880
+ app_framework::GetCurrentTimeInMicroseconds () %
881
+ kPhoneAuthTestNumPhoneNumbers ;
882
+ phone_provider.VerifyPhoneNumber (
883
+ kPhoneAuthTestPhoneNumbers [random_phone_number], kPhoneAuthTimeoutMs ,
884
+ nullptr , &listener);
885
+
886
+ // Wait for OnCodeSent() callback.
887
+ int wait_ms = 0 ;
888
+ LogDebug (" Waiting for code send." );
889
+ while (listener.waiting_to_send_code ()) {
890
+ if (wait_ms > kPhoneAuthCodeSendWaitMs ) break ;
891
+ ProcessEvents (kWaitIntervalMs );
892
+ wait_ms += kWaitIntervalMs ;
893
+ }
894
+ EXPECT_EQ (listener.on_verification_failed_count (), 0 );
895
+
896
+ LogDebug (" Waiting for verification ID." );
897
+ // Wait for the listener to have a verification ID.
898
+ wait_ms = 0 ;
899
+ while (listener.waiting_for_verification_id ()) {
900
+ if (wait_ms > kPhoneAuthCompletionWaitMs ) break ;
901
+ ProcessEvents (kWaitIntervalMs );
902
+ wait_ms += kWaitIntervalMs ;
936
903
}
904
+ if (listener.on_verification_complete_count () > 0 ) {
905
+ LogDebug (" Signing in with automatic verification code." );
906
+ WaitForCompletion (auth_->SignInWithCredential (listener.credential ()),
907
+ " SignInWithCredential(PhoneCredential) automatic" );
908
+ } else if (listener.on_verification_failed_count () > 0 ) {
909
+ FAIL () << " Automatic verification failed." ;
910
+ } else {
911
+ // Did not automatically verify, submit verification code manually.
912
+ EXPECT_GT (listener.on_code_auto_retrieval_time_out_count (), 0 );
913
+ EXPECT_NE (listener.verification_id (), " " );
914
+ LogDebug (" Signing in with verification code." );
915
+ const firebase::auth::Credential phone_credential =
916
+ phone_provider.GetCredential (listener.verification_id ().c_str (),
917
+ kPhoneAuthTestVerificationCode );
918
+
919
+ WaitForCompletion (auth_->SignInWithCredential (phone_credential),
920
+ " SignInWithCredential(PhoneCredential)" );
921
+ }
922
+
923
+ ProcessEvents (1000 );
924
+ DeleteUser ();
925
+
926
+ FLAKY_TEST_SECTION_END ();
937
927
}
938
928
939
929
#if defined(ENABLE_OAUTH_TESTS)
0 commit comments