| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile_info_cache_unittest.h" | 5 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 126 for (uint32 i = 0; i < 4; ++i) { | 126 for (uint32 i = 0; i < 4; ++i) { |
| 127 base::FilePath profile_path = | 127 base::FilePath profile_path = |
| 128 GetProfilePath(base::StringPrintf("path_%ud", i)); | 128 GetProfilePath(base::StringPrintf("path_%ud", i)); |
| 129 base::string16 profile_name = | 129 base::string16 profile_name = |
| 130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); | 130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
| 131 const SkBitmap* icon = rb.GetImageNamed( | 131 const SkBitmap* icon = rb.GetImageNamed( |
| 132 profiles::GetDefaultAvatarIconResourceIDAtIndex( | 132 profiles::GetDefaultAvatarIconResourceIDAtIndex( |
| 133 i)).ToSkBitmap(); | 133 i)).ToSkBitmap(); |
| 134 std::string managed_user_id = i == 3 ? "TEST_ID" : ""; | 134 std::string supervised_user_id = i == 3 ? "TEST_ID" : ""; |
| 135 | 135 |
| 136 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), | 136 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), |
| 137 i, managed_user_id); | 137 i, supervised_user_id); |
| 138 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); | 138 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
| 139 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); | 139 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
| 140 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); | 140 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
| 141 | 141 |
| 142 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); | 142 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 143 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); | 143 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 144 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); | 144 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 145 const SkBitmap* actual_icon = | 145 const SkBitmap* actual_icon = |
| 146 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); | 146 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); |
| 147 EXPECT_EQ(icon->width(), actual_icon->width()); | 147 EXPECT_EQ(icon->width(), actual_icon->width()); |
| 148 EXPECT_EQ(icon->height(), actual_icon->height()); | 148 EXPECT_EQ(icon->height(), actual_icon->height()); |
| 149 EXPECT_EQ(i == 3, GetCache()->ProfileIsManagedAtIndex(i)); | 149 EXPECT_EQ(i == 3, GetCache()->ProfileIsSupervisedAtIndex(i)); |
| 150 EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i)); | 150 EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i)); |
| 151 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); | 151 EXPECT_EQ(supervised_user_id, |
| 152 GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Reset the cache and test the it reloads correctly. | 155 // Reset the cache and test the it reloads correctly. |
| 155 ResetCache(); | 156 ResetCache(); |
| 156 | 157 |
| 157 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); | 158 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 158 for (uint32 i = 0; i < 4; ++i) { | 159 for (uint32 i = 0; i < 4; ++i) { |
| 159 base::FilePath profile_path = | 160 base::FilePath profile_path = |
| 160 GetProfilePath(base::StringPrintf("path_%ud", i)); | 161 GetProfilePath(base::StringPrintf("path_%ud", i)); |
| 161 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); | 162 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // disk is done. | 404 // disk is done. |
| 404 content::WindowedNotificationObserver read_observer( | 405 content::WindowedNotificationObserver read_observer( |
| 405 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 406 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 406 content::NotificationService::AllSources()); | 407 content::NotificationService::AllSources()); |
| 407 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 408 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 408 read_observer.Wait(); | 409 read_observer.Wait(); |
| 409 EXPECT_TRUE(gfx::test::IsEqual( | 410 EXPECT_TRUE(gfx::test::IsEqual( |
| 410 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 411 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 411 } | 412 } |
| 412 | 413 |
| 413 TEST_F(ProfileInfoCacheTest, SetManagedUserId) { | 414 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { |
| 414 GetCache()->AddProfileToCache( | 415 GetCache()->AddProfileToCache( |
| 415 GetProfilePath("test"), ASCIIToUTF16("Test"), | 416 GetProfilePath("test"), ASCIIToUTF16("Test"), |
| 416 base::string16(), 0, std::string()); | 417 base::string16(), 0, std::string()); |
| 417 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); | 418 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 418 | 419 |
| 419 GetCache()->SetManagedUserIdOfProfileAtIndex(0, "TEST_ID"); | 420 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, "TEST_ID"); |
| 420 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); | 421 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 421 EXPECT_EQ("TEST_ID", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); | 422 EXPECT_EQ("TEST_ID", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
| 422 | 423 |
| 423 ResetCache(); | 424 ResetCache(); |
| 424 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); | 425 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 425 | 426 |
| 426 GetCache()->SetManagedUserIdOfProfileAtIndex(0, std::string()); | 427 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, std::string()); |
| 427 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); | 428 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 428 EXPECT_EQ("", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); | 429 EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
| 429 } | 430 } |
| 430 | 431 |
| 431 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { | 432 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
| 432 base::string16 profile_name = ASCIIToUTF16("name_1"); | 433 base::string16 profile_name = ASCIIToUTF16("name_1"); |
| 433 int id = profiles::GetDefaultAvatarIconResourceIDAtIndex(0); | 434 int id = profiles::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 434 const gfx::Image& profile_image( | 435 const gfx::Image& profile_image( |
| 435 ResourceBundle::GetSharedInstance().GetImageNamed(id)); | 436 ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
| 436 | 437 |
| 437 GetCache()->AddProfileToCache( | 438 GetCache()->AddProfileToCache( |
| 438 GetProfilePath("path_1"), profile_name, base::string16(), 0, | 439 GetProfilePath("path_1"), profile_name, base::string16(), 0, |
| 439 std::string()); | 440 std::string()); |
| 440 | 441 |
| 441 // Set empty GAIA info. | 442 // Set empty GAIA info. |
| 442 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); | 443 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); |
| 443 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); | 444 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
| 444 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); | 445 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 445 | 446 |
| 446 // Verify that the profile name and picture are not empty. | 447 // Verify that the profile name and picture are not empty. |
| 447 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); | 448 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 448 EXPECT_TRUE(gfx::test::IsEqual( | 449 EXPECT_TRUE(gfx::test::IsEqual( |
| 449 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); | 450 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
| 450 } | 451 } |
| 451 | 452 |
| 452 TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) { | 453 TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) { |
| 453 testing_profile_manager_.CreateTestingProfile("default"); | 454 testing_profile_manager_.CreateTestingProfile("default"); |
| 454 base::string16 managed_user_name = ASCIIToUTF16("Supervised User"); | 455 base::string16 supervised_user_name = ASCIIToUTF16("Supervised User"); |
| 455 testing_profile_manager_.CreateTestingProfile( | 456 testing_profile_manager_.CreateTestingProfile( |
| 456 "test1", scoped_ptr<PrefServiceSyncable>(), | 457 "test1", scoped_ptr<PrefServiceSyncable>(), |
| 457 managed_user_name, 0, "TEST_ID", TestingProfile::TestingFactories()); | 458 supervised_user_name, 0, "TEST_ID", TestingProfile::TestingFactories()); |
| 458 for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { | 459 for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { |
| 459 bool is_managed = | 460 bool is_supervised = |
| 460 GetCache()->GetNameOfProfileAtIndex(i) == managed_user_name; | 461 GetCache()->GetNameOfProfileAtIndex(i) == supervised_user_name; |
| 461 EXPECT_EQ(is_managed, GetCache()->ProfileIsManagedAtIndex(i)); | 462 EXPECT_EQ(is_supervised, GetCache()->ProfileIsSupervisedAtIndex(i)); |
| 462 std::string managed_user_id = is_managed ? "TEST_ID" : ""; | 463 std::string supervised_user_id = is_supervised ? "TEST_ID" : ""; |
| 463 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); | 464 EXPECT_EQ(supervised_user_id, |
| 465 GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); |
| 464 } | 466 } |
| 465 | 467 |
| 466 // Managed profiles have a custom theme, which needs to be deleted on the FILE | 468 // Supervised profiles have a custom theme, which needs to be deleted on the |
| 467 // thread. Reset the profile manager now so everything is deleted while we | 469 // FILE thread. Reset the profile manager now so everything is deleted while |
| 468 // still have a FILE thread. | 470 // we still have a FILE thread. |
| 469 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 471 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
| 470 } | 472 } |
| 471 | 473 |
| 472 TEST_F(ProfileInfoCacheTest, AddStubProfile) { | 474 TEST_F(ProfileInfoCacheTest, AddStubProfile) { |
| 473 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 475 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 474 | 476 |
| 475 // Add some profiles with and without a '.' in their paths. | 477 // Add some profiles with and without a '.' in their paths. |
| 476 const struct { | 478 const struct { |
| 477 const char* profile_path; | 479 const char* profile_path; |
| 478 const char* profile_name; | 480 const char* profile_name; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
| 543 | 545 |
| 544 // Clean up. | 546 // Clean up. |
| 545 base::FilePath icon_path = | 547 base::FilePath icon_path = |
| 546 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | 548 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); |
| 547 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); | 549 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); |
| 548 EXPECT_TRUE(base::PathExists(icon_path)); | 550 EXPECT_TRUE(base::PathExists(icon_path)); |
| 549 EXPECT_TRUE(base::DeleteFile(icon_path, true)); | 551 EXPECT_TRUE(base::DeleteFile(icon_path, true)); |
| 550 EXPECT_FALSE(base::PathExists(icon_path)); | 552 EXPECT_FALSE(base::PathExists(icon_path)); |
| 551 } | 553 } |
| OLD | NEW |