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