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 base::string16 name_5 = ASCIIToUTF16("Person 2"); |
| 613 base::FilePath path_5 = GetProfilePath("path_5"); |
| 614 GetCache()->AddProfileToCache(path_5, name_5, |
| 615 base::string16(), 2, std::string()); |
| 616 |
| 617 EXPECT_EQ(5U, GetCache()->GetNumberOfProfiles()); |
| 618 |
| 619 |
| 620 ResetCache(); |
| 621 |
| 622 // Legacy profile names like "Default Profile" and "First user" should be |
| 623 // migrated to "Person %n" type names. |
| 624 EXPECT_EQ(ASCIIToUTF16("Person 1"), GetCache()->GetNameOfProfileAtIndex( |
| 625 GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 626 EXPECT_EQ(ASCIIToUTF16("Person 3"), GetCache()->GetNameOfProfileAtIndex( |
| 627 GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 628 |
| 629 // Other profile names should not be migrated even if they're the old |
| 630 // default cartoon profile names. |
| 631 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 632 GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 633 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 634 GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 635 EXPECT_EQ(name_5, GetCache()->GetNameOfProfileAtIndex( |
| 636 GetCache()->GetIndexOfProfileWithPath(path_5))); |
| 637 } |
593 #endif | 638 #endif |
| 639 |
| 640 TEST_F(ProfileInfoCacheTest, |
| 641 DontMigrateLegacyProfileNamesWithoutNewAvatarMenu) { |
| 642 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
| 643 |
| 644 base::string16 name_1 = ASCIIToUTF16("Default Profile"); |
| 645 base::FilePath path_1 = GetProfilePath("path_1"); |
| 646 GetCache()->AddProfileToCache(path_1, name_1, |
| 647 base::string16(), 0, std::string()); |
| 648 base::string16 name_2 = ASCIIToUTF16("First user"); |
| 649 base::FilePath path_2 = GetProfilePath("path_2"); |
| 650 GetCache()->AddProfileToCache(path_2, name_2, |
| 651 base::string16(), 1, std::string()); |
| 652 base::string16 name_3 = ASCIIToUTF16("Lemonade"); |
| 653 base::FilePath path_3 = GetProfilePath("path_3"); |
| 654 GetCache()->AddProfileToCache(path_3, name_3, |
| 655 base::string16(), 2, std::string()); |
| 656 base::string16 name_4 = ASCIIToUTF16("Batman"); |
| 657 base::FilePath path_4 = GetProfilePath("path_4"); |
| 658 GetCache()->AddProfileToCache(path_4, name_4, |
| 659 base::string16(), 3, std::string()); |
| 660 EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
| 661 |
| 662 ResetCache(); |
| 663 |
| 664 // Profile names should have been preserved. |
| 665 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
| 666 GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 667 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
| 668 GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 669 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 670 GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 671 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 672 GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 673 } |
| 674 |
OLD | NEW |