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 <objbase.h> // For CoInitialize(). | 5 #include <objbase.h> // For CoInitialize(). |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Delete all profiles and ensure their shortcuts got removed. | 65 // Delete all profiles and ensure their shortcuts got removed. |
| 66 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); | 66 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); |
| 67 for (int i = 0; i < num_profiles; ++i) { | 67 for (int i = 0; i < num_profiles; ++i) { |
| 68 const base::FilePath profile_path = | 68 const base::FilePath profile_path = |
| 69 profile_info_cache_->GetPathOfProfileAtIndex(0); | 69 profile_info_cache_->GetPathOfProfileAtIndex(0); |
| 70 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); | 70 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); |
| 71 profile_info_cache_->DeleteProfileFromCache(profile_path); | 71 profile_info_cache_->DeleteProfileFromCache(profile_path); |
| 72 RunPendingTasks(); | 72 RunPendingTasks(); |
| 73 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); | 73 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); |
| 74 const base::FilePath icon_path = | 74 const base::FilePath icon_path = |
| 75 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 75 profiles::internal::GetProfileIconPath(profile_path); |
| 76 ASSERT_FALSE(file_util::PathExists(icon_path)); | 76 // The icon file should not be deleted on shortcut deletion. |
|
gab
2013/07/11 12:30:16
Wait, this is wrong, no? It is true that the icon
calamity
2013/07/12 07:55:08
Profile directories are not cleaned up on the file
gab
2013/07/12 11:47:45
Hmm, okay, so then why is the directory absent in
gab
2013/07/16 14:10:38
Ok, then the comment above should state that, not
gab
2013/07/16 14:10:38
Ah okay I see, so it's not that it's deleted too e
calamity
2013/07/18 08:39:08
This test is fine. It's others that are failing. T
| |
| 77 ASSERT_TRUE(file_util::PathExists(icon_path)); | |
| 78 ASSERT_TRUE(base::Delete(icon_path, false)); | |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 base::FilePath CreateProfileDirectory(const string16& profile_name) { | 82 base::FilePath CreateProfileDirectory(const string16& profile_name) { |
| 81 const base::FilePath profile_path = | 83 const base::FilePath profile_path = |
| 82 profile_info_cache_->GetUserDataDir().Append(profile_name); | 84 profile_info_cache_->GetUserDataDir().Append(profile_name); |
| 83 file_util::CreateDirectoryW(profile_path); | 85 file_util::CreateDirectoryW(profile_path); |
| 84 return profile_path; | 86 return profile_path; |
| 85 } | 87 } |
| 86 | 88 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 129 |
| 128 // Calls base::win::ValidateShortcut() with expected properties for the | 130 // Calls base::win::ValidateShortcut() with expected properties for the |
| 129 // shortcut at |shortcut_path| for the profile at |profile_path|. | 131 // shortcut at |shortcut_path| for the profile at |profile_path|. |
| 130 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, | 132 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, |
| 131 const base::FilePath& shortcut_path, | 133 const base::FilePath& shortcut_path, |
| 132 const base::FilePath& profile_path) { | 134 const base::FilePath& profile_path) { |
| 133 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); | 135 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 134 | 136 |
| 135 // Ensure that the corresponding icon exists. | 137 // Ensure that the corresponding icon exists. |
| 136 const base::FilePath icon_path = | 138 const base::FilePath icon_path = |
| 137 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 139 profiles::internal::GetProfileIconPath(profile_path); |
| 138 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); | 140 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); |
| 139 | 141 |
| 140 base::win::ShortcutProperties expected_properties; | 142 base::win::ShortcutProperties expected_properties; |
| 141 expected_properties.set_app_id( | 143 expected_properties.set_app_id( |
| 142 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); | 144 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); |
| 143 expected_properties.set_target(GetExePath()); | 145 expected_properties.set_target(GetExePath()); |
| 144 expected_properties.set_description(GetDistribution()->GetAppDescription()); | 146 expected_properties.set_description(GetDistribution()->GetAppDescription()); |
| 145 expected_properties.set_dual_mode(false); | 147 expected_properties.set_dual_mode(false); |
| 146 expected_properties.set_arguments( | 148 expected_properties.set_arguments( |
| 147 profiles::internal::CreateProfileShortcutFlags(profile_path)); | 149 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 | 755 |
| 754 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 756 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
| 755 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false)); | 757 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false)); |
| 756 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 758 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 757 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | 759 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); |
| 758 | 760 |
| 759 const base::FilePath system_level_shortcut_path = | 761 const base::FilePath system_level_shortcut_path = |
| 760 CreateRegularSystemLevelShortcut(FROM_HERE); | 762 CreateRegularSystemLevelShortcut(FROM_HERE); |
| 761 | 763 |
| 762 // Delete the profile that has a shortcut, which will exercise the non-profile | 764 // Delete the profile that has a shortcut, which will exercise the non-profile |
| 763 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is | 765 // shortcut creation path in |DeleteDesktopShortcuts()|, which is |
| 764 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | 766 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. |
| 765 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | 767 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 766 RunPendingTasks(); | 768 RunPendingTasks(); |
| 767 | 769 |
| 768 // Verify that only the system-level shortcut still exists. | 770 // Verify that only the system-level shortcut still exists. |
| 769 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | 771 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
| 770 EXPECT_FALSE(file_util::PathExists( | 772 EXPECT_FALSE(file_util::PathExists( |
| 771 GetDefaultShortcutPathForProfile(string16()))); | 773 GetDefaultShortcutPathForProfile(string16()))); |
| 772 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 774 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 773 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 775 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
| 774 } | 776 } |
| 777 | |
| 778 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) { | |
| 779 SetupDefaultProfileShortcut(FROM_HERE); | |
| 780 | |
| 781 const base::FilePath icon_path = | |
| 782 profiles::internal::GetProfileIconPath(profile_1_path_); | |
| 783 | |
| 784 EXPECT_TRUE(file_util::PathExists(icon_path)); | |
| 785 EXPECT_TRUE(base::Delete(icon_path, false)); | |
| 786 EXPECT_FALSE(file_util::PathExists(icon_path)); | |
| 787 | |
| 788 profile_shortcut_manager_->CreateOrUpdateProfileIcon(profile_1_path_, | |
| 789 base::Closure()); | |
| 790 RunPendingTasks(); | |
| 791 EXPECT_TRUE(file_util::PathExists(icon_path)); | |
| 792 } | |
| 793 | |
| 794 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) { | |
| 795 SetupDefaultProfileShortcut(FROM_HERE); | |
| 796 const base::FilePath icon_path_1 = | |
| 797 profiles::internal::GetProfileIconPath(profile_1_path_); | |
| 798 const base::FilePath icon_path_2 = | |
| 799 profiles::internal::GetProfileIconPath(profile_2_path_); | |
| 800 | |
| 801 // Default profile has unbadged icon to start. | |
| 802 std::string unbadged_icon_1; | |
| 803 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); | |
| 804 | |
| 805 // Creating a new profile adds a badge to both the new profile icon and the | |
| 806 // default profile icon. Since they use the same icon index, the icon files | |
| 807 // should be the same. | |
| 808 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | |
| 809 | |
| 810 std::string badged_icon_1; | |
| 811 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); | |
| 812 std::string badged_icon_2; | |
| 813 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); | |
| 814 | |
| 815 EXPECT_NE(badged_icon_1, unbadged_icon_1); | |
| 816 EXPECT_EQ(badged_icon_1, badged_icon_2); | |
| 817 | |
| 818 // Deleting the default profile will unbadge the new profile's icon and should | |
| 819 // result in an icon that is identical to the unbadged default profile icon. | |
| 820 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); | |
| 821 RunPendingTasks(); | |
| 822 | |
| 823 std::string unbadged_icon_2; | |
| 824 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &unbadged_icon_2)); | |
| 825 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); | |
| 826 } | |
| 827 | |
| 828 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { | |
| 829 SetupAndCreateTwoShortcuts(FROM_HERE); | |
| 830 const base::FilePath icon_path_1 = | |
| 831 profiles::internal::GetProfileIconPath(profile_1_path_); | |
| 832 const base::FilePath icon_path_2 = | |
| 833 profiles::internal::GetProfileIconPath(profile_2_path_); | |
| 834 const size_t profile_index_1 = | |
| 835 profile_info_cache_->GetIndexOfProfileWithPath(profile_1_path_); | |
| 836 | |
| 837 std::string badged_icon_1; | |
| 838 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); | |
| 839 std::string badged_icon_2; | |
| 840 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); | |
| 841 | |
| 842 // Profile 1 and 2 are created with the same icon. | |
| 843 EXPECT_EQ(badged_icon_1, badged_icon_2); | |
| 844 | |
| 845 // Change profile 1's icon. | |
| 846 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); | |
| 847 RunPendingTasks(); | |
| 848 | |
| 849 std::string new_badged_icon_1; | |
| 850 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &new_badged_icon_1)); | |
| 851 EXPECT_NE(new_badged_icon_1, badged_icon_1); | |
| 852 | |
| 853 // Ensure the new icon is not the unbadged icon. | |
| 854 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | |
| 855 RunPendingTasks(); | |
| 856 | |
| 857 std::string unbadged_icon_1; | |
| 858 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); | |
| 859 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); | |
| 860 | |
| 861 // Ensure the icon doesn't change on avatar change without 2 profiles. | |
| 862 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); | |
| 863 RunPendingTasks(); | |
| 864 | |
| 865 std::string unbadged_icon_1_a; | |
| 866 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); | |
| 867 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); | |
| 868 } | |
| OLD | NEW |