@@ -649,6 +649,38 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) {
649
649
auth_->CreateUserWithEmailAndPassword (email.c_str (), kTestPassword );
650
650
WaitForCompletion (create_user, " CreateUserWithEmailAndPassword" );
651
651
EXPECT_TRUE (auth_->current_user ().is_valid ());
652
+
653
+ // Set some user profile properties.
654
+ firebase::auth::User user = create_user.result ()->user ;
655
+ const char kDisplayName [] = " Hello World" ;
656
+ const char kPhotoUrl [] = " http://example.com/image.jpg" ;
657
+ firebase::auth::User::UserProfile user_profile;
658
+ user_profile.display_name = kDisplayName ;
659
+ user_profile.photo_url = kPhotoUrl ;
660
+ firebase::Future<void > update_profile = user.UpdateUserProfile (user_profile);
661
+ WaitForCompletion (update_profile, " UpdateUserProfile" );
662
+ user = auth_->current_user ();
663
+ EXPECT_EQ (user.display_name (), kDisplayName );
664
+ EXPECT_EQ (user.photo_url (), kPhotoUrl );
665
+
666
+ // Validate that the new properties are present after signing out and in.
667
+ SignOut ();
668
+ WaitForCompletion (
669
+ auth_->SignInWithEmailAndPassword (email.c_str (), kTestPassword ),
670
+ " SignInWithEmailAndPassword" );
671
+ user = auth_->current_user ();
672
+ EXPECT_EQ (user.display_name (), kDisplayName );
673
+ EXPECT_EQ (user.photo_url (), kPhotoUrl );
674
+ DeleteUser ();
675
+ }
676
+
677
+ TEST_F (FirebaseAuthTest, TestUpdateUserProfileNull) {
678
+ std::string email = GenerateEmailAddress ();
679
+ firebase::Future<firebase::auth::AuthResult> create_user =
680
+ auth_->CreateUserWithEmailAndPassword (email.c_str (), kTestPassword );
681
+ WaitForCompletion (create_user, " CreateUserWithEmailAndPassword" );
682
+ EXPECT_TRUE (auth_->current_user ().is_valid ());
683
+
652
684
// Set some user profile properties.
653
685
firebase::auth::User user = create_user.result ()->user ;
654
686
const char kDisplayName [] = " Hello World" ;
@@ -661,6 +693,19 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) {
661
693
user = auth_->current_user ();
662
694
EXPECT_EQ (user.display_name (), kDisplayName );
663
695
EXPECT_EQ (user.photo_url (), kPhotoUrl );
696
+
697
+ // Setting the entries to null should leave the old values
698
+ firebase::auth::User::UserProfile user_profile_null;
699
+ user_profile_null.display_name = nullptr ;
700
+ user_profile_null.photo_url = nullptr ;
701
+ firebase::Future<void > update_profile_null =
702
+ user.UpdateUserProfile (user_profile_null);
703
+ WaitForCompletion (update_profile_null, " UpdateUserProfileNull" );
704
+ user = auth_->current_user ();
705
+ EXPECT_EQ (user.display_name (), kDisplayName );
706
+ EXPECT_EQ (user.photo_url (), kPhotoUrl );
707
+
708
+ // Validate that the new properties are present after signing out and in.
664
709
SignOut ();
665
710
WaitForCompletion (
666
711
auth_->SignInWithEmailAndPassword (email.c_str (), kTestPassword ),
@@ -671,6 +716,48 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) {
671
716
DeleteUser ();
672
717
}
673
718
719
+ TEST_F (FirebaseAuthTest, TestUpdateUserProfileEmpty) {
720
+ std::string email = GenerateEmailAddress ();
721
+ firebase::Future<firebase::auth::AuthResult> create_user =
722
+ auth_->CreateUserWithEmailAndPassword (email.c_str (), kTestPassword );
723
+ WaitForCompletion (create_user, " CreateUserWithEmailAndPassword" );
724
+ EXPECT_TRUE (auth_->current_user ().is_valid ());
725
+
726
+ // Set some user profile properties.
727
+ firebase::auth::User user = create_user.result ()->user ;
728
+ const char kDisplayName [] = " Hello World" ;
729
+ const char kPhotoUrl [] = " http://example.com/image.jpg" ;
730
+ firebase::auth::User::UserProfile user_profile;
731
+ user_profile.display_name = kDisplayName ;
732
+ user_profile.photo_url = kPhotoUrl ;
733
+ firebase::Future<void > update_profile = user.UpdateUserProfile (user_profile);
734
+ WaitForCompletion (update_profile, " UpdateUserProfile" );
735
+ user = auth_->current_user ();
736
+ EXPECT_EQ (user.display_name (), kDisplayName );
737
+ EXPECT_EQ (user.photo_url (), kPhotoUrl );
738
+
739
+ // Setting the fields to empty should clear it.
740
+ firebase::auth::User::UserProfile user_profile_empty;
741
+ user_profile_empty.display_name = " " ;
742
+ user_profile_empty.photo_url = " " ;
743
+ firebase::Future<void > update_profile_empty =
744
+ user.UpdateUserProfile (user_profile_empty);
745
+ WaitForCompletion (update_profile_empty, " UpdateUserProfileEmpty" );
746
+ user = auth_->current_user ();
747
+ EXPECT_EQ (user.display_name (), " " );
748
+ EXPECT_EQ (user.photo_url (), " " );
749
+
750
+ // Validate that the properties are cleared out after signing out and in.
751
+ SignOut ();
752
+ WaitForCompletion (
753
+ auth_->SignInWithEmailAndPassword (email.c_str (), kTestPassword ),
754
+ " SignInWithEmailAndPassword" );
755
+ user = auth_->current_user ();
756
+ EXPECT_EQ (user.display_name (), " " );
757
+ EXPECT_EQ (user.photo_url (), " " );
758
+ DeleteUser ();
759
+ }
760
+
674
761
TEST_F (FirebaseAuthTest, TestUpdateEmailAndPassword) {
675
762
std::string email = GenerateEmailAddress ();
676
763
WaitForCompletion (
0 commit comments