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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 supervised_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, std::string(), |
137 i, supervised_user_id); | 137 base::string16(), 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()); |
(...skipping 20 matching lines...) Expand all Loading... |
168 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); | 168 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
169 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); | 169 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 TEST_F(ProfileInfoCacheTest, DeleteProfile) { | 173 TEST_F(ProfileInfoCacheTest, DeleteProfile) { |
174 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 174 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
175 | 175 |
176 base::FilePath path_1 = GetProfilePath("path_1"); | 176 base::FilePath path_1 = GetProfilePath("path_1"); |
177 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), | 177 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), |
178 base::string16(), 0, std::string()); | 178 std::string(), base::string16(), 0, |
| 179 std::string()); |
179 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); | 180 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
180 | 181 |
181 base::FilePath path_2 = GetProfilePath("path_2"); | 182 base::FilePath path_2 = GetProfilePath("path_2"); |
182 base::string16 name_2 = ASCIIToUTF16("name_2"); | 183 base::string16 name_2 = ASCIIToUTF16("name_2"); |
183 GetCache()->AddProfileToCache(path_2, name_2, base::string16(), 0, | 184 GetCache()->AddProfileToCache(path_2, name_2, std::string(), base::string16(), |
184 std::string()); | 185 0, std::string()); |
185 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); | 186 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
186 | 187 |
187 GetCache()->DeleteProfileFromCache(path_1); | 188 GetCache()->DeleteProfileFromCache(path_1); |
188 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); | 189 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
189 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); | 190 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
190 | 191 |
191 GetCache()->DeleteProfileFromCache(path_2); | 192 GetCache()->DeleteProfileFromCache(path_2); |
192 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 193 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
193 } | 194 } |
194 | 195 |
195 TEST_F(ProfileInfoCacheTest, MutateProfile) { | 196 TEST_F(ProfileInfoCacheTest, MutateProfile) { |
196 GetCache()->AddProfileToCache( | 197 GetCache()->AddProfileToCache( |
197 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 198 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(), |
198 base::string16(), 0, std::string()); | 199 base::string16(), 0, std::string()); |
199 GetCache()->AddProfileToCache( | 200 GetCache()->AddProfileToCache( |
200 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), | 201 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), std::string(), |
201 base::string16(), 0, std::string()); | 202 base::string16(), 0, std::string()); |
202 | 203 |
203 base::string16 new_name = ASCIIToUTF16("new_name"); | 204 base::string16 new_name = ASCIIToUTF16("new_name"); |
204 GetCache()->SetNameOfProfileAtIndex(1, new_name); | 205 GetCache()->SetNameOfProfileAtIndex(1, new_name); |
205 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); | 206 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
206 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); | 207 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
207 | 208 |
208 base::string16 new_user_name = ASCIIToUTF16("user_name"); | 209 base::string16 new_user_name = ASCIIToUTF16("user_name"); |
209 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); | 210 std::string new_gaia_id = "12345"; |
| 211 GetCache()->SetAuthInfoOfProfileAtIndex(1, new_gaia_id, new_user_name); |
210 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); | 212 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 213 EXPECT_EQ(new_gaia_id, GetCache()->GetGAIAIdOfProfileAtIndex(1)); |
211 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); | 214 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
212 | 215 |
213 size_t new_icon_index = 3; | 216 size_t new_icon_index = 3; |
214 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); | 217 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
215 // Not much to test. | 218 // Not much to test. |
216 GetCache()->GetAvatarIconOfProfileAtIndex(1); | 219 GetCache()->GetAvatarIconOfProfileAtIndex(1); |
217 } | 220 } |
218 | 221 |
219 TEST_F(ProfileInfoCacheTest, Sort) { | 222 TEST_F(ProfileInfoCacheTest, Sort) { |
220 base::string16 name_a = ASCIIToUTF16("apple"); | 223 base::string16 name_a = ASCIIToUTF16("apple"); |
221 GetCache()->AddProfileToCache( | 224 GetCache()->AddProfileToCache( |
222 GetProfilePath("path_a"), name_a, base::string16(), 0, std::string()); | 225 GetProfilePath("path_a"), name_a, std::string(), base::string16(), 0, |
| 226 std::string()); |
223 | 227 |
224 base::string16 name_c = ASCIIToUTF16("cat"); | 228 base::string16 name_c = ASCIIToUTF16("cat"); |
225 GetCache()->AddProfileToCache( | 229 GetCache()->AddProfileToCache( |
226 GetProfilePath("path_c"), name_c, base::string16(), 0, std::string()); | 230 GetProfilePath("path_c"), name_c, std::string(), base::string16(), 0, |
| 231 std::string()); |
227 | 232 |
228 // Sanity check the initial order. | 233 // Sanity check the initial order. |
229 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); | 234 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
230 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); | 235 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
231 | 236 |
232 // Add a new profile (start with a capital to test case insensitive sorting. | 237 // Add a new profile (start with a capital to test case insensitive sorting. |
233 base::string16 name_b = ASCIIToUTF16("Banana"); | 238 base::string16 name_b = ASCIIToUTF16("Banana"); |
234 GetCache()->AddProfileToCache( | 239 GetCache()->AddProfileToCache( |
235 GetProfilePath("path_b"), name_b, base::string16(), 0, std::string()); | 240 GetProfilePath("path_b"), name_b, std::string(), base::string16(), 0, |
| 241 std::string()); |
236 | 242 |
237 // Verify the new order. | 243 // Verify the new order. |
238 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); | 244 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
239 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); | 245 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
240 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); | 246 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
241 | 247 |
242 // Change the name of an existing profile. | 248 // Change the name of an existing profile. |
243 name_a = UTF8ToUTF16("dog"); | 249 name_a = UTF8ToUTF16("dog"); |
244 GetCache()->SetNameOfProfileAtIndex(0, name_a); | 250 GetCache()->SetNameOfProfileAtIndex(0, name_a); |
245 | 251 |
246 // Verify the new order. | 252 // Verify the new order. |
247 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); | 253 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
248 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); | 254 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
249 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); | 255 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
250 | 256 |
251 // Delete a profile. | 257 // Delete a profile. |
252 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); | 258 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); |
253 | 259 |
254 // Verify the new order. | 260 // Verify the new order. |
255 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); | 261 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
256 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); | 262 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
257 } | 263 } |
258 | 264 |
259 TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { | 265 TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { |
260 GetCache()->AddProfileToCache( | 266 GetCache()->AddProfileToCache( |
261 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 267 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
262 base::string16(), 0, std::string()); | 268 std::string(), base::string16(), 0, std::string()); |
263 GetCache()->AddProfileToCache( | 269 GetCache()->AddProfileToCache( |
264 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), | 270 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
265 base::string16(), 0, std::string()); | 271 std::string(), base::string16(), 0, std::string()); |
266 | 272 |
267 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 273 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
268 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 274 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
269 | 275 |
270 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); | 276 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
271 | 277 |
272 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 278 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
273 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 279 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
274 | 280 |
275 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); | 281 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
276 | 282 |
277 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 283 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
278 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 284 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
279 | 285 |
280 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); | 286 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
281 | 287 |
282 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 288 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
283 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 289 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
284 } | 290 } |
285 | 291 |
286 TEST_F(ProfileInfoCacheTest, ProfileActiveTime) { | 292 TEST_F(ProfileInfoCacheTest, ProfileActiveTime) { |
287 GetCache()->AddProfileToCache( | 293 GetCache()->AddProfileToCache( |
288 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 294 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
289 base::string16(), 0, std::string()); | 295 std::string(), base::string16(), 0, std::string()); |
290 EXPECT_EQ(base::Time(), GetCache()->GetProfileActiveTimeAtIndex(0)); | 296 EXPECT_EQ(base::Time(), GetCache()->GetProfileActiveTimeAtIndex(0)); |
291 // Before & After times are artificially shifted because just relying upon | 297 // Before & After times are artificially shifted because just relying upon |
292 // the system time can yield problems due to inaccuracies in the | 298 // the system time can yield problems due to inaccuracies in the |
293 // underlying storage system (which uses a double with only 52 bits of | 299 // underlying storage system (which uses a double with only 52 bits of |
294 // precision to store the 64-bit "time" number). http://crbug.com/346827 | 300 // precision to store the 64-bit "time" number). http://crbug.com/346827 |
295 base::Time before = base::Time::Now(); | 301 base::Time before = base::Time::Now(); |
296 before -= base::TimeDelta::FromSeconds(1); | 302 before -= base::TimeDelta::FromSeconds(1); |
297 GetCache()->SetProfileActiveTimeAtIndex(0); | 303 GetCache()->SetProfileActiveTimeAtIndex(0); |
298 base::Time after = base::Time::Now(); | 304 base::Time after = base::Time::Now(); |
299 after += base::TimeDelta::FromSeconds(1); | 305 after += base::TimeDelta::FromSeconds(1); |
300 EXPECT_LE(before, GetCache()->GetProfileActiveTimeAtIndex(0)); | 306 EXPECT_LE(before, GetCache()->GetProfileActiveTimeAtIndex(0)); |
301 EXPECT_GE(after, GetCache()->GetProfileActiveTimeAtIndex(0)); | 307 EXPECT_GE(after, GetCache()->GetProfileActiveTimeAtIndex(0)); |
302 } | 308 } |
303 | 309 |
304 TEST_F(ProfileInfoCacheTest, GAIAName) { | 310 TEST_F(ProfileInfoCacheTest, GAIAName) { |
305 GetCache()->AddProfileToCache( | 311 GetCache()->AddProfileToCache( |
306 GetProfilePath("path_1"), ASCIIToUTF16("Person 1"), | 312 GetProfilePath("path_1"), ASCIIToUTF16("Person 1"), |
307 base::string16(), 0, std::string()); | 313 std::string(), base::string16(), 0, std::string()); |
308 base::string16 profile_name(ASCIIToUTF16("Person 2")); | 314 base::string16 profile_name(ASCIIToUTF16("Person 2")); |
309 GetCache()->AddProfileToCache( | 315 GetCache()->AddProfileToCache( |
310 GetProfilePath("path_2"), profile_name, base::string16(), 0, | 316 GetProfilePath("path_2"), profile_name, std::string(), base::string16(), |
311 std::string()); | 317 0, std::string()); |
312 | 318 |
313 int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); | 319 int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
314 int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); | 320 int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
315 | 321 |
316 // Sanity check. | 322 // Sanity check. |
317 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); | 323 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); |
318 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty()); | 324 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty()); |
319 | 325 |
320 // Set GAIA name. This re-sorts the cache. | 326 // Set GAIA name. This re-sorts the cache. |
321 base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); | 327 base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
(...skipping 17 matching lines...) Expand all Loading... |
339 EXPECT_EQ(custom_name, GetCache()->GetNameOfProfileAtIndex(index2)); | 345 EXPECT_EQ(custom_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
340 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); | 346 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
341 } | 347 } |
342 | 348 |
343 TEST_F(ProfileInfoCacheTest, GAIAPicture) { | 349 TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
344 const int kDefaultAvatarIndex = 0; | 350 const int kDefaultAvatarIndex = 0; |
345 const int kOtherAvatarIndex = 1; | 351 const int kOtherAvatarIndex = 1; |
346 const int kGaiaPictureSize = 256; // Standard size of a Gaia account picture. | 352 const int kGaiaPictureSize = 256; // Standard size of a Gaia account picture. |
347 GetCache()->AddProfileToCache( | 353 GetCache()->AddProfileToCache( |
348 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 354 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
349 base::string16(), kDefaultAvatarIndex, std::string()); | 355 std::string(), base::string16(), kDefaultAvatarIndex, std::string()); |
350 GetCache()->AddProfileToCache( | 356 GetCache()->AddProfileToCache( |
351 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), | 357 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
352 base::string16(), kDefaultAvatarIndex, std::string()); | 358 std::string(), base::string16(), kDefaultAvatarIndex, std::string()); |
353 | 359 |
354 // Sanity check. | 360 // Sanity check. |
355 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 361 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
356 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); | 362 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); |
357 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); | 363 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
358 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); | 364 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
359 | 365 |
360 // The profile icon should be the default one. | 366 // The profile icon should be the default one. |
361 EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(0)); | 367 EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(0)); |
362 EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(1)); | 368 EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(1)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); | 413 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
408 EXPECT_TRUE(gfx::test::IsEqual( | 414 EXPECT_TRUE(gfx::test::IsEqual( |
409 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); | 415 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
410 EXPECT_TRUE(gfx::test::IsEqual( | 416 EXPECT_TRUE(gfx::test::IsEqual( |
411 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); | 417 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
412 } | 418 } |
413 | 419 |
414 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { | 420 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
415 GetCache()->AddProfileToCache( | 421 GetCache()->AddProfileToCache( |
416 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 422 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
417 base::string16(), 0, std::string()); | 423 std::string(), base::string16(), 0, std::string()); |
418 gfx::Image gaia_image(gfx::test::CreateImage()); | 424 gfx::Image gaia_image(gfx::test::CreateImage()); |
419 | 425 |
420 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); | 426 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
421 | 427 |
422 // Make sure everything has completed, and the file has been written to disk. | 428 // Make sure everything has completed, and the file has been written to disk. |
423 base::RunLoop().RunUntilIdle(); | 429 base::RunLoop().RunUntilIdle(); |
424 | 430 |
425 EXPECT_TRUE(gfx::test::IsEqual( | 431 EXPECT_TRUE(gfx::test::IsEqual( |
426 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 432 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
427 | 433 |
428 ResetCache(); | 434 ResetCache(); |
429 // Try to get the GAIA picture. This should return NULL until the read from | 435 // Try to get the GAIA picture. This should return NULL until the read from |
430 // disk is done. | 436 // disk is done. |
431 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 437 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
432 base::RunLoop().RunUntilIdle(); | 438 base::RunLoop().RunUntilIdle(); |
433 | 439 |
434 EXPECT_TRUE(gfx::test::IsEqual( | 440 EXPECT_TRUE(gfx::test::IsEqual( |
435 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 441 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
436 } | 442 } |
437 | 443 |
438 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { | 444 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { |
439 GetCache()->AddProfileToCache( | 445 GetCache()->AddProfileToCache( |
440 GetProfilePath("test"), ASCIIToUTF16("Test"), | 446 GetProfilePath("test"), ASCIIToUTF16("Test"), |
441 base::string16(), 0, std::string()); | 447 std::string(), base::string16(), 0, std::string()); |
442 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 448 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
443 | 449 |
444 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, "TEST_ID"); | 450 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, "TEST_ID"); |
445 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 451 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
446 EXPECT_EQ("TEST_ID", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); | 452 EXPECT_EQ("TEST_ID", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
447 | 453 |
448 ResetCache(); | 454 ResetCache(); |
449 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 455 EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
450 | 456 |
451 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, std::string()); | 457 GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, std::string()); |
452 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 458 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
453 EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); | 459 EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
454 } | 460 } |
455 | 461 |
456 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { | 462 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
457 base::string16 profile_name = ASCIIToUTF16("name_1"); | 463 base::string16 profile_name = ASCIIToUTF16("name_1"); |
458 int id = profiles::GetDefaultAvatarIconResourceIDAtIndex(0); | 464 int id = profiles::GetDefaultAvatarIconResourceIDAtIndex(0); |
459 const gfx::Image& profile_image( | 465 const gfx::Image& profile_image( |
460 ResourceBundle::GetSharedInstance().GetImageNamed(id)); | 466 ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
461 | 467 |
462 GetCache()->AddProfileToCache( | 468 GetCache()->AddProfileToCache( |
463 GetProfilePath("path_1"), profile_name, base::string16(), 0, | 469 GetProfilePath("path_1"), profile_name, std::string(), base::string16(), |
464 std::string()); | 470 0, std::string()); |
465 | 471 |
466 // Set empty GAIA info. | 472 // Set empty GAIA info. |
467 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); | 473 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); |
468 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); | 474 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
469 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); | 475 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
470 | 476 |
471 // Verify that the profile name and picture are not empty. | 477 // Verify that the profile name and picture are not empty. |
472 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); | 478 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
473 EXPECT_TRUE(gfx::test::IsEqual( | 479 EXPECT_TRUE(gfx::test::IsEqual( |
474 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); | 480 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 { "path.test0", "name_0" }, | 512 { "path.test0", "name_0" }, |
507 { "path_test1", "name_1" }, | 513 { "path_test1", "name_1" }, |
508 { "path.test2", "name_2" }, | 514 { "path.test2", "name_2" }, |
509 { "path_test3", "name_3" }, | 515 { "path_test3", "name_3" }, |
510 }; | 516 }; |
511 | 517 |
512 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 518 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
513 base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); | 519 base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); |
514 base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name); | 520 base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name); |
515 | 521 |
516 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), | 522 GetCache()->AddProfileToCache(profile_path, profile_name, std::string(), |
517 i, ""); | 523 base::string16(), i, ""); |
518 | 524 |
519 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); | 525 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
520 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); | 526 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
521 } | 527 } |
522 | 528 |
523 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); | 529 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
524 | 530 |
525 // Check that the profiles can be extracted from the local state. | 531 // Check that the profiles can be extracted from the local state. |
526 std::vector<base::string16> names; | 532 std::vector<base::string16> names; |
527 PrefService* local_state = g_browser_process->local_state(); | 533 PrefService* local_state = g_browser_process->local_state(); |
(...skipping 24 matching lines...) Expand all Loading... |
552 | 558 |
553 // // Make sure there are no avatars already on disk. | 559 // // Make sure there are no avatars already on disk. |
554 const size_t kIconIndex = 0; | 560 const size_t kIconIndex = 0; |
555 base::FilePath icon_path = | 561 base::FilePath icon_path = |
556 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | 562 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); |
557 EXPECT_FALSE(base::PathExists(icon_path)); | 563 EXPECT_FALSE(base::PathExists(icon_path)); |
558 | 564 |
559 EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles()); | 565 EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles()); |
560 base::FilePath path_1 = GetProfilePath("path_1"); | 566 base::FilePath path_1 = GetProfilePath("path_1"); |
561 profile_info_cache.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), | 567 profile_info_cache.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), |
562 base::string16(), kIconIndex, std::string()); | 568 std::string(), base::string16(), kIconIndex, std::string()); |
563 EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles()); | 569 EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles()); |
564 base::RunLoop().RunUntilIdle(); | 570 base::RunLoop().RunUntilIdle(); |
565 | 571 |
566 // We haven't downloaded any high-res avatars yet. | 572 // We haven't downloaded any high-res avatars yet. |
567 EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size()); | 573 EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size()); |
568 | 574 |
569 // After adding a new profile, the download of high-res avatar will be | 575 // After adding a new profile, the download of high-res avatar will be |
570 // triggered if the flag kNewAvatarMenu has been set. But the downloader | 576 // triggered if the flag kNewAvatarMenu has been set. But the downloader |
571 // won't ever call OnFetchComplete in the test. | 577 // won't ever call OnFetchComplete in the test. |
572 EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size()); | 578 EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 EXPECT_FALSE(base::PathExists(icon_path)); | 614 EXPECT_FALSE(base::PathExists(icon_path)); |
609 } | 615 } |
610 | 616 |
611 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { | 617 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { |
612 switches::EnableNewAvatarMenuForTesting( | 618 switches::EnableNewAvatarMenuForTesting( |
613 base::CommandLine::ForCurrentProcess()); | 619 base::CommandLine::ForCurrentProcess()); |
614 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | 620 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
615 | 621 |
616 base::FilePath path_1 = GetProfilePath("path_1"); | 622 base::FilePath path_1 = GetProfilePath("path_1"); |
617 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("Default Profile"), | 623 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("Default Profile"), |
618 base::string16(), 0, std::string()); | 624 std::string(), base::string16(), 0, |
| 625 std::string()); |
619 base::FilePath path_2 = GetProfilePath("path_2"); | 626 base::FilePath path_2 = GetProfilePath("path_2"); |
620 GetCache()->AddProfileToCache(path_2, ASCIIToUTF16("First user"), | 627 GetCache()->AddProfileToCache(path_2, ASCIIToUTF16("First user"), |
621 base::string16(), 1, std::string()); | 628 std::string(), base::string16(), 1, |
| 629 std::string()); |
622 base::string16 name_3 = ASCIIToUTF16("Lemonade"); | 630 base::string16 name_3 = ASCIIToUTF16("Lemonade"); |
623 base::FilePath path_3 = GetProfilePath("path_3"); | 631 base::FilePath path_3 = GetProfilePath("path_3"); |
624 GetCache()->AddProfileToCache(path_3, name_3, | 632 GetCache()->AddProfileToCache(path_3, name_3, |
625 base::string16(), 2, std::string()); | 633 std::string(), base::string16(), 2, |
| 634 std::string()); |
626 base::string16 name_4 = ASCIIToUTF16("Batman"); | 635 base::string16 name_4 = ASCIIToUTF16("Batman"); |
627 base::FilePath path_4 = GetProfilePath("path_4"); | 636 base::FilePath path_4 = GetProfilePath("path_4"); |
628 GetCache()->AddProfileToCache(path_4, name_4, | 637 GetCache()->AddProfileToCache(path_4, name_4, |
629 base::string16(), 3, std::string()); | 638 std::string(), base::string16(), 3, |
| 639 std::string()); |
630 base::string16 name_5 = ASCIIToUTF16("Person 2"); | 640 base::string16 name_5 = ASCIIToUTF16("Person 2"); |
631 base::FilePath path_5 = GetProfilePath("path_5"); | 641 base::FilePath path_5 = GetProfilePath("path_5"); |
632 GetCache()->AddProfileToCache(path_5, name_5, | 642 GetCache()->AddProfileToCache(path_5, name_5, |
633 base::string16(), 2, std::string()); | 643 std::string(), base::string16(), 2, |
| 644 std::string()); |
634 | 645 |
635 EXPECT_EQ(5U, GetCache()->GetNumberOfProfiles()); | 646 EXPECT_EQ(5U, GetCache()->GetNumberOfProfiles()); |
636 | 647 |
637 | 648 |
638 ResetCache(); | 649 ResetCache(); |
639 | 650 |
640 // Legacy profile names like "Default Profile" and "First user" should be | 651 // Legacy profile names like "Default Profile" and "First user" should be |
641 // migrated to "Person %n" type names. | 652 // migrated to "Person %n" type names. |
642 EXPECT_EQ(ASCIIToUTF16("Person 1"), GetCache()->GetNameOfProfileAtIndex( | 653 EXPECT_EQ(ASCIIToUTF16("Person 1"), GetCache()->GetNameOfProfileAtIndex( |
643 GetCache()->GetIndexOfProfileWithPath(path_1))); | 654 GetCache()->GetIndexOfProfileWithPath(path_1))); |
(...skipping 14 matching lines...) Expand all Loading... |
658 TEST_F(ProfileInfoCacheTest, | 669 TEST_F(ProfileInfoCacheTest, |
659 DontMigrateLegacyProfileNamesWithoutNewAvatarMenu) { | 670 DontMigrateLegacyProfileNamesWithoutNewAvatarMenu) { |
660 switches::DisableNewAvatarMenuForTesting( | 671 switches::DisableNewAvatarMenuForTesting( |
661 base::CommandLine::ForCurrentProcess()); | 672 base::CommandLine::ForCurrentProcess()); |
662 | 673 |
663 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | 674 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
664 | 675 |
665 base::string16 name_1 = ASCIIToUTF16("Default Profile"); | 676 base::string16 name_1 = ASCIIToUTF16("Default Profile"); |
666 base::FilePath path_1 = GetProfilePath("path_1"); | 677 base::FilePath path_1 = GetProfilePath("path_1"); |
667 GetCache()->AddProfileToCache(path_1, name_1, | 678 GetCache()->AddProfileToCache(path_1, name_1, |
668 base::string16(), 0, std::string()); | 679 std::string(), base::string16(), 0, |
| 680 std::string()); |
669 base::string16 name_2 = ASCIIToUTF16("First user"); | 681 base::string16 name_2 = ASCIIToUTF16("First user"); |
670 base::FilePath path_2 = GetProfilePath("path_2"); | 682 base::FilePath path_2 = GetProfilePath("path_2"); |
671 GetCache()->AddProfileToCache(path_2, name_2, | 683 GetCache()->AddProfileToCache(path_2, name_2, |
672 base::string16(), 1, std::string()); | 684 std::string(), base::string16(), 1, |
| 685 std::string()); |
673 base::string16 name_3 = ASCIIToUTF16("Lemonade"); | 686 base::string16 name_3 = ASCIIToUTF16("Lemonade"); |
674 base::FilePath path_3 = GetProfilePath("path_3"); | 687 base::FilePath path_3 = GetProfilePath("path_3"); |
675 GetCache()->AddProfileToCache(path_3, name_3, | 688 GetCache()->AddProfileToCache(path_3, name_3, |
676 base::string16(), 2, std::string()); | 689 std::string(), base::string16(), 2, |
| 690 std::string()); |
677 base::string16 name_4 = ASCIIToUTF16("Batman"); | 691 base::string16 name_4 = ASCIIToUTF16("Batman"); |
678 base::FilePath path_4 = GetProfilePath("path_4"); | 692 base::FilePath path_4 = GetProfilePath("path_4"); |
679 GetCache()->AddProfileToCache(path_4, name_4, | 693 GetCache()->AddProfileToCache(path_4, name_4, |
680 base::string16(), 3, std::string()); | 694 std::string(), base::string16(), 3, |
| 695 std::string()); |
681 EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); | 696 EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
682 | 697 |
683 ResetCache(); | 698 ResetCache(); |
684 | 699 |
685 // Profile names should have been preserved. | 700 // Profile names should have been preserved. |
686 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( | 701 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
687 GetCache()->GetIndexOfProfileWithPath(path_1))); | 702 GetCache()->GetIndexOfProfileWithPath(path_1))); |
688 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( | 703 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
689 GetCache()->GetIndexOfProfileWithPath(path_2))); | 704 GetCache()->GetIndexOfProfileWithPath(path_2))); |
690 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | 705 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
691 GetCache()->GetIndexOfProfileWithPath(path_3))); | 706 GetCache()->GetIndexOfProfileWithPath(path_3))); |
692 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | 707 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
693 GetCache()->GetIndexOfProfileWithPath(path_4))); | 708 GetCache()->GetIndexOfProfileWithPath(path_4))); |
694 } | 709 } |
OLD | NEW |