| 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. |
| 77 ASSERT_TRUE(file_util::PathExists(icon_path)); |
| 78 ASSERT_TRUE(file_util::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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 132 |
| 131 // Calls base::win::ValidateShortcut() with expected properties for the | 133 // Calls base::win::ValidateShortcut() with expected properties for the |
| 132 // shortcut at |shortcut_path| for the profile at |profile_path|. | 134 // shortcut at |shortcut_path| for the profile at |profile_path|. |
| 133 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, | 135 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, |
| 134 const base::FilePath& shortcut_path, | 136 const base::FilePath& shortcut_path, |
| 135 const base::FilePath& profile_path) { | 137 const base::FilePath& profile_path) { |
| 136 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); | 138 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 137 | 139 |
| 138 // Ensure that the corresponding icon exists. | 140 // Ensure that the corresponding icon exists. |
| 139 const base::FilePath icon_path = | 141 const base::FilePath icon_path = |
| 140 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 142 profiles::internal::GetProfileIconPath(profile_path); |
| 141 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); | 143 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); |
| 142 | 144 |
| 143 base::win::ShortcutProperties expected_properties; | 145 base::win::ShortcutProperties expected_properties; |
| 144 expected_properties.set_target(GetExePath()); | 146 expected_properties.set_target(GetExePath()); |
| 145 expected_properties.set_description(GetDistribution()->GetAppDescription()); | 147 expected_properties.set_description(GetDistribution()->GetAppDescription()); |
| 146 expected_properties.set_dual_mode(false); | 148 expected_properties.set_dual_mode(false); |
| 147 expected_properties.set_arguments( | 149 expected_properties.set_arguments( |
| 148 profiles::internal::CreateProfileShortcutFlags(profile_path)); | 150 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| 149 expected_properties.set_icon(icon_path, 0); | 151 expected_properties.set_icon(icon_path, 0); |
| 150 base::win::ValidateShortcut(shortcut_path, expected_properties); | 152 base::win::ValidateShortcut(shortcut_path, expected_properties); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 756 |
| 755 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 757 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
| 756 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); | 758 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); |
| 757 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 759 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 758 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | 760 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); |
| 759 | 761 |
| 760 const base::FilePath system_level_shortcut_path = | 762 const base::FilePath system_level_shortcut_path = |
| 761 CreateRegularSystemLevelShortcut(FROM_HERE); | 763 CreateRegularSystemLevelShortcut(FROM_HERE); |
| 762 | 764 |
| 763 // Delete the profile that has a shortcut, which will exercise the non-profile | 765 // Delete the profile that has a shortcut, which will exercise the non-profile |
| 764 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is | 766 // shortcut creation path in |DeleteDesktopShortcuts()|, which is |
| 765 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | 767 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. |
| 766 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | 768 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 767 RunPendingTasks(); | 769 RunPendingTasks(); |
| 768 | 770 |
| 769 // Verify that only the system-level shortcut still exists. | 771 // Verify that only the system-level shortcut still exists. |
| 770 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | 772 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
| 771 EXPECT_FALSE(file_util::PathExists( | 773 EXPECT_FALSE(file_util::PathExists( |
| 772 GetDefaultShortcutPathForProfile(string16()))); | 774 GetDefaultShortcutPathForProfile(string16()))); |
| 773 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 775 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 774 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 776 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
| 775 } | 777 } |
| 778 |
| 779 TEST_F(ProfileShortcutManagerTest, |
| 780 CreateProfileIcon) { |
| 781 SetupDefaultProfileShortcut(FROM_HERE); |
| 782 |
| 783 base::FilePath icon_path = |
| 784 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 785 |
| 786 EXPECT_TRUE(file_util::PathExists(icon_path)); |
| 787 EXPECT_TRUE(file_util::Delete(icon_path, false)); |
| 788 EXPECT_FALSE(file_util::PathExists(icon_path)); |
| 789 |
| 790 profile_shortcut_manager_->CreateProfileIcon(profile_1_path_); |
| 791 RunPendingTasks(); |
| 792 EXPECT_TRUE(file_util::PathExists(icon_path)); |
| 793 } |
| OLD | NEW |