Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/profiles/profile_info_cache_unittest.cc

Issue 196473015: [Profiles] Don't treat GAIA names differently than regular profile names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove useless comment Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 275 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
276 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 276 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
277 277
278 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); 278 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false);
279 279
280 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 280 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
281 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 281 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
282 } 282 }
283 283
284 TEST_F(ProfileInfoCacheTest, HasMigrated) {
285 GetCache()->AddProfileToCache(
286 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
287 base::string16(), 0, std::string());
288 GetCache()->AddProfileToCache(
289 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
290 base::string16(), 0, std::string());
291
292 // Sanity check.
293 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
294 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
295
296 // Set migrated state for 2nd profile.
297 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true);
298 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
299 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
300
301 // Set migrated state for 1st profile.
302 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true);
303 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
304 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
305
306 // Unset migrated state for 2nd profile.
307 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false);
308 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
309 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
310 }
311
312 TEST_F(ProfileInfoCacheTest, ProfileActiveTime) { 284 TEST_F(ProfileInfoCacheTest, ProfileActiveTime) {
313 GetCache()->AddProfileToCache( 285 GetCache()->AddProfileToCache(
314 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 286 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
315 base::string16(), 0, std::string()); 287 base::string16(), 0, std::string());
316 EXPECT_EQ(base::Time(), GetCache()->GetProfileActiveTimeAtIndex(0)); 288 EXPECT_EQ(base::Time(), GetCache()->GetProfileActiveTimeAtIndex(0));
317 // Before & After times are artificially shifted because just relying upon 289 // Before & After times are artificially shifted because just relying upon
318 // the system time can yield problems due to inaccuracies in the 290 // the system time can yield problems due to inaccuracies in the
319 // underlying storage system (which uses a double with only 52 bits of 291 // underlying storage system (which uses a double with only 52 bits of
320 // precision to store the 64-bit "time" number). http://crbug.com/346827 292 // precision to store the 64-bit "time" number). http://crbug.com/346827
321 base::Time before = base::Time::Now(); 293 base::Time before = base::Time::Now();
(...skipping 13 matching lines...) Expand all
335 GetCache()->AddProfileToCache( 307 GetCache()->AddProfileToCache(
336 GetProfilePath("path_2"), profile_name, base::string16(), 0, 308 GetProfilePath("path_2"), profile_name, base::string16(), 0,
337 std::string()); 309 std::string());
338 310
339 int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); 311 int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1"));
340 int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); 312 int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2"));
341 313
342 // Sanity check. 314 // Sanity check.
343 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); 315 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
344 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty()); 316 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty());
345 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index1));
346 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2));
347 317
348 // Set GAIA name. 318 // Set GAIA name. This re-sorts the cache.
349 base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); 319 base::string16 gaia_name(ASCIIToUTF16("Pat Smith"));
350 GetCache()->SetGAIANameOfProfileAtIndex(index2, gaia_name); 320 GetCache()->SetGAIANameOfProfileAtIndex(index2, gaia_name);
351 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
352 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
353 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2));
354
355 // Use GAIA name as profile name. This re-sorts the cache.
356 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, true);
357 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); 321 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1"));
358 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); 322 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2"));
359 323
360 EXPECT_EQ(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2), true); 324 // Since there is a GAIA name, we use that as a display name.
325 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty());
326 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
361 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2)); 327 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2));
362 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
363 328
364 // Don't use GAIA name as profile name. This re-sorts the cache. 329 // Don't use GAIA name as profile name. This re-sorts the cache.
365 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, false); 330 base::string16 custom_name(ASCIIToUTF16("Custom name"));
331 GetCache()->SetNameOfProfileAtIndex(index2, custom_name);
366 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); 332 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1"));
367 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); 333 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2"));
368 334
369 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2)); 335 EXPECT_EQ(custom_name, GetCache()->GetNameOfProfileAtIndex(index2));
370 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); 336 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2));
371 } 337 }
372 338
373 TEST_F(ProfileInfoCacheTest, GAIAPicture) { 339 TEST_F(ProfileInfoCacheTest, GAIAPicture) {
374 GetCache()->AddProfileToCache( 340 GetCache()->AddProfileToCache(
375 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 341 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
376 base::string16(), 0, std::string()); 342 base::string16(), 0, std::string());
377 GetCache()->AddProfileToCache( 343 GetCache()->AddProfileToCache(
378 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), 344 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
379 base::string16(), 0, std::string()); 345 base::string16(), 0, std::string());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 const gfx::Image& profile_image( 433 const gfx::Image& profile_image(
468 ResourceBundle::GetSharedInstance().GetImageNamed(id)); 434 ResourceBundle::GetSharedInstance().GetImageNamed(id));
469 435
470 GetCache()->AddProfileToCache( 436 GetCache()->AddProfileToCache(
471 GetProfilePath("path_1"), profile_name, base::string16(), 0, 437 GetProfilePath("path_1"), profile_name, base::string16(), 0,
472 std::string()); 438 std::string());
473 439
474 // Set empty GAIA info. 440 // Set empty GAIA info.
475 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); 441 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16());
476 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); 442 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL);
477 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
478 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); 443 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
479 444
480 // Verify that the profile name and picture are not empty. 445 // Verify that the profile name and picture are not empty.
481 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); 446 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0));
482 EXPECT_TRUE(gfx::test::IsEqual( 447 EXPECT_TRUE(gfx::test::IsEqual(
483 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); 448 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
484 } 449 }
485 450
486 TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) { 451 TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) {
487 testing_profile_manager_.CreateTestingProfile("default"); 452 testing_profile_manager_.CreateTestingProfile("default");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 495
531 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); 496 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles());
532 497
533 // Check that the profiles can be extracted from the local state. 498 // Check that the profiles can be extracted from the local state.
534 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); 499 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames();
535 for (size_t i = 0; i < 4; i++) 500 for (size_t i = 0; i < 4; i++)
536 ASSERT_FALSE(names[i].empty()); 501 ASSERT_FALSE(names[i].empty());
537 } 502 }
538 503
539 } // namespace 504 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698