OLD | NEW |
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return NULL; | 98 return NULL; |
99 } | 99 } |
100 return policy_manager->core()->store(); | 100 return policy_manager->core()->store(); |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 class UserImageManagerTest : public LoginManagerTest, | 105 class UserImageManagerTest : public LoginManagerTest, |
106 public user_manager::UserManager::Observer { | 106 public user_manager::UserManager::Observer { |
107 protected: | 107 protected: |
108 UserImageManagerTest() | 108 UserImageManagerTest() : LoginManagerTest(true) {} |
109 : LoginManagerTest(true), | |
110 enterprise_account_id_(AccountId::FromUserEmail(kEnterpriseUser1)) {} | |
111 | 109 |
112 // LoginManagerTest overrides: | 110 // LoginManagerTest overrides: |
113 void SetUpInProcessBrowserTestFixture() override { | 111 void SetUpInProcessBrowserTestFixture() override { |
114 LoginManagerTest::SetUpInProcessBrowserTestFixture(); | 112 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
115 | 113 |
116 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 114 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
117 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)); | 115 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)); |
118 } | 116 } |
119 | 117 |
120 void SetUpOnMainThread() override { | 118 void SetUpOnMainThread() override { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 base::FilePath user_data_dir_; | 306 base::FilePath user_data_dir_; |
309 | 307 |
310 PrefService* local_state_; | 308 PrefService* local_state_; |
311 | 309 |
312 scoped_ptr<gfx::ImageSkia> decoded_image_; | 310 scoped_ptr<gfx::ImageSkia> decoded_image_; |
313 | 311 |
314 scoped_ptr<base::RunLoop> run_loop_; | 312 scoped_ptr<base::RunLoop> run_loop_; |
315 | 313 |
316 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); | 314 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); |
317 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2); | 315 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2); |
318 const AccountId enterprise_account_id_; | 316 const AccountId enterprise_account_id_ = |
| 317 AccountId::FromUserEmail(kEnterpriseUser1); |
| 318 const cryptohome::Identification cryptohome_id_ = |
| 319 cryptohome::Identification(enterprise_account_id_); |
319 | 320 |
320 private: | 321 private: |
321 DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest); | 322 DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest); |
322 }; | 323 }; |
323 | 324 |
324 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_DefaultUserImagePreserved) { | 325 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_DefaultUserImagePreserved) { |
325 // Setup an old default (stock) user image. | 326 // Setup an old default (stock) user image. |
326 ScopedUserManagerEnabler(new MockUserManager); | 327 ScopedUserManagerEnabler(new MockUserManager); |
327 SetOldUserImageInfo(test_account_id1_, | 328 SetOldUserImageInfo(test_account_id1_, |
328 default_user_image::kFirstDefaultImageIndex, | 329 default_user_image::kFirstDefaultImageIndex, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 UserImageManagerTest::SetUpInProcessBrowserTestFixture(); | 648 UserImageManagerTest::SetUpInProcessBrowserTestFixture(); |
648 } | 649 } |
649 | 650 |
650 void SetUpOnMainThread() override { | 651 void SetUpOnMainThread() override { |
651 UserImageManagerTest::SetUpOnMainThread(); | 652 UserImageManagerTest::SetUpOnMainThread(); |
652 | 653 |
653 base::FilePath user_keys_dir; | 654 base::FilePath user_keys_dir; |
654 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, | 655 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, |
655 &user_keys_dir)); | 656 &user_keys_dir)); |
656 const std::string sanitized_username = | 657 const std::string sanitized_username = |
657 chromeos::CryptohomeClient::GetStubSanitizedUsername( | 658 chromeos::CryptohomeClient::GetStubSanitizedUsername(cryptohome_id_); |
658 enterprise_account_id_.GetUserEmail()); | |
659 const base::FilePath user_key_file = | 659 const base::FilePath user_key_file = |
660 user_keys_dir.AppendASCII(sanitized_username) | 660 user_keys_dir.AppendASCII(sanitized_username) |
661 .AppendASCII("policy.pub"); | 661 .AppendASCII("policy.pub"); |
662 std::vector<uint8_t> user_key_bits; | 662 std::vector<uint8_t> user_key_bits; |
663 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits)); | 663 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits)); |
664 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName())); | 664 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName())); |
665 ASSERT_EQ(base::WriteFile( | 665 ASSERT_EQ(base::WriteFile( |
666 user_key_file, | 666 user_key_file, |
667 reinterpret_cast<const char*>(user_key_bits.data()), | 667 reinterpret_cast<const char*>(user_key_bits.data()), |
668 user_key_bits.size()), | 668 user_key_bits.size()), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 base::RunLoop().RunUntilIdle(); | 729 base::RunLoop().RunUntilIdle(); |
730 | 730 |
731 policy::CloudPolicyStore* store = GetStoreForUser(user); | 731 policy::CloudPolicyStore* store = GetStoreForUser(user); |
732 ASSERT_TRUE(store); | 732 ASSERT_TRUE(store); |
733 | 733 |
734 // Set policy. Verify that the policy-provided user image is downloaded, set | 734 // Set policy. Verify that the policy-provided user image is downloaded, set |
735 // and persisted. | 735 // and persisted. |
736 user_policy_.payload().mutable_useravatarimage()->set_value( | 736 user_policy_.payload().mutable_useravatarimage()->set_value( |
737 ConstructPolicy(test::kUserAvatarImage2RelativePath)); | 737 ConstructPolicy(test::kUserAvatarImage2RelativePath)); |
738 user_policy_.Build(); | 738 user_policy_.Build(); |
739 fake_session_manager_client_->set_user_policy( | 739 fake_session_manager_client_->set_user_policy(cryptohome_id_, |
740 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); | 740 user_policy_.GetBlob()); |
741 run_loop_.reset(new base::RunLoop); | 741 run_loop_.reset(new base::RunLoop); |
742 store->Load(); | 742 store->Load(); |
743 run_loop_->Run(); | 743 run_loop_->Run(); |
744 | 744 |
745 EXPECT_FALSE(user->HasDefaultImage()); | 745 EXPECT_FALSE(user->HasDefaultImage()); |
746 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); | 746 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); |
747 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); | 747 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); |
748 ExpectNewUserImageInfo(enterprise_account_id_, | 748 ExpectNewUserImageInfo(enterprise_account_id_, |
749 user_manager::User::USER_IMAGE_EXTERNAL, | 749 user_manager::User::USER_IMAGE_EXTERNAL, |
750 GetUserImagePath(enterprise_account_id_, "jpg")); | 750 GetUserImagePath(enterprise_account_id_, "jpg")); |
751 | 751 |
752 scoped_ptr<gfx::ImageSkia> saved_image = | 752 scoped_ptr<gfx::ImageSkia> saved_image = |
753 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); | 753 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); |
754 ASSERT_TRUE(saved_image); | 754 ASSERT_TRUE(saved_image); |
755 | 755 |
756 // Check image dimensions. Images can't be compared since JPEG is lossy. | 756 // Check image dimensions. Images can't be compared since JPEG is lossy. |
757 EXPECT_EQ(policy_image_->width(), saved_image->width()); | 757 EXPECT_EQ(policy_image_->width(), saved_image->width()); |
758 EXPECT_EQ(policy_image_->height(), saved_image->height()); | 758 EXPECT_EQ(policy_image_->height(), saved_image->height()); |
759 | 759 |
760 // Clear policy. Verify that the user image switches to a random default | 760 // Clear policy. Verify that the user image switches to a random default |
761 // image. | 761 // image. |
762 user_policy_.payload().Clear(); | 762 user_policy_.payload().Clear(); |
763 user_policy_.Build(); | 763 user_policy_.Build(); |
764 fake_session_manager_client_->set_user_policy( | 764 fake_session_manager_client_->set_user_policy(cryptohome_id_, |
765 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); | 765 user_policy_.GetBlob()); |
766 run_loop_.reset(new base::RunLoop); | 766 run_loop_.reset(new base::RunLoop); |
767 store->AddObserver(this); | 767 store->AddObserver(this); |
768 store->Load(); | 768 store->Load(); |
769 run_loop_->Run(); | 769 run_loop_->Run(); |
770 store->RemoveObserver(this); | 770 store->RemoveObserver(this); |
771 base::RunLoop().RunUntilIdle(); | 771 base::RunLoop().RunUntilIdle(); |
772 | 772 |
773 const int default_image_index = user->image_index(); | 773 const int default_image_index = user->image_index(); |
774 EXPECT_TRUE(user->HasDefaultImage()); | 774 EXPECT_TRUE(user->HasDefaultImage()); |
775 ASSERT_LE(default_user_image::kFirstDefaultImageIndex, default_image_index); | 775 ASSERT_LE(default_user_image::kFirstDefaultImageIndex, default_image_index); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 EXPECT_TRUE(test::AreImagesEqual(default_image, user->GetImage())); | 836 EXPECT_TRUE(test::AreImagesEqual(default_image, user->GetImage())); |
837 ExpectNewUserImageInfo(enterprise_account_id_, | 837 ExpectNewUserImageInfo(enterprise_account_id_, |
838 default_user_image::kFirstDefaultImageIndex, | 838 default_user_image::kFirstDefaultImageIndex, |
839 base::FilePath()); | 839 base::FilePath()); |
840 | 840 |
841 // Set policy. Verify that the policy-provided user image is downloaded, set | 841 // Set policy. Verify that the policy-provided user image is downloaded, set |
842 // and persisted, overriding the previously set image. | 842 // and persisted, overriding the previously set image. |
843 user_policy_.payload().mutable_useravatarimage()->set_value( | 843 user_policy_.payload().mutable_useravatarimage()->set_value( |
844 ConstructPolicy(test::kUserAvatarImage2RelativePath)); | 844 ConstructPolicy(test::kUserAvatarImage2RelativePath)); |
845 user_policy_.Build(); | 845 user_policy_.Build(); |
846 fake_session_manager_client_->set_user_policy( | 846 fake_session_manager_client_->set_user_policy(cryptohome_id_, |
847 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); | 847 user_policy_.GetBlob()); |
848 run_loop_.reset(new base::RunLoop); | 848 run_loop_.reset(new base::RunLoop); |
849 store->Load(); | 849 store->Load(); |
850 run_loop_->Run(); | 850 run_loop_->Run(); |
851 | 851 |
852 EXPECT_FALSE(user->HasDefaultImage()); | 852 EXPECT_FALSE(user->HasDefaultImage()); |
853 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); | 853 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); |
854 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); | 854 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); |
855 ExpectNewUserImageInfo(enterprise_account_id_, | 855 ExpectNewUserImageInfo(enterprise_account_id_, |
856 user_manager::User::USER_IMAGE_EXTERNAL, | 856 user_manager::User::USER_IMAGE_EXTERNAL, |
857 GetUserImagePath(enterprise_account_id_, "jpg")); | 857 GetUserImagePath(enterprise_account_id_, "jpg")); |
(...skipping 25 matching lines...) Expand all Loading... |
883 base::RunLoop().RunUntilIdle(); | 883 base::RunLoop().RunUntilIdle(); |
884 | 884 |
885 policy::CloudPolicyStore* store = GetStoreForUser(user); | 885 policy::CloudPolicyStore* store = GetStoreForUser(user); |
886 ASSERT_TRUE(store); | 886 ASSERT_TRUE(store); |
887 | 887 |
888 // Set policy. Verify that the policy-provided user image is downloaded, set | 888 // Set policy. Verify that the policy-provided user image is downloaded, set |
889 // and persisted. | 889 // and persisted. |
890 user_policy_.payload().mutable_useravatarimage()->set_value( | 890 user_policy_.payload().mutable_useravatarimage()->set_value( |
891 ConstructPolicy(test::kUserAvatarImage2RelativePath)); | 891 ConstructPolicy(test::kUserAvatarImage2RelativePath)); |
892 user_policy_.Build(); | 892 user_policy_.Build(); |
893 fake_session_manager_client_->set_user_policy( | 893 fake_session_manager_client_->set_user_policy(cryptohome_id_, |
894 enterprise_account_id_.GetUserEmail(), user_policy_.GetBlob()); | 894 user_policy_.GetBlob()); |
895 run_loop_.reset(new base::RunLoop); | 895 run_loop_.reset(new base::RunLoop); |
896 store->Load(); | 896 store->Load(); |
897 run_loop_->Run(); | 897 run_loop_->Run(); |
898 | 898 |
899 EXPECT_FALSE(user->HasDefaultImage()); | 899 EXPECT_FALSE(user->HasDefaultImage()); |
900 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); | 900 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); |
901 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); | 901 EXPECT_TRUE(test::AreImagesEqual(*policy_image_, user->GetImage())); |
902 ExpectNewUserImageInfo(enterprise_account_id_, | 902 ExpectNewUserImageInfo(enterprise_account_id_, |
903 user_manager::User::USER_IMAGE_EXTERNAL, | 903 user_manager::User::USER_IMAGE_EXTERNAL, |
904 GetUserImagePath(enterprise_account_id_, "jpg")); | 904 GetUserImagePath(enterprise_account_id_, "jpg")); |
(...skipping 23 matching lines...) Expand all Loading... |
928 saved_image = | 928 saved_image = |
929 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); | 929 test::ImageLoader(GetUserImagePath(enterprise_account_id_, "jpg")).Load(); |
930 ASSERT_TRUE(saved_image); | 930 ASSERT_TRUE(saved_image); |
931 | 931 |
932 // Check image dimensions. Images can't be compared since JPEG is lossy. | 932 // Check image dimensions. Images can't be compared since JPEG is lossy. |
933 EXPECT_EQ(policy_image_->width(), saved_image->width()); | 933 EXPECT_EQ(policy_image_->width(), saved_image->width()); |
934 EXPECT_EQ(policy_image_->height(), saved_image->height()); | 934 EXPECT_EQ(policy_image_->height(), saved_image->height()); |
935 } | 935 } |
936 | 936 |
937 } // namespace chromeos | 937 } // namespace chromeos |
OLD | NEW |