Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_browsertest.cc

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return NULL; 100 return NULL;
101 } 101 }
102 return policy_manager->core()->store(); 102 return policy_manager->core()->store();
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 class UserImageManagerTest : public LoginManagerTest, 107 class UserImageManagerTest : public LoginManagerTest,
108 public user_manager::UserManager::Observer { 108 public user_manager::UserManager::Observer {
109 protected: 109 protected:
110 UserImageManagerTest() 110 UserImageManagerTest() : LoginManagerTest(true) {}
111 : LoginManagerTest(true),
112 enterprise_account_id_(AccountId::FromUserEmail(kEnterpriseUser1)) {}
113 111
114 // LoginManagerTest overrides: 112 // LoginManagerTest overrides:
115 void SetUpInProcessBrowserTestFixture() override { 113 void SetUpInProcessBrowserTestFixture() override {
116 LoginManagerTest::SetUpInProcessBrowserTestFixture(); 114 LoginManagerTest::SetUpInProcessBrowserTestFixture();
117 115
118 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); 116 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
119 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)); 117 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_));
120 } 118 }
121 119
122 void SetUpCommandLine(base::CommandLine* command_line) override { 120 void SetUpCommandLine(base::CommandLine* command_line) override {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 base::FilePath user_data_dir_; 318 base::FilePath user_data_dir_;
321 319
322 PrefService* local_state_; 320 PrefService* local_state_;
323 321
324 scoped_ptr<gfx::ImageSkia> decoded_image_; 322 scoped_ptr<gfx::ImageSkia> decoded_image_;
325 323
326 scoped_ptr<base::RunLoop> run_loop_; 324 scoped_ptr<base::RunLoop> run_loop_;
327 325
328 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); 326 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1);
329 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2); 327 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2);
330 const AccountId enterprise_account_id_; 328 const AccountId enterprise_account_id_ =
329 AccountId::FromUserEmail(kEnterpriseUser1);
330 const cryptohome::Identification cryptohome_id_ =
331 cryptohome::Identification(enterprise_account_id_);
331 332
332 private: 333 private:
333 DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest); 334 DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest);
334 }; 335 };
335 336
336 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_DefaultUserImagePreserved) { 337 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_DefaultUserImagePreserved) {
337 // Setup an old default (stock) user image. 338 // Setup an old default (stock) user image.
338 ScopedUserManagerEnabler(new MockUserManager); 339 ScopedUserManagerEnabler(new MockUserManager);
339 SetOldUserImageInfo(test_account_id1_, 340 SetOldUserImageInfo(test_account_id1_,
340 default_user_image::kFirstDefaultImageIndex, 341 default_user_image::kFirstDefaultImageIndex,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 UserImageManagerTest::SetUpInProcessBrowserTestFixture(); 660 UserImageManagerTest::SetUpInProcessBrowserTestFixture();
660 } 661 }
661 662
662 void SetUpOnMainThread() override { 663 void SetUpOnMainThread() override {
663 UserImageManagerTest::SetUpOnMainThread(); 664 UserImageManagerTest::SetUpOnMainThread();
664 665
665 base::FilePath user_keys_dir; 666 base::FilePath user_keys_dir;
666 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, 667 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS,
667 &user_keys_dir)); 668 &user_keys_dir));
668 const std::string sanitized_username = 669 const std::string sanitized_username =
669 chromeos::CryptohomeClient::GetStubSanitizedUsername( 670 chromeos::CryptohomeClient::GetStubSanitizedUsername(cryptohome_id_);
670 enterprise_account_id_.GetUserEmail());
671 const base::FilePath user_key_file = 671 const base::FilePath user_key_file =
672 user_keys_dir.AppendASCII(sanitized_username) 672 user_keys_dir.AppendASCII(sanitized_username)
673 .AppendASCII("policy.pub"); 673 .AppendASCII("policy.pub");
674 std::vector<uint8_t> user_key_bits; 674 std::vector<uint8_t> user_key_bits;
675 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits)); 675 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits));
676 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName())); 676 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName()));
677 ASSERT_EQ(base::WriteFile( 677 ASSERT_EQ(base::WriteFile(
678 user_key_file, 678 user_key_file,
679 reinterpret_cast<const char*>(user_key_bits.data()), 679 reinterpret_cast<const char*>(user_key_bits.data()),
680 user_key_bits.size()), 680 user_key_bits.size()),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 base::RunLoop().RunUntilIdle(); 741 base::RunLoop().RunUntilIdle();
742 742
743 policy::CloudPolicyStore* store = GetStoreForUser(user); 743 policy::CloudPolicyStore* store = GetStoreForUser(user);
744 ASSERT_TRUE(store); 744 ASSERT_TRUE(store);
745 745
746 // Set policy. Verify that the policy-provided user image is downloaded, set 746 // Set policy. Verify that the policy-provided user image is downloaded, set
747 // and persisted. 747 // and persisted.
748 user_policy_.payload().mutable_useravatarimage()->set_value( 748 user_policy_.payload().mutable_useravatarimage()->set_value(
749 ConstructPolicy(test::kUserAvatarImage2RelativePath)); 749 ConstructPolicy(test::kUserAvatarImage2RelativePath));
750 user_policy_.Build(); 750 user_policy_.Build();
751 fake_session_manager_client_->set_user_policy( 751 fake_session_manager_client_->set_user_policy(cryptohome_id_,
752 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); 752 user_policy_.GetBlob());
753 run_loop_.reset(new base::RunLoop); 753 run_loop_.reset(new base::RunLoop);
754 store->Load(); 754 store->Load();
755 run_loop_->Run(); 755 run_loop_->Run();
756 756
757 EXPECT_FALSE(user->HasDefaultImage()); 757 EXPECT_FALSE(user->HasDefaultImage());
758 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); 758 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index());
759 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); 759 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage()));
760 ExpectNewUserImageInfo(enterprise_account_id_, 760 ExpectNewUserImageInfo(enterprise_account_id_,
761 user_manager::User::USER_IMAGE_EXTERNAL, 761 user_manager::User::USER_IMAGE_EXTERNAL,
762 GetUserImagePath(enterprise_account_id_, "jpg")); 762 GetUserImagePath(enterprise_account_id_, "jpg"));
763 763
764 scoped_ptr<gfx::ImageSkia> saved_image = 764 scoped_ptr<gfx::ImageSkia> saved_image =
765 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); 765 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load();
766 ASSERT_TRUE(saved_image); 766 ASSERT_TRUE(saved_image);
767 767
768 // Check image dimensions. Images can't be compared since JPEG is lossy. 768 // Check image dimensions. Images can't be compared since JPEG is lossy.
769 EXPECT_EQ(policy_image_->width(), saved_image->width()); 769 EXPECT_EQ(policy_image_->width(), saved_image->width());
770 EXPECT_EQ(policy_image_->height(), saved_image->height()); 770 EXPECT_EQ(policy_image_->height(), saved_image->height());
771 771
772 // Clear policy. Verify that the user image switches to a random default 772 // Clear policy. Verify that the user image switches to a random default
773 // image. 773 // image.
774 user_policy_.payload().Clear(); 774 user_policy_.payload().Clear();
775 user_policy_.Build(); 775 user_policy_.Build();
776 fake_session_manager_client_->set_user_policy( 776 fake_session_manager_client_->set_user_policy(cryptohome_id_,
777 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); 777 user_policy_.GetBlob());
778 run_loop_.reset(new base::RunLoop); 778 run_loop_.reset(new base::RunLoop);
779 store->AddObserver(this); 779 store->AddObserver(this);
780 store->Load(); 780 store->Load();
781 run_loop_->Run(); 781 run_loop_->Run();
782 store->RemoveObserver(this); 782 store->RemoveObserver(this);
783 base::RunLoop().RunUntilIdle(); 783 base::RunLoop().RunUntilIdle();
784 784
785 const int default_image_index = user->image_index(); 785 const int default_image_index = user->image_index();
786 EXPECT_TRUE(user->HasDefaultImage()); 786 EXPECT_TRUE(user->HasDefaultImage());
787 ASSERT_LE(default_user_image::kFirstDefaultImageIndex, default_image_index); 787 ASSERT_LE(default_user_image::kFirstDefaultImageIndex, default_image_index);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 EXPECT_TRUE(test::AreImagesEqual(default_image, user->GetImage())); 848 EXPECT_TRUE(test::AreImagesEqual(default_image, user->GetImage()));
849 ExpectNewUserImageInfo(enterprise_account_id_, 849 ExpectNewUserImageInfo(enterprise_account_id_,
850 default_user_image::kFirstDefaultImageIndex, 850 default_user_image::kFirstDefaultImageIndex,
851 base::FilePath()); 851 base::FilePath());
852 852
853 // Set policy. Verify that the policy-provided user image is downloaded, set 853 // Set policy. Verify that the policy-provided user image is downloaded, set
854 // and persisted, overriding the previously set image. 854 // and persisted, overriding the previously set image.
855 user_policy_.payload().mutable_useravatarimage()->set_value( 855 user_policy_.payload().mutable_useravatarimage()->set_value(
856 ConstructPolicy(test::kUserAvatarImage2RelativePath)); 856 ConstructPolicy(test::kUserAvatarImage2RelativePath));
857 user_policy_.Build(); 857 user_policy_.Build();
858 fake_session_manager_client_->set_user_policy( 858 fake_session_manager_client_->set_user_policy(cryptohome_id_,
859 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); 859 user_policy_.GetBlob());
860 run_loop_.reset(new base::RunLoop); 860 run_loop_.reset(new base::RunLoop);
861 store->Load(); 861 store->Load();
862 run_loop_->Run(); 862 run_loop_->Run();
863 863
864 EXPECT_FALSE(user->HasDefaultImage()); 864 EXPECT_FALSE(user->HasDefaultImage());
865 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); 865 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index());
866 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); 866 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage()));
867 ExpectNewUserImageInfo(enterprise_account_id_, 867 ExpectNewUserImageInfo(enterprise_account_id_,
868 user_manager::User::USER_IMAGE_EXTERNAL, 868 user_manager::User::USER_IMAGE_EXTERNAL,
869 GetUserImagePath(enterprise_account_id_, "jpg")); 869 GetUserImagePath(enterprise_account_id_, "jpg"));
(...skipping 25 matching lines...) Expand all
895 base::RunLoop().RunUntilIdle(); 895 base::RunLoop().RunUntilIdle();
896 896
897 policy::CloudPolicyStore* store = GetStoreForUser(user); 897 policy::CloudPolicyStore* store = GetStoreForUser(user);
898 ASSERT_TRUE(store); 898 ASSERT_TRUE(store);
899 899
900 // Set policy. Verify that the policy-provided user image is downloaded, set 900 // Set policy. Verify that the policy-provided user image is downloaded, set
901 // and persisted. 901 // and persisted.
902 user_policy_.payload().mutable_useravatarimage()->set_value( 902 user_policy_.payload().mutable_useravatarimage()->set_value(
903 ConstructPolicy(test::kUserAvatarImage2RelativePath)); 903 ConstructPolicy(test::kUserAvatarImage2RelativePath));
904 user_policy_.Build(); 904 user_policy_.Build();
905 fake_session_manager_client_->set_user_policy( 905 fake_session_manager_client_->set_user_policy(cryptohome_id_,
906 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); 906 user_policy_.GetBlob());
907 run_loop_.reset(new base::RunLoop); 907 run_loop_.reset(new base::RunLoop);
908 store->Load(); 908 store->Load();
909 run_loop_->Run(); 909 run_loop_->Run();
910 910
911 EXPECT_FALSE(user->HasDefaultImage()); 911 EXPECT_FALSE(user->HasDefaultImage());
912 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); 912 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index());
913 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); 913 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage()));
914 ExpectNewUserImageInfo(enterprise_account_id_, 914 ExpectNewUserImageInfo(enterprise_account_id_,
915 user_manager::User::USER_IMAGE_EXTERNAL, 915 user_manager::User::USER_IMAGE_EXTERNAL,
916 GetUserImagePath(enterprise_account_id_, "jpg")); 916 GetUserImagePath(enterprise_account_id_, "jpg"));
(...skipping 23 matching lines...) Expand all
940 saved_image = 940 saved_image =
941 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); 941 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load();
942 ASSERT_TRUE(saved_image); 942 ASSERT_TRUE(saved_image);
943 943
944 // Check image dimensions. Images can't be compared since JPEG is lossy. 944 // Check image dimensions. Images can't be compared since JPEG is lossy.
945 EXPECT_EQ(policy_image_->width(), saved_image->width()); 945 EXPECT_EQ(policy_image_->width(), saved_image->width());
946 EXPECT_EQ(policy_image_->height(), saved_image->height()); 946 EXPECT_EQ(policy_image_->height(), saved_image->height());
947 } 947 }
948 948
949 } // namespace chromeos 949 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698