| 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 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 base::FilePath CreateRegularSystemLevelShortcut( | 223 base::FilePath CreateRegularSystemLevelShortcut( |
| 224 const tracked_objects::Location& location) { | 224 const tracked_objects::Location& location) { |
| 225 BrowserDistribution* distribution = GetDistribution(); | 225 BrowserDistribution* distribution = GetDistribution(); |
| 226 installer::Product product(distribution); | 226 installer::Product product(distribution); |
| 227 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); | 227 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); |
| 228 product.AddDefaultShortcutProperties(GetExePath(), &properties); | 228 product.AddDefaultShortcutProperties(GetExePath(), &properties); |
| 229 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 229 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 230 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties, | 230 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties, |
| 231 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); | 231 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); |
| 232 const base::FilePath system_level_shortcut_path = | 232 const base::FilePath system_level_shortcut_path = |
| 233 GetSystemShortcutsDirectory().Append( | 233 GetSystemShortcutsDirectory().Append(distribution->GetShortcutName() + |
| 234 distribution-> | 234 installer::kLnkExt); |
| 235 GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
| 236 installer::kLnkExt); | |
| 237 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)) | 235 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)) |
| 238 << location.ToString(); | 236 << location.ToString(); |
| 239 return system_level_shortcut_path; | 237 return system_level_shortcut_path; |
| 240 } | 238 } |
| 241 | 239 |
| 242 void RenameProfile(const tracked_objects::Location& location, | 240 void RenameProfile(const tracked_objects::Location& location, |
| 243 const base::FilePath& profile_path, | 241 const base::FilePath& profile_path, |
| 244 const base::string16& new_profile_name) { | 242 const base::string16& new_profile_name) { |
| 245 ProfileAttributesEntry* entry; | 243 ProfileAttributesEntry* entry; |
| 246 ASSERT_TRUE(profile_attributes_storage_-> | 244 ASSERT_TRUE(profile_attributes_storage_-> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 BrowserDistribution* distribution = GetDistribution(); | 319 BrowserDistribution* distribution = GetDistribution(); |
| 322 const base::string16 expected_name = kSanitizedProfileName + L" - " + | 320 const base::string16 expected_name = kSanitizedProfileName + L" - " + |
| 323 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME) + installer::kLnkExt; | 321 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME) + installer::kLnkExt; |
| 324 EXPECT_EQ(expected_name, | 322 EXPECT_EQ(expected_name, |
| 325 profiles::internal::GetShortcutFilenameForProfile(kProfileName, | 323 profiles::internal::GetShortcutFilenameForProfile(kProfileName, |
| 326 distribution)); | 324 distribution)); |
| 327 } | 325 } |
| 328 | 326 |
| 329 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { | 327 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { |
| 330 BrowserDistribution* distribution = GetDistribution(); | 328 BrowserDistribution* distribution = GetDistribution(); |
| 331 EXPECT_EQ( | 329 EXPECT_EQ(distribution->GetShortcutName() + installer::kLnkExt, |
| 332 distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | 330 profiles::internal::GetShortcutFilenameForProfile(base::string16(), |
| 333 installer::kLnkExt, | 331 distribution)); |
| 334 profiles::internal::GetShortcutFilenameForProfile(base::string16(), | |
| 335 distribution)); | |
| 336 } | 332 } |
| 337 | 333 |
| 338 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) { | 334 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) { |
| 339 const base::string16 kProfileName = L"MyProfileX"; | 335 const base::string16 kProfileName = L"MyProfileX"; |
| 340 const base::FilePath profile_path = | 336 const base::FilePath profile_path = |
| 341 profile_manager_->profiles_dir().Append(kProfileName); | 337 profile_manager_->profiles_dir().Append(kProfileName); |
| 342 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"", | 338 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"", |
| 343 profiles::internal::CreateProfileShortcutFlags(profile_path)); | 339 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| 344 } | 340 } |
| 345 | 341 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); | 578 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); |
| 583 } | 579 } |
| 584 | 580 |
| 585 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { | 581 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { |
| 586 SetupDefaultProfileShortcut(FROM_HERE); | 582 SetupDefaultProfileShortcut(FROM_HERE); |
| 587 | 583 |
| 588 // Delete the shortcut that got created for this profile and instead make | 584 // Delete the shortcut that got created for this profile and instead make |
| 589 // a new one without any command-line flags. | 585 // a new one without any command-line flags. |
| 590 ASSERT_TRUE(base::DeleteFile( | 586 ASSERT_TRUE(base::DeleteFile( |
| 591 GetDefaultShortcutPathForProfile(base::string16()), false)); | 587 GetDefaultShortcutPathForProfile(base::string16()), false)); |
| 592 const base::FilePath regular_shortcut_path = | 588 const base::FilePath regular_shortcut_path = CreateRegularShortcutWithName( |
| 593 CreateRegularShortcutWithName(FROM_HERE, | 589 FROM_HERE, GetDistribution()->GetShortcutName()); |
| 594 GetDistribution()->GetShortcutName( | |
| 595 BrowserDistribution::SHORTCUT_CHROME)); | |
| 596 | 590 |
| 597 // Add another profile and check that the shortcut was replaced with | 591 // Add another profile and check that the shortcut was replaced with |
| 598 // a badged shortcut with the right command line for the profile | 592 // a badged shortcut with the right command line for the profile |
| 599 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 593 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 600 EXPECT_FALSE(base::PathExists(regular_shortcut_path)); | 594 EXPECT_FALSE(base::PathExists(regular_shortcut_path)); |
| 601 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 595 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
| 602 } | 596 } |
| 603 | 597 |
| 604 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { | 598 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { |
| 605 SetupDefaultProfileShortcut(FROM_HERE); | 599 SetupDefaultProfileShortcut(FROM_HERE); |
| 606 | 600 |
| 607 // Delete the shortcut that got created for this profile and instead make | 601 // Delete the shortcut that got created for this profile and instead make |
| 608 // two new ones without any command-line flags. | 602 // two new ones without any command-line flags. |
| 609 ASSERT_TRUE(base::DeleteFile( | 603 ASSERT_TRUE(base::DeleteFile( |
| 610 GetDefaultShortcutPathForProfile(base::string16()), false)); | 604 GetDefaultShortcutPathForProfile(base::string16()), false)); |
| 611 const base::FilePath regular_shortcut_path = | 605 const base::FilePath regular_shortcut_path = CreateRegularShortcutWithName( |
| 612 CreateRegularShortcutWithName(FROM_HERE, | 606 FROM_HERE, GetDistribution()->GetShortcutName()); |
| 613 GetDistribution()->GetShortcutName( | |
| 614 BrowserDistribution::SHORTCUT_CHROME)); | |
| 615 const base::FilePath customized_regular_shortcut_path = | 607 const base::FilePath customized_regular_shortcut_path = |
| 616 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); | 608 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); |
| 617 | 609 |
| 618 // Add another profile and check that one shortcut was renamed and that the | 610 // Add another profile and check that one shortcut was renamed and that the |
| 619 // other shortcut was updated but kept the same name. | 611 // other shortcut was updated but kept the same name. |
| 620 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 612 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 621 EXPECT_FALSE(base::PathExists(regular_shortcut_path)); | 613 EXPECT_FALSE(base::PathExists(regular_shortcut_path)); |
| 622 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, | 614 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, |
| 623 profile_1_path_); | 615 profile_1_path_); |
| 624 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 616 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 GetDefaultShortcutPathForProfile(profile_2_name_))); | 1027 GetDefaultShortcutPathForProfile(profile_2_name_))); |
| 1036 EXPECT_TRUE(base::PathExists(profile_3_shortcut_path)); | 1028 EXPECT_TRUE(base::PathExists(profile_3_shortcut_path)); |
| 1037 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 1029 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
| 1038 RunPendingTasks(); | 1030 RunPendingTasks(); |
| 1039 EXPECT_FALSE(base::PathExists( | 1031 EXPECT_FALSE(base::PathExists( |
| 1040 GetDefaultShortcutPathForProfile(profile_2_name_))); | 1032 GetDefaultShortcutPathForProfile(profile_2_name_))); |
| 1041 // Only profile3 exists. There should be non-profile shortcut only. | 1033 // Only profile3 exists. There should be non-profile shortcut only. |
| 1042 EXPECT_FALSE(base::PathExists(profile_3_shortcut_path)); | 1034 EXPECT_FALSE(base::PathExists(profile_3_shortcut_path)); |
| 1043 ValidateNonProfileShortcut(FROM_HERE); | 1035 ValidateNonProfileShortcut(FROM_HERE); |
| 1044 } | 1036 } |
| OLD | NEW |