| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/signin/signin_util.h" |
| 15 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 16 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" | 18 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 23 using ::testing::Mock; |
| 24 using ::testing::_; |
| 25 |
| 21 namespace { | 26 namespace { |
| 22 // The ProfileMetadataEntry accessors aren't just plain old accessors to local | 27 // The ProfileMetadataEntry accessors aren't just plain old accessors to local |
| 23 // members so they'll be tested. The following helpers will make the testing | 28 // members so they'll be tested. The following helpers will make the testing |
| 24 // code less verbose. | 29 // code less verbose. |
| 25 #define TEST_ACCESSORS(entry_type, entry, member, first_value, second_value) \ | 30 #define TEST_ACCESSORS(entry_type, entry, member, first_value, second_value) \ |
| 26 TestAccessors(&entry, \ | 31 TestAccessors(&entry, \ |
| 27 &entry_type::Get ## member, \ | 32 &entry_type::Get ## member, \ |
| 28 &entry_type::Set ## member, \ | 33 &entry_type::Set ## member, \ |
| 29 first_value, \ | 34 first_value, \ |
| 30 second_value); | 35 second_value); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 std::string("")); | 130 std::string("")); |
| 126 | 131 |
| 127 EXPECT_EQ(number_of_profiles + 1, storage()->GetNumberOfProfiles()); | 132 EXPECT_EQ(number_of_profiles + 1, storage()->GetNumberOfProfiles()); |
| 128 } | 133 } |
| 129 | 134 |
| 130 private: | 135 private: |
| 131 TestingProfileManager testing_profile_manager_; | 136 TestingProfileManager testing_profile_manager_; |
| 132 content::TestBrowserThreadBundle thread_bundle_; | 137 content::TestBrowserThreadBundle thread_bundle_; |
| 133 }; | 138 }; |
| 134 | 139 |
| 140 class ProfileAttributesTestObserver |
| 141 : public ProfileAttributesStorage::Observer { |
| 142 public: |
| 143 MOCK_METHOD1(OnProfileSigninRequiredChanged, |
| 144 void(const base::FilePath& profile_path)); |
| 145 }; |
| 146 |
| 135 TEST_F(ProfileAttributesStorageTest, ProfileNotFound) { | 147 TEST_F(ProfileAttributesStorageTest, ProfileNotFound) { |
| 136 EXPECT_EQ(0U, storage()->GetNumberOfProfiles()); | 148 EXPECT_EQ(0U, storage()->GetNumberOfProfiles()); |
| 137 | 149 |
| 138 ProfileAttributesEntry* entry; | 150 ProfileAttributesEntry* entry; |
| 139 ASSERT_FALSE(storage()->GetProfileAttributesWithPath( | 151 ASSERT_FALSE(storage()->GetProfileAttributesWithPath( |
| 140 GetProfilePath("testing_profile_path0"), &entry)); | 152 GetProfilePath("testing_profile_path0"), &entry)); |
| 141 | 153 |
| 142 AddTestingProfile(); | 154 AddTestingProfile(); |
| 143 EXPECT_EQ(1U, storage()->GetNumberOfProfiles()); | 155 EXPECT_EQ(1U, storage()->GetNumberOfProfiles()); |
| 144 | 156 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 icon_index, | 441 icon_index, |
| 430 std::string()); | 442 std::string()); |
| 431 } | 443 } |
| 432 | 444 |
| 433 for (int iter = 0; iter < num_iterations; ++iter) { | 445 for (int iter = 0; iter < num_iterations; ++iter) { |
| 434 // All icons are used up, expect any valid icon. | 446 // All icons are used up, expect any valid icon. |
| 435 ASSERT_GT(total_icon_count, | 447 ASSERT_GT(total_icon_count, |
| 436 storage()->ChooseAvatarIconIndexForNewProfile()); | 448 storage()->ChooseAvatarIconIndexForNewProfile()); |
| 437 } | 449 } |
| 438 } | 450 } |
| 451 |
| 452 TEST_F(ProfileAttributesStorageTest, ProfileForceSigninLock) { |
| 453 signin_util::SetForceSigninForTesting(true); |
| 454 ProfileAttributesTestObserver observer; |
| 455 ProfileAttributesEntry* entry; |
| 456 |
| 457 AddTestingProfile(); |
| 458 ASSERT_TRUE(storage()->GetProfileAttributesWithPath( |
| 459 GetProfilePath("testing_profile_path0"), &entry)); |
| 460 storage()->AddObserver(&observer); |
| 461 ASSERT_FALSE(entry->IsSigninRequired()); |
| 462 |
| 463 EXPECT_CALL(observer, OnProfileSigninRequiredChanged(_)).Times(0); |
| 464 entry->LockForceSigninProfile(false); |
| 465 ASSERT_FALSE(entry->IsSigninRequired()); |
| 466 Mock::VerifyAndClear(&observer); |
| 467 |
| 468 EXPECT_CALL(observer, OnProfileSigninRequiredChanged(_)).Times(1); |
| 469 entry->LockForceSigninProfile(true); |
| 470 ASSERT_TRUE(entry->IsSigninRequired()); |
| 471 Mock::VerifyAndClear(&observer); |
| 472 |
| 473 EXPECT_CALL(observer, OnProfileSigninRequiredChanged(_)).Times(1); |
| 474 entry->SetIsSigninRequired(false); |
| 475 ASSERT_FALSE(entry->IsSigninRequired()); |
| 476 Mock::VerifyAndClear(&observer); |
| 477 } |
| OLD | NEW |