[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 5 | #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 6 | |
| 7 | #include "base/stringprintf.h" |
| 8 | #include "base/utf_string_conversions.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 12 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 13 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 14 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 15 | #include "chrome/test/base/ui_test_utils.h" |
| 16 | #include "content/public/browser/notification_observer.h" |
| 17 | #include "content/public/browser/notification_registrar.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 18 | #include "third_party/skia/include/core/SkBitmap.h" |
| 19 | #include "ui/base/resource/resource_bundle.h" |
| 20 | #include "ui/gfx/image/image.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 21 | #include "ui/gfx/image/image_unittest_util.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 22 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 23 | using content::BrowserThread; |
| 24 | |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 25 | ProfileNameVerifierObserver::ProfileNameVerifierObserver() { |
| 26 | } |
| 27 | |
| 28 | ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { |
| 29 | } |
| 30 | |
| 31 | void ProfileNameVerifierObserver::OnProfileAdded( |
| 32 | const string16& profile_name, |
| 33 | const string16& profile_base_dir, |
| 34 | const FilePath& profile_path, |
| 35 | const gfx::Image* avatar_image) { |
| 36 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 37 | profile_names_.insert(profile_name); |
| 38 | } |
| 39 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame^] | 40 | void ProfileNameVerifierObserver::OnProfileWillBeRemoved( |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 41 | const string16& profile_name) { |
| 42 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 43 | profile_names_.erase(profile_name); |
| 44 | } |
| 45 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame^] | 46 | void ProfileNameVerifierObserver::OnProfileWasRemoved( |
| 47 | const string16& profile_name) { |
| 48 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 49 | } |
| 50 | |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 51 | void ProfileNameVerifierObserver::OnProfileNameChanged( |
| 52 | const string16& old_profile_name, |
| 53 | const string16& new_profile_name) { |
| 54 | EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); |
| 55 | EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); |
| 56 | profile_names_.erase(old_profile_name); |
| 57 | profile_names_.insert(new_profile_name); |
| 58 | } |
| 59 | |
| 60 | void ProfileNameVerifierObserver::OnProfileAvatarChanged( |
| 61 | const string16& profile_name, |
| 62 | const string16& profile_base_dir, |
| 63 | const FilePath& profile_path, |
| 64 | const gfx::Image* avatar_image) { |
| 65 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 66 | } |
| 67 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 68 | ProfileInfoCacheTest::ProfileInfoCacheTest() |
| 69 | : testing_profile_manager_( |
| 70 | static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 71 | ui_thread_(BrowserThread::UI, &ui_loop_), |
| 72 | file_thread_(BrowserThread::FILE, &ui_loop_) { |
| 73 | } |
| 74 | |
| 75 | ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
| 76 | } |
| 77 | |
| 78 | void ProfileInfoCacheTest::SetUp() { |
| 79 | ASSERT_TRUE(testing_profile_manager_.SetUp()); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 80 | testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 83 | void ProfileInfoCacheTest::TearDown() { |
| 84 | // Drain the UI thread to make sure all tasks are completed. This prevents |
| 85 | // memory leaks. |
| 86 | ui_loop_.RunAllPending(); |
| 87 | } |
| 88 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 89 | ProfileInfoCache* ProfileInfoCacheTest::GetCache() { |
| 90 | return testing_profile_manager_.profile_info_cache(); |
| 91 | } |
| 92 | |
| 93 | FilePath ProfileInfoCacheTest::GetProfilePath( |
| 94 | const std::string& base_name) { |
| 95 | return testing_profile_manager_.profile_manager()->user_data_dir(). |
| 96 | AppendASCII(base_name); |
| 97 | } |
| 98 | |
| 99 | void ProfileInfoCacheTest::ResetCache() { |
| 100 | testing_profile_manager_.DeleteProfileInfoCache(); |
| 101 | } |
| 102 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 103 | namespace { |
| 104 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 105 | TEST_F(ProfileInfoCacheTest, AddProfiles) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 106 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 107 | |
| 108 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 109 | FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 110 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 111 | const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 112 | ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| 113 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 114 | GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i); |
| 115 | GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
| 116 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 117 | GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 118 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 119 | EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 120 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 121 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 122 | const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 123 | EXPECT_EQ(icon.width(), actual_icon.width()); |
| 124 | EXPECT_EQ(icon.height(), actual_icon.height()); |
| 125 | } |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 126 | |
| 127 | // Reset the cache and test the it reloads correctly. |
| 128 | ResetCache(); |
| 129 | |
| 130 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 131 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 132 | FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 133 | EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 134 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 135 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 136 | EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); |
| 137 | EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); |
| 138 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 139 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
| 140 | } |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 143 | TEST_F(ProfileInfoCacheTest, DeleteProfile) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 144 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 145 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 146 | FilePath path_1 = GetProfilePath("path_1"); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 147 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 148 | 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 149 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 150 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 151 | FilePath path_2 = GetProfilePath("path_2"); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 152 | string16 name_2 = ASCIIToUTF16("name_2"); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 153 | GetCache()->AddProfileToCache(path_2, name_2, string16(), 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 154 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 155 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 156 | GetCache()->DeleteProfileFromCache(path_1); |
| 157 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 158 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 159 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 160 | GetCache()->DeleteProfileFromCache(path_2); |
| 161 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 164 | TEST_F(ProfileInfoCacheTest, MutateProfile) { |
| 165 | GetCache()->AddProfileToCache( |
| 166 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
| 167 | GetCache()->AddProfileToCache( |
| 168 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 169 | |
| 170 | string16 new_name = ASCIIToUTF16("new_name"); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 171 | GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 172 | EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 173 | EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 174 | |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 175 | string16 new_user_name = ASCIIToUTF16("user_name"); |
| 176 | GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
| 177 | EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 178 | EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 179 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 180 | size_t new_icon_index = 3; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 181 | GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 182 | // Not much to test. |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 183 | GetCache()->GetAvatarIconOfProfileAtIndex(1); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 186 | TEST_F(ProfileInfoCacheTest, Sort) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 187 | string16 name_a = ASCIIToUTF16("apple"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 188 | GetCache()->AddProfileToCache( |
| 189 | GetProfilePath("path_a"), name_a, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 190 | |
| 191 | string16 name_c = ASCIIToUTF16("cat"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 192 | GetCache()->AddProfileToCache( |
| 193 | GetProfilePath("path_c"), name_c, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 194 | |
| 195 | // Sanity check the initial order. |
| 196 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 197 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 198 | |
| 199 | // Add a new profile (start with a capital to test case insensitive sorting. |
| 200 | string16 name_b = ASCIIToUTF16("Banana"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 201 | GetCache()->AddProfileToCache( |
| 202 | GetProfilePath("path_b"), name_b, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 203 | |
| 204 | // Verify the new order. |
| 205 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 206 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
| 207 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
| 208 | |
| 209 | // Change the name of an existing profile. |
| 210 | name_a = UTF8ToUTF16("dog"); |
| 211 | GetCache()->SetNameOfProfileAtIndex(0, name_a); |
| 212 | |
| 213 | // Verify the new order. |
| 214 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 215 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 216 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
| 217 | |
| 218 | // Delete a profile. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 219 | GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 220 | |
| 221 | // Verify the new order. |
| 222 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 223 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
| 224 | } |
| 225 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 226 | TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 227 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 228 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 229 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 230 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 231 | |
| 232 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 233 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 234 | |
| 235 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
| 236 | |
| 237 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 238 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 239 | |
| 240 | GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
| 241 | |
| 242 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 243 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 244 | |
| 245 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
| 246 | |
| 247 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 248 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 249 | } |
| 250 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 251 | TEST_F(ProfileInfoCacheTest, HasMigrated) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 252 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 253 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 254 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 255 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 256 | |
| 257 | // Sanity check. |
| 258 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 259 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 260 | |
| 261 | // Set migrated state for 2nd profile. |
| 262 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true); |
| 263 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 264 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 265 | |
| 266 | // Set migrated state for 1st profile. |
| 267 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true); |
| 268 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 269 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 270 | |
| 271 | // Unset migrated state for 2nd profile. |
| 272 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false); |
| 273 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 274 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 275 | } |
| 276 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 277 | TEST_F(ProfileInfoCacheTest, GAIAName) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 278 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 279 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 280 | string16 profile_name(ASCIIToUTF16("profile name 2")); |
| 281 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 282 | GetProfilePath("path_2"), profile_name, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 283 | |
| 284 | // Sanity check. |
| 285 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 286 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); |
| 287 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); |
| 288 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); |
| 289 | |
| 290 | // Set GAIA name. |
| 291 | string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
| 292 | GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); |
| 293 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 294 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 295 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 296 | |
| 297 | // Use GAIA name as profile name. |
| 298 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); |
| 299 | |
| 300 | EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 301 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 302 | |
| 303 | // Don't use GAIA name as profile name. |
| 304 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); |
| 305 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 306 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 307 | } |
| 308 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 309 | TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 310 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 311 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 312 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 313 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 314 | |
| 315 | // Sanity check. |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 316 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 317 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 318 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 319 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 320 | |
| 321 | // The profile icon should be the default one. |
| 322 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 323 | const gfx::Image& profile_image( |
| 324 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 325 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 326 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 327 | |
| 328 | // Set GAIA picture. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 329 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 330 | GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image); |
| 331 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 332 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 333 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 334 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 335 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 336 | |
| 337 | // Use GAIA picture as profile picture. |
| 338 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 339 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 340 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 341 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 342 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 343 | |
| 344 | // Don't use GAIA picture as profile picture. |
| 345 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 346 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 347 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 348 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 349 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 350 | } |
| 351 | |
[email protected] | 754bebc | 2011-12-01 16:42:16 | [diff] [blame] | 352 | TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 353 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 354 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
| 355 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 356 | |
| 357 | ui_test_utils::WindowedNotificationObserver save_observer( |
| 358 | chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 359 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 360 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 361 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 362 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 363 | |
| 364 | // Wait for the file to be written to disk then reset the cache. |
| 365 | save_observer.Wait(); |
| 366 | ResetCache(); |
| 367 | |
| 368 | // Try to get the GAIA picture. This should return NULL until the read from |
| 369 | // disk is done. |
| 370 | ui_test_utils::WindowedNotificationObserver read_observer( |
| 371 | chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 372 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 373 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 374 | read_observer.Wait(); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 375 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 376 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 377 | } |
| 378 | |
| 379 | TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
| 380 | string16 profile_name = ASCIIToUTF16("name_1"); |
| 381 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 382 | const gfx::Image& profile_image( |
| 383 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
| 384 | |
| 385 | GetCache()->AddProfileToCache( |
| 386 | GetProfilePath("path_1"), profile_name, string16(), 0); |
| 387 | |
| 388 | // Set empty GAIA info. |
| 389 | GetCache()->SetGAIANameOfProfileAtIndex(0, string16()); |
| 390 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
| 391 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
| 392 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 393 | |
| 394 | // Verify that the profile name and picture are not empty. |
| 395 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 396 | EXPECT_TRUE(gfx::test::IsEqual( |
| 397 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 398 | } |
| 399 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 400 | } // namespace |