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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/test/scoped_path_override.h" | 10 #include "base/test/scoped_path_override.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/test/test_shortcut_win.h" | 12 #include "base/test/test_shortcut_win.h" |
| 13 #include "base/win/shortcut.h" | 13 #include "base/win/shortcut.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 16 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 17 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | 17 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
| 18 #include "chrome/installer/util/browser_distribution.h" | 18 #include "chrome/installer/util/browser_distribution.h" |
| 19 #include "chrome/installer/util/product.h" | |
| 19 #include "chrome/installer/util/shell_util.h" | 20 #include "chrome/installer/util/shell_util.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 | 28 |
| 28 class ProfileShortcutManagerTest : public testing::Test { | 29 class ProfileShortcutManagerTest : public testing::Test { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // A non-badged shortcut for chrome is automatically created with the | 98 // A non-badged shortcut for chrome is automatically created with the |
| 98 // first profile (for the case when the user deletes their only profile). | 99 // first profile (for the case when the user deletes their only profile). |
| 99 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, | 100 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, |
| 100 string16(), 0); | 101 string16(), 0); |
| 101 RunPendingTasks(); | 102 RunPendingTasks(); |
| 102 // We now have 1 profile, so we expect a new shortcut with no profile | 103 // We now have 1 profile, so we expect a new shortcut with no profile |
| 103 // information. | 104 // information. |
| 104 ValidateProfileShortcut(string16()); | 105 ValidateProfileShortcut(string16()); |
| 105 } | 106 } |
| 106 | 107 |
| 108 void CreateSecondProfileWithShortcut() { | |
| 109 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | |
| 110 profile_info_cache_->AddProfileToCache(second_dest_path_, | |
| 111 second_profile_name_, string16(), 0); | |
| 112 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
|
sail
2012/11/26 21:27:16
I know this was there previously but is it really
Alexei Svitkine (slow)
2012/11/27 14:49:26
No. Whether the shortcut is created is based on th
| |
| 113 RunPendingTasks(); | |
| 114 ValidateProfileShortcut(second_profile_name_); | |
| 115 } | |
| 116 | |
| 107 void SetupAndCreateTwoShortcuts() { | 117 void SetupAndCreateTwoShortcuts() { |
| 108 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()); | 118 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()); |
| 109 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 119 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); |
| 110 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | |
| 111 | 120 |
| 112 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, | 121 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, |
| 113 string16(), 0); | 122 string16(), 0); |
| 114 profile_info_cache_->AddProfileToCache(second_dest_path_, | 123 CreateSecondProfileWithShortcut(); |
| 115 second_profile_name_, string16(), 0); | |
| 116 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | |
| 117 RunPendingTasks(); | |
| 118 ValidateProfileShortcut(profile_name_); | 124 ValidateProfileShortcut(profile_name_); |
| 119 ValidateProfileShortcut(second_profile_name_); | |
| 120 } | 125 } |
| 121 | 126 |
| 122 // Returns the default shortcut path for this profile. | 127 // Returns the default shortcut path for this profile. |
| 123 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { | 128 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { |
| 124 return shortcuts_directory_.Append( | 129 return shortcuts_directory_.Append( |
| 125 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 130 profiles::internal::GetShortcutFilenameForProfile(profile_name, |
| 126 distribution_)); | 131 distribution_)); |
| 127 } | 132 } |
| 128 | 133 |
| 129 // Returns true if the shortcut for this profile exists. | 134 // Returns true if the shortcut for this profile exists. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 141 | 146 |
| 142 // TODO(asvitkine): With this new struct method for VerifyShortcut you can | 147 // TODO(asvitkine): With this new struct method for VerifyShortcut you can |
| 143 // now test more properties like: arguments, icon, icon_index, and app_id. | 148 // now test more properties like: arguments, icon, icon_index, and app_id. |
| 144 base::win::ShortcutProperties expected_properties; | 149 base::win::ShortcutProperties expected_properties; |
| 145 expected_properties.set_target(exe_path_); | 150 expected_properties.set_target(exe_path_); |
| 146 expected_properties.set_description(distribution_->GetAppDescription()); | 151 expected_properties.set_description(distribution_->GetAppDescription()); |
| 147 expected_properties.set_dual_mode(false); | 152 expected_properties.set_dual_mode(false); |
| 148 base::win::ValidateShortcut(shortcut_path, expected_properties); | 153 base::win::ValidateShortcut(shortcut_path, expected_properties); |
| 149 } | 154 } |
| 150 | 155 |
| 156 // Creates a regular (non-profile) desktop shortcut with the given name and | |
| 157 // returns its path. Fails the test if an error occurs. | |
| 158 FilePath CreateRegularShortcutWithName(const string16& shortcut_name) { | |
| 159 const FilePath shortcut_path = | |
| 160 shortcuts_directory_.Append(shortcut_name + installer::kLnkExt); | |
| 161 EXPECT_FALSE(file_util::PathExists(shortcut_path)); | |
| 162 | |
| 163 installer::Product product(distribution_); | |
| 164 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | |
| 165 product.AddDefaultShortcutProperties(exe_path_, &properties); | |
| 166 properties.set_shortcut_name(shortcut_name); | |
| 167 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | |
| 168 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, | |
| 169 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
| 170 | |
| 171 return shortcut_path; | |
| 172 } | |
| 173 | |
| 151 BrowserDistribution* distribution_; | 174 BrowserDistribution* distribution_; |
| 152 MessageLoopForUI message_loop_; | 175 MessageLoopForUI message_loop_; |
| 153 content::TestBrowserThread ui_thread_; | 176 content::TestBrowserThread ui_thread_; |
| 154 content::TestBrowserThread file_thread_; | 177 content::TestBrowserThread file_thread_; |
| 155 scoped_ptr<TestingProfileManager> profile_manager_; | 178 scoped_ptr<TestingProfileManager> profile_manager_; |
| 156 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; | 179 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
| 157 ProfileInfoCache* profile_info_cache_; | 180 ProfileInfoCache* profile_info_cache_; |
| 158 base::ScopedPathOverride fake_user_desktop_; | 181 base::ScopedPathOverride fake_user_desktop_; |
| 159 FilePath exe_path_; | 182 FilePath exe_path_; |
| 160 FilePath dest_path_; | 183 FilePath dest_path_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 173 distribution_)); | 196 distribution_)); |
| 174 } | 197 } |
| 175 | 198 |
| 176 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { | 199 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { |
| 177 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, | 200 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, |
| 178 profiles::internal::GetShortcutFilenameForProfile(string16(), | 201 profiles::internal::GetShortcutFilenameForProfile(string16(), |
| 179 distribution_)); | 202 distribution_)); |
| 180 } | 203 } |
| 181 | 204 |
| 182 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { | 205 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { |
| 183 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 206 SetupDefaultProfileShortcut(); |
| 184 | 207 |
| 185 profile_info_cache_->AddProfileToCache(second_dest_path_, | 208 profile_info_cache_->AddProfileToCache(second_dest_path_, |
| 186 second_profile_name_, string16(), 0); | 209 second_profile_name_, string16(), 0); |
| 187 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 210 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); |
| 188 RunPendingTasks(); | 211 RunPendingTasks(); |
| 189 | 212 |
| 190 // We now have 2 profiles, so we expect a new shortcut with profile | 213 // We now have 2 profiles, so we expect a new shortcut with profile |
| 191 // information for this 2nd profile. | 214 // information for this 2nd profile. |
| 192 ValidateProfileShortcut(second_profile_name_); | 215 ValidateProfileShortcut(second_profile_name_); |
| 193 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append( | 216 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append( |
| 194 FILE_PATH_LITERAL("Google Profile.ico")))); | 217 FILE_PATH_LITERAL("Google Profile.ico")))); |
| 195 } | 218 } |
| 196 | 219 |
| 197 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { | 220 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { |
| 198 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 221 SetupDefaultProfileShortcut(); |
| 199 | 222 |
| 200 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 223 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); |
| 201 | 224 |
| 202 profile_info_cache_->AddProfileToCache(second_dest_path_, | 225 profile_info_cache_->AddProfileToCache(second_dest_path_, |
| 203 second_profile_name_, string16(), 0); | 226 second_profile_name_, string16(), 0); |
| 204 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 227 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); |
| 205 RunPendingTasks(); | 228 RunPendingTasks(); |
| 206 ValidateProfileShortcut(second_profile_name_); | 229 ValidateProfileShortcut(second_profile_name_); |
| 207 | 230 |
| 208 // Cause an update in ProfileShortcutManager by modifying the profile info | 231 // Cause an update in ProfileShortcutManager by modifying the profile info |
| 209 // cache. | 232 // cache. |
| 210 const string16 new_profile_name = L"New Profile Name"; | 233 const string16 new_profile_name = L"New Profile Name"; |
| 211 profile_info_cache_->SetNameOfProfileAtIndex( | 234 profile_info_cache_->SetNameOfProfileAtIndex( |
| 212 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), | 235 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), |
| 213 new_profile_name); | 236 new_profile_name); |
| 214 RunPendingTasks(); | 237 RunPendingTasks(); |
| 215 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 238 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); |
| 216 ValidateProfileShortcut(new_profile_name); | 239 ValidateProfileShortcut(new_profile_name); |
| 217 } | 240 } |
| 218 | 241 |
| 219 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { | 242 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { |
| 220 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 243 SetupAndCreateTwoShortcuts(); |
| 221 | 244 |
| 222 // Delete one shortcut. | 245 // Delete one shortcut. |
| 223 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 246 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); |
| 224 RunPendingTasks(); | 247 RunPendingTasks(); |
| 225 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 248 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); |
| 226 | 249 |
| 227 // Verify that the profile name has been removed from the remaining shortcut. | 250 // Verify that the profile name has been removed from the remaining shortcut. |
| 228 ValidateProfileShortcut(string16()); | 251 ValidateProfileShortcut(string16()); |
| 229 // Verify that an additional shortcut, with the default profile's name does | 252 // Verify that an additional shortcut, with the default profile's name does |
| 230 // not exist. | 253 // not exist. |
| 231 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 254 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); |
| 232 } | 255 } |
| 233 | 256 |
| 234 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { | 257 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { |
| 235 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 258 SetupAndCreateTwoShortcuts(); |
| 236 | 259 |
| 237 // Delete one shortcut. | 260 // Delete one shortcut. |
| 238 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 261 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); |
| 239 RunPendingTasks(); | 262 RunPendingTasks(); |
| 240 | 263 |
| 241 // Verify that a default shortcut exists (no profile name/avatar). | 264 // Verify that a default shortcut exists (no profile name/avatar). |
| 242 ValidateProfileShortcut(string16()); | 265 ValidateProfileShortcut(string16()); |
| 243 // Verify that an additional shortcut, with the default profile's name does | 266 // Verify that an additional shortcut, with the default profile's name does |
| 244 // not exist. | 267 // not exist. |
| 245 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); | 268 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); |
| 246 | 269 |
| 247 // Create a second profile and shortcut. | 270 // Create a second profile and shortcut. |
| 248 profile_info_cache_->AddProfileToCache(second_dest_path_, | 271 profile_info_cache_->AddProfileToCache(second_dest_path_, |
| 249 second_profile_name_, string16(), 0); | 272 second_profile_name_, string16(), 0); |
| 250 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 273 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); |
| 251 RunPendingTasks(); | 274 RunPendingTasks(); |
| 252 ValidateProfileShortcut(second_profile_name_); | 275 ValidateProfileShortcut(second_profile_name_); |
| 253 | 276 |
| 254 // Verify that the original shortcut received the profile's name. | 277 // Verify that the original shortcut received the profile's name. |
| 255 ValidateProfileShortcut(profile_name_); | 278 ValidateProfileShortcut(profile_name_); |
| 256 // Verify that a default shortcut no longer exists. | 279 // Verify that a default shortcut no longer exists. |
| 257 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); | 280 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); |
| 258 } | 281 } |
| 259 | 282 |
| 260 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { | 283 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { |
| 261 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 284 SetupAndCreateTwoShortcuts(); |
| 262 | 285 |
| 263 const FilePath old_shortcut_path = | 286 const FilePath old_shortcut_path = |
| 264 GetDefaultShortcutPathForProfile(second_profile_name_); | 287 GetDefaultShortcutPathForProfile(second_profile_name_); |
| 265 const FilePath new_shortcut_path = | 288 const FilePath new_shortcut_path = |
| 266 shortcuts_directory_.Append(L"MyChrome.lnk"); | 289 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 267 ASSERT_TRUE(file_util::Move(old_shortcut_path, new_shortcut_path)); | 290 ASSERT_TRUE(file_util::Move(old_shortcut_path, new_shortcut_path)); |
| 268 | 291 |
| 269 // Ensure that a new shortcut does not get made if the old one was renamed. | 292 // Ensure that a new shortcut does not get made if the old one was renamed. |
| 270 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 293 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); |
| 271 RunPendingTasks(); | 294 RunPendingTasks(); |
| 272 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 295 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); |
| 273 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 296 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); |
| 274 | 297 |
| 275 // Delete the renamed shortcut and try to create it again, which should work. | 298 // Delete the renamed shortcut and try to create it again, which should work. |
| 276 ASSERT_TRUE(file_util::Delete(new_shortcut_path, false)); | 299 ASSERT_TRUE(file_util::Delete(new_shortcut_path, false)); |
| 277 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); | 300 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); |
| 278 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); | 301 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); |
| 279 RunPendingTasks(); | 302 RunPendingTasks(); |
| 280 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); | 303 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); |
| 281 } | 304 } |
| 282 | 305 |
| 283 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { | 306 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { |
| 284 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 307 SetupAndCreateTwoShortcuts(); |
| 285 | 308 |
| 286 const FilePath old_shortcut_path = | 309 const FilePath old_shortcut_path = |
| 287 GetDefaultShortcutPathForProfile(second_profile_name_); | 310 GetDefaultShortcutPathForProfile(second_profile_name_); |
| 288 const FilePath new_shortcut_path = | 311 const FilePath new_shortcut_path = |
| 289 shortcuts_directory_.Append(L"MyChrome.lnk"); | 312 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 290 // Make a copy of the shortcut. | 313 // Make a copy of the shortcut. |
| 291 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); | 314 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); |
| 292 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); | 315 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); |
| 293 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 316 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); |
| 294 | 317 |
| 295 // Also, copy the shortcut for the first user and ensure it gets preserved. | 318 // Also, copy the shortcut for the first user and ensure it gets preserved. |
| 296 const FilePath preserved_shortcut_path = | 319 const FilePath preserved_shortcut_path = |
| 297 shortcuts_directory_.Append(L"Preserved.lnk"); | 320 shortcuts_directory_.Append(L"Preserved.lnk"); |
| 298 ASSERT_TRUE(file_util::CopyFile( | 321 ASSERT_TRUE(file_util::CopyFile( |
| 299 GetDefaultShortcutPathForProfile(profile_name_), | 322 GetDefaultShortcutPathForProfile(profile_name_), |
| 300 preserved_shortcut_path)); | 323 preserved_shortcut_path)); |
| 301 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); | 324 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); |
| 302 | 325 |
| 303 // Delete the profile and ensure both shortcuts were also deleted. | 326 // Delete the profile and ensure both shortcuts were also deleted. |
| 304 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); | 327 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); |
| 305 RunPendingTasks(); | 328 RunPendingTasks(); |
| 306 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); | 329 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); |
| 307 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); | 330 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); |
| 308 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); | 331 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); |
| 309 } | 332 } |
| 310 | 333 |
| 311 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { | 334 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { |
| 312 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); | 335 SetupAndCreateTwoShortcuts(); |
| 313 | 336 |
| 314 const FilePath old_shortcut_path = | 337 const FilePath old_shortcut_path = |
| 315 GetDefaultShortcutPathForProfile(second_profile_name_); | 338 GetDefaultShortcutPathForProfile(second_profile_name_); |
| 316 const FilePath new_shortcut_path = | 339 const FilePath new_shortcut_path = |
| 317 shortcuts_directory_.Append(L"MyChrome.lnk"); | 340 shortcuts_directory_.Append(L"MyChrome.lnk"); |
| 318 | 341 |
| 319 // Make a copy of the shortcut. | 342 // Make a copy of the shortcut. |
| 320 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); | 343 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); |
| 321 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); | 344 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); |
| 322 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 345 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); |
| 323 | 346 |
| 324 // Now, rename the profile. | 347 // Now, rename the profile. |
| 325 const string16 new_profile_name = L"New profile"; | 348 const string16 new_profile_name = L"New profile"; |
| 326 ASSERT_NE(second_profile_name_, new_profile_name); | 349 ASSERT_NE(second_profile_name_, new_profile_name); |
| 327 profile_info_cache_->SetNameOfProfileAtIndex( | 350 profile_info_cache_->SetNameOfProfileAtIndex( |
| 328 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), | 351 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), |
| 329 new_profile_name); | 352 new_profile_name); |
| 330 RunPendingTasks(); | 353 RunPendingTasks(); |
| 331 | 354 |
| 332 // The original shortcut should be renamed but the copied shortcut should | 355 // The original shortcut should be renamed but the copied shortcut should |
| 333 // keep its name. | 356 // keep its name. |
| 334 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); | 357 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); |
| 335 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | 358 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); |
| 336 const FilePath updated_shortcut_path = | 359 const FilePath updated_shortcut_path = |
| 337 GetDefaultShortcutPathForProfile(new_profile_name); | 360 GetDefaultShortcutPathForProfile(new_profile_name); |
| 338 EXPECT_TRUE(file_util::PathExists(updated_shortcut_path)); | 361 EXPECT_TRUE(file_util::PathExists(updated_shortcut_path)); |
| 339 } | 362 } |
| 340 | 363 |
| 364 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { | |
| 365 SetupDefaultProfileShortcut(); | |
| 366 | |
| 367 // Delete the shortcut that got created for this profile and instead make | |
| 368 // a new one without any command-line flags. | |
| 369 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), | |
| 370 false)); | |
| 371 const FilePath default_shortcut_path = | |
|
sail
2012/11/26 21:27:16
naming here is inconsistent.
above you refer to th
Alexei Svitkine (slow)
2012/11/27 22:31:26
Done.
| |
| 372 CreateRegularShortcutWithName(distribution_->GetAppShortCutName()); | |
| 373 EXPECT_TRUE(file_util::PathExists(default_shortcut_path)); | |
|
sail
2012/11/26 21:27:16
move this into CreateRegularShortcutWithName? (sam
Alexei Svitkine (slow)
2012/11/27 14:49:26
The reason I didn't is because when an EXPECT fail
Alexei Svitkine (slow)
2012/11/27 14:53:58
Replying to myself:
Looks like we have base/locat
Alexei Svitkine (slow)
2012/11/27 22:31:26
Done.
| |
| 374 | |
| 375 // Add another profile and check that the shortcut was renamed. | |
| 376 CreateSecondProfileWithShortcut(); | |
| 377 | |
| 378 EXPECT_FALSE(file_util::PathExists(default_shortcut_path)); | |
| 379 const FilePath new_shortcut_path = | |
| 380 GetDefaultShortcutPathForProfile(profile_name_); | |
|
sail
2012/11/26 21:27:16
This test is really confusing.
Here's what I thin
Alexei Svitkine (slow)
2012/11/27 22:31:26
That's correct.
| |
| 381 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | |
| 382 | |
| 383 // Check that the renamed shortcut has the correct command line flags set. | |
| 384 string16 shortcut_args; | |
| 385 ASSERT_TRUE(base::win::ResolveShortcut(new_shortcut_path, NULL, | |
| 386 &shortcut_args)); | |
| 387 const string16 expected_args = | |
| 388 profiles::internal::CreateProfileShortcutFlags(dest_path_); | |
| 389 EXPECT_NE(string16::npos, shortcut_args.find(expected_args)); | |
| 390 } | |
| 391 | |
| 392 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { | |
| 393 SetupDefaultProfileShortcut(); | |
| 394 | |
| 395 // Delete the shortcut that got created for this profile and instead make | |
| 396 // two new ones without any command-line flags. | |
| 397 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), | |
| 398 false)); | |
| 399 const FilePath default_shortcut_path = | |
| 400 CreateRegularShortcutWithName(distribution_->GetAppShortCutName()); | |
| 401 EXPECT_TRUE(file_util::PathExists(default_shortcut_path)); | |
| 402 const FilePath second_shortcut_path = | |
| 403 CreateRegularShortcutWithName(L"MyChrome"); | |
| 404 EXPECT_TRUE(file_util::PathExists(second_shortcut_path)); | |
| 405 | |
| 406 // Add another profile and check that one shortcut was renamed and that the | |
| 407 // other shortcut was updated but kept the same name. | |
| 408 CreateSecondProfileWithShortcut(); | |
| 409 EXPECT_FALSE(file_util::PathExists(default_shortcut_path)); | |
| 410 EXPECT_TRUE(file_util::PathExists(second_shortcut_path)); | |
| 411 | |
| 412 const FilePath new_shortcut_path = | |
| 413 GetDefaultShortcutPathForProfile(profile_name_); | |
| 414 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); | |
| 415 | |
| 416 // Check that both shortcuts have the correct command line flags set. | |
| 417 const string16 expected_args = | |
| 418 profiles::internal::CreateProfileShortcutFlags(dest_path_); | |
| 419 string16 shortcut_args; | |
| 420 ASSERT_TRUE(base::win::ResolveShortcut(new_shortcut_path, NULL, | |
| 421 &shortcut_args)); | |
| 422 EXPECT_NE(string16::npos, shortcut_args.find(expected_args)); | |
| 423 | |
| 424 shortcut_args.clear(); | |
| 425 ASSERT_TRUE(base::win::ResolveShortcut(second_shortcut_path, NULL, | |
| 426 &shortcut_args)); | |
| 427 EXPECT_NE(string16::npos, shortcut_args.find(expected_args)); | |
| 428 } | |
| OLD | NEW |