| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 53 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 54 | 54 |
| 55 for (uint32 i = 0; i < 4; ++i) { | 55 for (uint32 i = 0; i < 4; ++i) { |
| 56 std::string base_name = StringPrintf("path_%ud", i); | 56 std::string base_name = StringPrintf("path_%ud", i); |
| 57 FilePath profile_path = | 57 FilePath profile_path = |
| 58 GetUserDataDir().Append(StringToFilePath(base_name)); | 58 GetUserDataDir().Append(StringToFilePath(base_name)); |
| 59 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); | 59 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 60 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( | 60 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 61 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); | 61 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| 62 | 62 |
| 63 GetCache()->AddProfileToCache(profile_path, profile_name, 0); | 63 GetCache()->AddProfileToCache(profile_path, profile_name, string16(), 0); |
| 64 | 64 |
| 65 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); | 65 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 66 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); | 66 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 67 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); | 67 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 68 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); | 68 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); |
| 69 EXPECT_EQ(icon.width(), actual_icon.width()); | 69 EXPECT_EQ(icon.width(), actual_icon.width()); |
| 70 EXPECT_EQ(icon.height(), actual_icon.height()); | 70 EXPECT_EQ(icon.height(), actual_icon.height()); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { | 74 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { |
| 75 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 75 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 76 | 76 |
| 77 FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); | 77 FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); |
| 78 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), | 78 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), |
| 79 0); | 79 0); |
| 80 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); | 80 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 81 | 81 |
| 82 FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); | 82 FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); |
| 83 string16 name_2 = ASCIIToUTF16("name_2"); | 83 string16 name_2 = ASCIIToUTF16("name_2"); |
| 84 GetCache()->AddProfileToCache(path_2, name_2, 0); | 84 GetCache()->AddProfileToCache(path_2, name_2, string16(), 0); |
| 85 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); | 85 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
| 86 | 86 |
| 87 GetCache()->DeleteProfileFromCache(path_1); | 87 GetCache()->DeleteProfileFromCache(path_1); |
| 88 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); | 88 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 89 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); | 89 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
| 90 | 90 |
| 91 GetCache()->DeleteProfileFromCache(path_2); | 91 GetCache()->DeleteProfileFromCache(path_2); |
| 92 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 92 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST_F(ProfileInfoCacheUnittests, MutateProfile) { | 95 TEST_F(ProfileInfoCacheUnittests, MutateProfile) { |
| 96 GetCache()->AddProfileToCache(GetUserDataDir().Append( | 96 GetCache()->AddProfileToCache(GetUserDataDir().Append( |
| 97 StringToFilePath("path_1")), ASCIIToUTF16("name_1"), 0); | 97 StringToFilePath("path_1")), ASCIIToUTF16("name_1"), string16(), 0); |
| 98 GetCache()->AddProfileToCache(GetUserDataDir().Append( | 98 GetCache()->AddProfileToCache(GetUserDataDir().Append( |
| 99 StringToFilePath("path_2")), ASCIIToUTF16("name_2"), 0); | 99 StringToFilePath("path_2")), ASCIIToUTF16("name_2"), string16(), 0); |
| 100 | 100 |
| 101 string16 new_name = ASCIIToUTF16("new_name"); | 101 string16 new_name = ASCIIToUTF16("new_name"); |
| 102 GetCache()->SetNameOfProfileAtIndex(1, new_name); | 102 GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 103 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); | 103 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 104 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); | 104 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 105 | 105 |
| 106 string16 new_user_name = ASCIIToUTF16("user_name"); | 106 string16 new_user_name = ASCIIToUTF16("user_name"); |
| 107 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); | 107 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
| 108 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); | 108 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 109 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); | 109 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 110 | 110 |
| 111 size_t new_icon_index = 3; | 111 size_t new_icon_index = 3; |
| 112 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); | 112 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
| 113 // Not much to test. | 113 // Not much to test. |
| 114 GetCache()->GetAvatarIconOfProfileAtIndex(1); | 114 GetCache()->GetAvatarIconOfProfileAtIndex(1); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| OLD | NEW |