Chromium Code Reviews| 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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 base::RunLoop().RunUntilIdle(); | 583 base::RunLoop().RunUntilIdle(); |
| 584 | 584 |
| 585 // Clean up. | 585 // Clean up. |
| 586 base::FilePath icon_path = | 586 base::FilePath icon_path = |
| 587 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | 587 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); |
| 588 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); | 588 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); |
| 589 EXPECT_TRUE(base::PathExists(icon_path)); | 589 EXPECT_TRUE(base::PathExists(icon_path)); |
| 590 EXPECT_TRUE(base::DeleteFile(icon_path, true)); | 590 EXPECT_TRUE(base::DeleteFile(icon_path, true)); |
| 591 EXPECT_FALSE(base::PathExists(icon_path)); | 591 EXPECT_FALSE(base::PathExists(icon_path)); |
| 592 } | 592 } |
| 593 | |
| 594 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { | |
| 595 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | |
| 596 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | |
| 597 | |
| 598 base::FilePath path_1 = GetProfilePath("path_1"); | |
| 599 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("Default Profile"), | |
| 600 base::string16(), 0, std::string()); | |
| 601 base::FilePath path_2 = GetProfilePath("path_2"); | |
| 602 GetCache()->AddProfileToCache(path_2, ASCIIToUTF16("First user"), | |
| 603 base::string16(), 1, std::string()); | |
| 604 base::string16 name_3 = ASCIIToUTF16("Lemonade"); | |
| 605 base::FilePath path_3 = GetProfilePath("path_3"); | |
| 606 GetCache()->AddProfileToCache(path_3, name_3, | |
| 607 base::string16(), 2, std::string()); | |
| 608 base::string16 name_4 = ASCIIToUTF16("Batman"); | |
| 609 base::FilePath path_4 = GetProfilePath("path_4"); | |
| 610 GetCache()->AddProfileToCache(path_4, name_4, | |
| 611 base::string16(), 3, std::string()); | |
| 612 EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); | |
|
rpetterson
2014/08/22 20:36:10
You could also add a fifth person whose name is "P
noms (inactive)
2014/08/22 20:44:35
Oh, that's a great idea. Thanks!
| |
| 613 | |
| 614 ResetCache(); | |
| 615 | |
| 616 // Legacy profile names like "Default Profile" and "First user" should be | |
| 617 // migrated to "Person %n" type names. | |
| 618 EXPECT_EQ(ASCIIToUTF16("Person 1"), GetCache()->GetNameOfProfileAtIndex( | |
| 619 GetCache()->GetIndexOfProfileWithPath(path_1))); | |
| 620 EXPECT_EQ(ASCIIToUTF16("Person 2"), GetCache()->GetNameOfProfileAtIndex( | |
| 621 GetCache()->GetIndexOfProfileWithPath(path_2))); | |
| 622 | |
| 623 // Other profile names should not be migrated even if they're the old | |
| 624 // default cartoon profile names. | |
| 625 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | |
| 626 GetCache()->GetIndexOfProfileWithPath(path_3))); | |
| 627 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | |
| 628 GetCache()->GetIndexOfProfileWithPath(path_4))); | |
| 629 } | |
| 593 #endif | 630 #endif |
| 631 | |
| 632 TEST_F(ProfileInfoCacheTest, | |
| 633 DontMigrateLegacyProfileNamesWithoutNewAvatarMenu) { | |
| 634 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | |
| 635 | |
| 636 base::string16 name_1 = ASCIIToUTF16("Default Profile"); | |
| 637 base::FilePath path_1 = GetProfilePath("path_1"); | |
| 638 GetCache()->AddProfileToCache(path_1, name_1, | |
| 639 base::string16(), 0, std::string()); | |
| 640 base::string16 name_2 = ASCIIToUTF16("First user"); | |
| 641 base::FilePath path_2 = GetProfilePath("path_2"); | |
| 642 GetCache()->AddProfileToCache(path_2, name_2, | |
| 643 base::string16(), 1, std::string()); | |
| 644 base::string16 name_3 = ASCIIToUTF16("Lemonade"); | |
| 645 base::FilePath path_3 = GetProfilePath("path_3"); | |
| 646 GetCache()->AddProfileToCache(path_3, name_3, | |
| 647 base::string16(), 2, std::string()); | |
| 648 base::string16 name_4 = ASCIIToUTF16("Batman"); | |
| 649 base::FilePath path_4 = GetProfilePath("path_4"); | |
| 650 GetCache()->AddProfileToCache(path_4, name_4, | |
| 651 base::string16(), 3, std::string()); | |
| 652 EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); | |
| 653 | |
| 654 ResetCache(); | |
| 655 | |
| 656 // Profile names should have been preserved. | |
| 657 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( | |
| 658 GetCache()->GetIndexOfProfileWithPath(path_1))); | |
| 659 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( | |
| 660 GetCache()->GetIndexOfProfileWithPath(path_2))); | |
| 661 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | |
| 662 GetCache()->GetIndexOfProfileWithPath(path_3))); | |
| 663 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | |
| 664 GetCache()->GetIndexOfProfileWithPath(path_4))); | |
| 665 } | |
| 666 | |
| OLD | NEW |