| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/location.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/test/scoped_path_override.h" | 11 #include "base/test/scoped_path_override.h" |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 #include "base/test/test_shortcut_win.h" | 13 #include "base/test/test_shortcut_win.h" |
| 13 #include "base/win/shortcut.h" | 14 #include "base/win/shortcut.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 17 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 17 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | 18 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
| 18 #include "chrome/installer/util/browser_distribution.h" | 19 #include "chrome/installer/util/browser_distribution.h" |
| 20 #include "chrome/installer/util/product.h" |
| 19 #include "chrome/installer/util/shell_util.h" | 21 #include "chrome/installer/util/shell_util.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| 26 using content::BrowserThread; | 28 using content::BrowserThread; |
| 27 | 29 |
| 28 class ProfileShortcutManagerTest : public testing::Test { | 30 class ProfileShortcutManagerTest : public testing::Test { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 | 45 |
| 44 TestingBrowserProcess* browser_process = | 46 TestingBrowserProcess* browser_process = |
| 45 static_cast<TestingBrowserProcess*>(g_browser_process); | 47 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 46 profile_manager_.reset(new TestingProfileManager(browser_process)); | 48 profile_manager_.reset(new TestingProfileManager(browser_process)); |
| 47 ASSERT_TRUE(profile_manager_->SetUp()); | 49 ASSERT_TRUE(profile_manager_->SetUp()); |
| 48 profile_info_cache_ = profile_manager_->profile_info_cache(); | 50 profile_info_cache_ = profile_manager_->profile_info_cache(); |
| 49 profile_shortcut_manager_.reset( | 51 profile_shortcut_manager_.reset( |
| 50 ProfileShortcutManager::Create(profile_manager_->profile_manager())); | 52 ProfileShortcutManager::Create(profile_manager_->profile_manager())); |
| 51 | 53 |
| 52 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); | 54 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); |
| 53 dest_path_ = profile_info_cache_->GetUserDataDir(); | |
| 54 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); | |
| 55 file_util::CreateDirectoryW(dest_path_); | |
| 56 profile_name_ = L"My profile"; | |
| 57 | |
| 58 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 55 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 59 distribution_, | 56 distribution_, |
| 60 ShellUtil::CURRENT_USER, | 57 ShellUtil::CURRENT_USER, |
| 61 &shortcuts_directory_)); | 58 &shortcuts_directory_)); |
| 62 | 59 |
| 63 second_dest_path_ = profile_info_cache_->GetUserDataDir(); | 60 profile_1_name_ = L"My profile"; |
| 64 second_dest_path_ = | 61 profile_1_path_ = CreateProfileDirectory(profile_1_name_); |
| 65 second_dest_path_.Append(FILE_PATH_LITERAL("My profile 2")); | 62 profile_2_name_ = L"My profile 2"; |
| 66 file_util::CreateDirectoryW(second_dest_path_); | 63 profile_2_path_ = CreateProfileDirectory(profile_2_name_); |
| 67 second_profile_name_ = L"My profile 2"; | |
| 68 } | 64 } |
| 69 | 65 |
| 70 virtual void TearDown() OVERRIDE { | 66 virtual void TearDown() OVERRIDE { |
| 71 message_loop_.RunUntilIdle(); | 67 message_loop_.RunUntilIdle(); |
| 72 | 68 |
| 73 // Remove all shortcuts except the last (since it will no longer have | 69 // Remove all shortcuts except the last (since it will no longer have |
| 74 // an appended name). | 70 // an appended name). |
| 75 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); | 71 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); |
| 76 for (int i = 0; i < num_profiles; ++i) { | 72 for (int i = 0; i < num_profiles; ++i) { |
| 77 const FilePath profile_path = | 73 const FilePath profile_path = |
| 78 profile_info_cache_->GetPathOfProfileAtIndex(0); | 74 profile_info_cache_->GetPathOfProfileAtIndex(0); |
| 79 string16 profile_name; | 75 string16 profile_name; |
| 80 if (i != num_profiles - 1) | 76 if (i != num_profiles - 1) |
| 81 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); | 77 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); |
| 82 profile_info_cache_->DeleteProfileFromCache(profile_path); | 78 profile_info_cache_->DeleteProfileFromCache(profile_path); |
| 83 RunPendingTasks(); | 79 RunPendingTasks(); |
| 84 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); | 80 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); |
| 85 ASSERT_FALSE(file_util::PathExists(profile_path.Append( | 81 const FilePath icon_path = |
| 86 FILE_PATH_LITERAL("Google Profile.ico")))); | 82 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); |
| 83 ASSERT_FALSE(file_util::PathExists(icon_path)); |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 87 FilePath CreateProfileDirectory(const string16& profile_name) { |
| 88 const FilePath profile_path = |
| 89 profile_info_cache_->GetUserDataDir().Append(profile_name); |
| 90 file_util::CreateDirectoryW(profile_path); |
| 91 return profile_path; |
| 92 } |
| 93 |
| 90 void RunPendingTasks() { | 94 void RunPendingTasks() { |
| 91 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 95 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 92 MessageLoop::current()->Run(); | 96 MessageLoop::current()->Run(); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void SetupDefaultProfileShortcut() { | 99 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { |
| 96 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 100 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) |
| 101 << location.ToString(); |
| 97 // A non-badged shortcut for chrome is automatically created with the | 102 // A non-badged shortcut for chrome is automatically created with the |
| 98 // first profile (for the case when the user deletes their only profile). | 103 // first profile (for the case when the user deletes their only profile). |
| 99 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, | 104 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, |
| 100 string16(), 0); | 105 string16(), 0); |
| 101 RunPendingTasks(); | 106 RunPendingTasks(); |
| 102 // We now have 1 profile, so we expect a new shortcut with no profile | 107 // We now have 1 profile, so we expect a new shortcut with no profile |
| 103 // information. | 108 // information. |
| 104 ValidateProfileShortcut(string16()); | 109 ValidateProfileShortcut(location, string16(), profile_1_path_); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void SetupAndCreateTwoShortcuts() { | 112 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { |
| 108 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()); | 113 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()) |
| 109 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 114 << location.ToString(); |
| 110 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 115 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) |
| 116 << location.ToString(); |
| 111 | 117 |
| 112 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, | 118 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, |
| 113 string16(), 0); | 119 string16(), 0); |
| 114 profile_info_cache_->AddProfileToCache(second_dest_path_, | 120 CreateProfileWithShortcut(location, profile_2_name_, profile_2_path_); |
| 115 second_profile_name_, string16(), 0); | 121 ValidateProfileShortcut(location, profile_1_name_, profile_1_path_); |
| 116 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
| 117 RunPendingTasks(); | |
| 118 ValidateProfileShortcut(profile_name_); | |
| 119 ValidateProfileShortcut(second_profile_name_); | |
| 120 } | 122 } |
| 121 | 123 |
| 122 // Returns the default shortcut path for this profile. | 124 // Returns the default shortcut path for this profile. |
| 123 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { | 125 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { |
| 124 return shortcuts_directory_.Append( | 126 return shortcuts_directory_.Append( |
| 125 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 127 profiles::internal::GetShortcutFilenameForProfile(profile_name, |
| 126 distribution_)); | 128 distribution_)); |
| 127 } | 129 } |
| 128 | 130 |
| 129 // Returns true if the shortcut for this profile exists. | 131 // Returns true if the shortcut for this profile exists. |
| 130 bool ProfileShortcutExistsAtDefaultPath(const string16& profile_name) { | 132 bool ProfileShortcutExistsAtDefaultPath(const string16& profile_name) { |
| 131 return file_util::PathExists( | 133 return file_util::PathExists( |
| 132 GetDefaultShortcutPathForProfile(profile_name)); | 134 GetDefaultShortcutPathForProfile(profile_name)); |
| 133 } | 135 } |
| 134 | 136 |
| 135 // Calls base::win::ValidateShortcut() with expected properties for | 137 // Calls base::win::ValidateShortcut() with expected properties for the |
| 136 // |profile_name|'s shortcut. | 138 // shortcut at |shortcut_path| for the profile at |profile_path|. |
| 137 void ValidateProfileShortcut(const string16& profile_name) { | 139 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, |
| 138 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(profile_name)); | 140 const FilePath& shortcut_path, |
| 139 | 141 const FilePath& profile_path) { |
| 140 FilePath shortcut_path = GetDefaultShortcutPathForProfile(profile_name); | 142 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 141 | 143 |
| 142 // TODO(asvitkine): With this new struct method for VerifyShortcut you can | 144 // TODO(asvitkine): With this new struct method for VerifyShortcut you can |
| 143 // now test more properties like: arguments, icon, icon_index, and app_id. | 145 // now test more properties like: arguments, icon, icon_index, and app_id. |
| 144 base::win::ShortcutProperties expected_properties; | 146 base::win::ShortcutProperties expected_properties; |
| 145 expected_properties.set_target(exe_path_); | 147 expected_properties.set_target(exe_path_); |
| 146 expected_properties.set_description(distribution_->GetAppDescription()); | 148 expected_properties.set_description(distribution_->GetAppDescription()); |
| 147 expected_properties.set_dual_mode(false); | 149 expected_properties.set_dual_mode(false); |
| 150 expected_properties.set_arguments( |
| 151 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| 148 base::win::ValidateShortcut(shortcut_path, expected_properties); | 152 base::win::ValidateShortcut(shortcut_path, expected_properties); |
| 149 } | 153 } |
| 150 | 154 |
| 155 // Calls base::win::ValidateShortcut() with expected properties for |
| 156 // |profile_name|'s shortcut. |
| 157 void ValidateProfileShortcut(const tracked_objects::Location& location, |
| 158 const string16& profile_name, |
| 159 const FilePath& profile_path) { |
| 160 ValidateProfileShortcutAtPath( |
| 161 location, GetDefaultShortcutPathForProfile(profile_name), profile_path); |
| 162 } |
| 163 |
| 164 void CreateProfileWithShortcut(const tracked_objects::Location& location, |
| 165 const string16& profile_name, |
| 166 const FilePath& profile_path) { |
| 167 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) |
| 168 << location.ToString(); |
| 169 profile_info_cache_->AddProfileToCache(profile_path, profile_name, |
| 170 string16(), 0); |
| 171 profile_shortcut_manager_->CreateProfileShortcut(profile_path); |
| 172 RunPendingTasks(); |
| 173 ValidateProfileShortcut(location, profile_name, profile_path); |
| 174 } |
| 175 |
| 176 // Creates a regular (non-profile) desktop shortcut with the given name and |
| 177 // returns its path. Fails the test if an error occurs. |
| 178 FilePath CreateRegularShortcutWithName( |
| 179 const tracked_objects::Location& location, |
| 180 const string16& shortcut_name) { |
| 181 const FilePath shortcut_path = |
| 182 shortcuts_directory_.Append(shortcut_name + installer::kLnkExt); |
| 183 EXPECT_FALSE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 184 |
| 185 installer::Product product(distribution_); |
| 186 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
| 187 product.AddDefaultShortcutProperties(exe_path_, &properties); |
| 188 properties.set_shortcut_name(shortcut_name); |
| 189 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 190 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, |
| 191 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); |
| 192 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 193 |
| 194 return shortcut_path; |
| 195 } |
| 196 |
| 151 BrowserDistribution* distribution_; | 197 BrowserDistribution* distribution_; |
| 152 MessageLoopForUI message_loop_; | 198 MessageLoopForUI message_loop_; |
| 153 content::TestBrowserThread ui_thread_; | 199 content::TestBrowserThread ui_thread_; |
| 154 content::TestBrowserThread file_thread_; | 200 content::TestBrowserThread file_thread_; |
| 155 scoped_ptr<TestingProfileManager> profile_manager_; | 201 scoped_ptr<TestingProfileManager> profile_manager_; |
| 156 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; | 202 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
| 157 ProfileInfoCache* profile_info_cache_; | 203 ProfileInfoCache* profile_info_cache_; |
| 158 base::ScopedPathOverride fake_user_desktop_; | 204 base::ScopedPathOverride fake_user_desktop_; |
| 159 FilePath exe_path_; | 205 FilePath exe_path_; |
| 160 FilePath dest_path_; | |
| 161 FilePath shortcuts_directory_; | 206 FilePath shortcuts_directory_; |
| 162 string16 profile_name_; | 207 string16 profile_1_name_; |
| 163 FilePath second_dest_path_; | 208 FilePath profile_1_path_; |
| 164 string16 second_profile_name_; | 209 string16 profile_2_name_; |
| 210 FilePath profile_2_path_; |
| 165 }; | 211 }; |
| 166 | 212 |
| 167 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { | 213 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { |
| 168 const string16 kProfileName = L"Harry"; | 214 const string16 kProfileName = L"Harry"; |
| 169 const string16 expected_name = kProfileName + L" - " + | 215 const string16 expected_name = kProfileName + L" - " + |
| 170 distribution_->GetAppShortCutName() + installer::kLnkExt; | 216 distribution_->GetAppShortCutName() + installer::kLnkExt; |
| 171 EXPECT_EQ(expected_name, | 217 EXPECT_EQ(expected_name, |
| 172 profiles::internal::GetShortcutFilenameForProfile(kProfileName, | 218 profiles::internal::GetShortcutFilenameForProfile(kProfileName, |
| 173 distribution_)); | 219 distribution_)); |
| 174 } | 220 } |
| 175 | 221 |
| 176 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { | 222 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { |
| 177 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, | 223 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, |
| 178 profiles::internal::GetShortcutFilenameForProfile(string16(), | 224 profiles::internal::GetShortcutFilenameForProfile(string16(), |
| 179 distribution_)); | 225 distribution_)); |
| 180 } | 226 } |
| 181 | 227 |
| 182 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { | 228 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { |
| 183 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 229 SetupDefaultProfileShortcut(FROM_HERE); |
| 184 | 230 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 185 profile_info_cache_->AddProfileToCache(second_dest_path_, | |
| 186 second_profile_name_, string16(), 0); | |
| 187 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
| 188 RunPendingTasks(); | |
| 189 | |
| 190 // We now have 2 profiles, so we expect a new shortcut with profile | 231 // We now have 2 profiles, so we expect a new shortcut with profile |
| 191 // information for this 2nd profile. | 232 // information for this 2nd profile. |
| 192 ValidateProfileShortcut(second_profile_name_); | 233 const FilePath icon_path = |
| 193 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append( | 234 profile_2_path_.AppendASCII(profiles::internal::kProfileIconFileName); |
| 194 FILE_PATH_LITERAL("Google Profile.ico")))); | 235 ASSERT_TRUE(file_util::PathExists(icon_path)); |
| 195 } | 236 } |
| 196 | 237 |
| 197 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { | 238 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { |
| 198 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 239 SetupDefaultProfileShortcut(FROM_HERE); |
| 199 | 240 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 200 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | |
| 201 | |
| 202 profile_info_cache_->AddProfileToCache(second_dest_path_, | |
| 203 second_profile_name_, string16(), 0); | |
| 204 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
| 205 RunPendingTasks(); | |
| 206 ValidateProfileShortcut(second_profile_name_); | |
| 207 | 241 |
| 208 // Cause an update in ProfileShortcutManager by modifying the profile info | 242 // Cause an update in ProfileShortcutManager by modifying the profile info |
| 209 // cache. | 243 // cache. |
| 210 const string16 new_profile_name = L"New Profile Name"; | 244 const string16 new_profile_name = L"New Profile Name"; |
| 211 profile_info_cache_->SetNameOfProfileAtIndex( | 245 profile_info_cache_->SetNameOfProfileAtIndex( |
| 212 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), | 246 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_), |
| 213 new_profile_name); | 247 new_profile_name); |
| 214 RunPendingTasks(); | 248 RunPendingTasks(); |
| 215 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 249 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
| 216 ValidateProfileShortcut(new_profile_name); | 250 ValidateProfileShortcut(FROM_HERE, new_profile_name, profile_2_path_); |
| 217 } | 251 } |
| 218 | 252 |
| 219 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { | 253 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { |
| 220 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 254 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 221 | 255 |
| 222 // Delete one shortcut. | 256 // Delete one shortcut. |
| 223 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 257 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 224 RunPendingTasks(); | 258 RunPendingTasks(); |
| 225 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 259 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
| 226 | 260 |
| 227 // Verify that the profile name has been removed from the remaining shortcut. | 261 // Verify that the profile name has been removed from the remaining shortcut. |
| 228 ValidateProfileShortcut(string16()); | 262 ValidateProfileShortcut(FROM_HERE, string16(), profile_1_path_); |
| 229 // Verify that an additional shortcut, with the default profile's name does | 263 // Verify that an additional shortcut, with the default profile's name does |
| 230 // not exist. | 264 // not exist. |
| 231 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 265 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); |
| 232 } | 266 } |
| 233 | 267 |
| 234 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { | 268 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { |
| 235 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 269 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 236 | 270 |
| 237 // Delete one shortcut. | 271 // Delete one shortcut. |
| 238 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 272 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 239 RunPendingTasks(); | 273 RunPendingTasks(); |
| 240 | 274 |
| 241 // Verify that a default shortcut exists (no profile name/avatar). | 275 // Verify that a default shortcut exists (no profile name/avatar). |
| 242 ValidateProfileShortcut(string16()); | 276 ValidateProfileShortcut(FROM_HERE, string16(), profile_1_path_); |
| 243 // Verify that an additional shortcut, with the default profile's name does | 277 // Verify that an additional shortcut, with the first profile's name does |
| 244 // not exist. | 278 // not exist. |
| 245 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 279 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); |
| 246 | 280 |
| 247 // Create a second profile and shortcut. | 281 // Create a second profile and shortcut. |
| 248 profile_info_cache_->AddProfileToCache(second_dest_path_, | 282 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 249 second_profile_name_, string16(), 0); | |
| 250 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
| 251 RunPendingTasks(); | |
| 252 ValidateProfileShortcut(second_profile_name_); | |
| 253 | 283 |
| 254 // Verify that the original shortcut received the profile's name. | 284 // Verify that the original shortcut received the profile's name. |
| 255 ValidateProfileShortcut(profile_name_); | 285 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
| 256 // Verify that a default shortcut no longer exists. | 286 // Verify that a default shortcut no longer exists. |
| 257 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); | 287 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); |
| 258 } | 288 } |
| 259 | 289 |
| 260 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { | 290 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { |
| 261 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 291 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 262 | 292 |
| 263 const FilePath old_shortcut_path = | 293 const FilePath profile_2_shortcut_path_1 = |
| 264 GetDefaultShortcutPathForProfile(second_profile_name_); | 294 GetDefaultShortcutPathForProfile(profile_2_name_); |
| 265 const FilePath new_shortcut_path = | 295 const FilePath profile_2_shortcut_path_2 = |
| 266 shortcuts_directory_.Append(L"MyChrome.lnk"); | 296 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 267 ASSERT_TRUE(file_util::Move(old_shortcut_path, new_shortcut_path)); | 297 ASSERT_TRUE(file_util::Move(profile_2_shortcut_path_1, |
| 298 profile_2_shortcut_path_2)); |
| 268 | 299 |
| 269 // Ensure that a new shortcut does not get made if the old one was renamed. | 300 // Ensure that a new shortcut does not get made if the old one was renamed. |
| 270 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 301 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); |
| 271 RunPendingTasks(); | 302 RunPendingTasks(); |
| 272 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 303 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
| 273 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 304 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 305 profile_2_path_); |
| 274 | 306 |
| 275 // Delete the renamed shortcut and try to create it again, which should work. | 307 // Delete the renamed shortcut and try to create it again, which should work. |
| 276 ASSERT_TRUE(file_util::Delete(new_shortcut_path, false)); | 308 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path_2, false)); |
| 277 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); | 309 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_2)); |
| 278 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 310 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); |
| 279 RunPendingTasks(); | 311 RunPendingTasks(); |
| 280 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 312 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 281 } | 313 } |
| 282 | 314 |
| 283 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { | 315 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { |
| 284 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 316 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 285 | 317 |
| 286 const FilePath old_shortcut_path = | 318 const FilePath profile_2_shortcut_path_1 = |
| 287 GetDefaultShortcutPathForProfile(second_profile_name_); | 319 GetDefaultShortcutPathForProfile(profile_2_name_); |
| 288 const FilePath new_shortcut_path = | 320 const FilePath profile_2_shortcut_path_2 = |
| 289 shortcuts_directory_.Append(L"MyChrome.lnk"); | 321 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 290 // Make a copy of the shortcut. | 322 // Make a copy of the shortcut. |
| 291 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); | 323 ASSERT_TRUE(file_util::CopyFile(profile_2_shortcut_path_1, |
| 292 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); | 324 profile_2_shortcut_path_2)); |
| 293 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 325 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, |
| 326 profile_2_path_); |
| 327 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 328 profile_2_path_); |
| 294 | 329 |
| 295 // Also, copy the shortcut for the first user and ensure it gets preserved. | 330 // Also, copy the shortcut for the first user and ensure it gets preserved. |
| 296 const FilePath preserved_shortcut_path = | 331 const FilePath preserved_profile_1_shortcut_path = |
| 297 shortcuts_directory_.Append(L"Preserved.lnk"); | 332 shortcuts_directory_.Append(L"Preserved.lnk"); |
| 298 ASSERT_TRUE(file_util::CopyFile( | 333 ASSERT_TRUE(file_util::CopyFile( |
| 299 GetDefaultShortcutPathForProfile(profile_name_), | 334 GetDefaultShortcutPathForProfile(profile_1_name_), |
| 300 preserved_shortcut_path)); | 335 preserved_profile_1_shortcut_path)); |
| 301 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); | 336 EXPECT_TRUE(file_util::PathExists(preserved_profile_1_shortcut_path)); |
| 302 | 337 |
| 303 // Delete the profile and ensure both shortcuts were also deleted. | 338 // Delete the profile and ensure both shortcuts were also deleted. |
| 304 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 339 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 305 RunPendingTasks(); | 340 RunPendingTasks(); |
| 306 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); | 341 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_1)); |
| 307 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); | 342 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_2)); |
| 308 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); | 343 ValidateProfileShortcutAtPath(FROM_HERE, preserved_profile_1_shortcut_path, |
| 344 profile_1_path_); |
| 309 } | 345 } |
| 310 | 346 |
| 311 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { | 347 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { |
| 312 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 348 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 313 | 349 |
| 314 const FilePath old_shortcut_path = | 350 const FilePath profile_2_shortcut_path_1 = |
| 315 GetDefaultShortcutPathForProfile(second_profile_name_); | 351 GetDefaultShortcutPathForProfile(profile_2_name_); |
| 316 const FilePath new_shortcut_path = | 352 const FilePath profile_2_shortcut_path_2 = |
| 317 shortcuts_directory_.Append(L"MyChrome.lnk"); | 353 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 318 | |
| 319 // Make a copy of the shortcut. | 354 // Make a copy of the shortcut. |
| 320 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); | 355 ASSERT_TRUE(file_util::CopyFile(profile_2_shortcut_path_1, |
| 321 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); | 356 profile_2_shortcut_path_2)); |
| 322 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 357 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, |
| 358 profile_2_path_); |
| 359 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 360 profile_2_path_); |
| 323 | 361 |
| 324 // Now, rename the profile. | 362 // Now, rename the profile. |
| 325 const string16 new_profile_name = L"New profile"; | 363 const string16 new_profile_2_name = L"New profile"; |
| 326 ASSERT_NE(second_profile_name_, new_profile_name); | 364 ASSERT_NE(profile_2_name_, new_profile_2_name); |
| 327 profile_info_cache_->SetNameOfProfileAtIndex( | 365 profile_info_cache_->SetNameOfProfileAtIndex( |
| 328 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), | 366 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_), |
| 329 new_profile_name); | 367 new_profile_2_name); |
| 330 RunPendingTasks(); | 368 RunPendingTasks(); |
| 331 | 369 |
| 332 // The original shortcut should be renamed but the copied shortcut should | 370 // The original shortcut should be renamed but the copied shortcut should |
| 333 // keep its name. | 371 // keep its name. |
| 334 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); | 372 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_1)); |
| 335 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 373 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 336 const FilePath updated_shortcut_path = | 374 profile_2_path_); |
| 337 GetDefaultShortcutPathForProfile(new_profile_name); | 375 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); |
| 338 EXPECT_TRUE(file_util::PathExists(updated_shortcut_path)); | |
| 339 } | 376 } |
| 340 | 377 |
| 378 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { |
| 379 SetupDefaultProfileShortcut(FROM_HERE); |
| 380 |
| 381 // Delete the shortcut that got created for this profile and instead make |
| 382 // a new one without any command-line flags. |
| 383 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), |
| 384 false)); |
| 385 const FilePath regular_shortcut_path = |
| 386 CreateRegularShortcutWithName(FROM_HERE, |
| 387 distribution_->GetAppShortCutName()); |
| 388 |
| 389 // Add another profile and check that the shortcut was replaced with |
| 390 // a badged shortcut with the right command line for the profile |
| 391 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 392 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); |
| 393 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
| 394 } |
| 395 |
| 396 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { |
| 397 SetupDefaultProfileShortcut(FROM_HERE); |
| 398 |
| 399 // Delete the shortcut that got created for this profile and instead make |
| 400 // two new ones without any command-line flags. |
| 401 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), |
| 402 false)); |
| 403 const FilePath regular_shortcut_path = |
| 404 CreateRegularShortcutWithName(FROM_HERE, |
| 405 distribution_->GetAppShortCutName()); |
| 406 const FilePath customized_regular_shortcut_path = |
| 407 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); |
| 408 |
| 409 // Add another profile and check that one shortcut was renamed and that the |
| 410 // other shortcut was updated but kept the same name. |
| 411 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 412 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); |
| 413 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, |
| 414 profile_1_path_); |
| 415 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
| 416 } |
| OLD | NEW |