| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/test/scoped_path_override.h" | 12 #include "base/test/scoped_path_override.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/test/test_shortcut_win.h" | 14 #include "base/test/test_shortcut_win.h" |
| 15 #include "base/win/shortcut.h" | 15 #include "base/win/shortcut.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 18 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 19 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | 19 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
| 20 #include "chrome/browser/shell_integration.h" | 20 #include "chrome/browser/shell_integration.h" |
| 21 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/installer/util/browser_distribution.h" | 22 #include "chrome/installer/util/browser_distribution.h" |
| 22 #include "chrome/installer/util/product.h" | 23 #include "chrome/installer/util/product.h" |
| 23 #include "chrome/installer/util/shell_util.h" | 24 #include "chrome/installer/util/shell_util.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 25 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 26 #include "chrome/test/base/testing_profile_manager.h" | 27 #include "chrome/test/base/testing_profile_manager.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
| 28 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Delete all profiles and ensure their shortcuts got removed. | 67 // Delete all profiles and ensure their shortcuts got removed. |
| 67 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); | 68 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); |
| 68 for (int i = 0; i < num_profiles; ++i) { | 69 for (int i = 0; i < num_profiles; ++i) { |
| 69 const base::FilePath profile_path = | 70 const base::FilePath profile_path = |
| 70 profile_info_cache_->GetPathOfProfileAtIndex(0); | 71 profile_info_cache_->GetPathOfProfileAtIndex(0); |
| 71 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); | 72 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); |
| 72 profile_info_cache_->DeleteProfileFromCache(profile_path); | 73 profile_info_cache_->DeleteProfileFromCache(profile_path); |
| 73 RunPendingTasks(); | 74 RunPendingTasks(); |
| 74 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); | 75 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); |
| 75 const base::FilePath icon_path = | 76 const base::FilePath icon_path = |
| 76 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 77 profiles::internal::GetProfileIconPath(profile_path); |
| 77 ASSERT_FALSE(file_util::PathExists(icon_path)); | 78 // The icon file should not be deleted on shortcut deletion. |
| 79 ASSERT_TRUE(file_util::PathExists(icon_path)); |
| 80 ASSERT_TRUE(file_util::Delete(icon_path, false)); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 base::FilePath CreateProfileDirectory(const string16& profile_name) { | 84 base::FilePath CreateProfileDirectory(const string16& profile_name) { |
| 82 const base::FilePath profile_path = | 85 const base::FilePath profile_path = |
| 83 profile_info_cache_->GetUserDataDir().Append(profile_name); | 86 profile_info_cache_->GetUserDataDir().Append(profile_name); |
| 84 file_util::CreateDirectoryW(profile_path); | 87 file_util::CreateDirectoryW(profile_path); |
| 85 return profile_path; | 88 return profile_path; |
| 86 } | 89 } |
| 87 | 90 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 131 |
| 129 // Calls base::win::ValidateShortcut() with expected properties for the | 132 // Calls base::win::ValidateShortcut() with expected properties for the |
| 130 // shortcut at |shortcut_path| for the profile at |profile_path|. | 133 // shortcut at |shortcut_path| for the profile at |profile_path|. |
| 131 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, | 134 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, |
| 132 const base::FilePath& shortcut_path, | 135 const base::FilePath& shortcut_path, |
| 133 const base::FilePath& profile_path) { | 136 const base::FilePath& profile_path) { |
| 134 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); | 137 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
| 135 | 138 |
| 136 // Ensure that the corresponding icon exists. | 139 // Ensure that the corresponding icon exists. |
| 137 const base::FilePath icon_path = | 140 const base::FilePath icon_path = |
| 138 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 141 profiles::internal::GetProfileIconPath(profile_path); |
| 139 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); | 142 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); |
| 140 | 143 |
| 141 base::win::ShortcutProperties expected_properties; | 144 base::win::ShortcutProperties expected_properties; |
| 142 expected_properties.set_app_id( | 145 expected_properties.set_app_id( |
| 143 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); | 146 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); |
| 144 expected_properties.set_target(GetExePath()); | 147 expected_properties.set_target(GetExePath()); |
| 145 expected_properties.set_description(GetDistribution()->GetAppDescription()); | 148 expected_properties.set_description(GetDistribution()->GetAppDescription()); |
| 146 expected_properties.set_dual_mode(false); | 149 expected_properties.set_dual_mode(false); |
| 147 expected_properties.set_arguments( | 150 expected_properties.set_arguments( |
| 148 profiles::internal::CreateProfileShortcutFlags(profile_path)); | 151 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 757 |
| 755 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 758 // 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)); | 759 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); |
| 757 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 760 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 758 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | 761 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); |
| 759 | 762 |
| 760 const base::FilePath system_level_shortcut_path = | 763 const base::FilePath system_level_shortcut_path = |
| 761 CreateRegularSystemLevelShortcut(FROM_HERE); | 764 CreateRegularSystemLevelShortcut(FROM_HERE); |
| 762 | 765 |
| 763 // Delete the profile that has a shortcut, which will exercise the non-profile | 766 // Delete the profile that has a shortcut, which will exercise the non-profile |
| 764 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is | 767 // shortcut creation path in |DeleteDesktopShortcuts()|, which is |
| 765 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | 768 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. |
| 766 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | 769 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 767 RunPendingTasks(); | 770 RunPendingTasks(); |
| 768 | 771 |
| 769 // Verify that only the system-level shortcut still exists. | 772 // Verify that only the system-level shortcut still exists. |
| 770 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | 773 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
| 771 EXPECT_FALSE(file_util::PathExists( | 774 EXPECT_FALSE(file_util::PathExists( |
| 772 GetDefaultShortcutPathForProfile(string16()))); | 775 GetDefaultShortcutPathForProfile(string16()))); |
| 773 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 776 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
| 774 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 777 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
| 775 } | 778 } |
| 779 |
| 780 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) { |
| 781 SetupDefaultProfileShortcut(FROM_HERE); |
| 782 |
| 783 const 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_->CreateOrUpdateProfileIcon(profile_1_path_, |
| 791 base::Closure()); |
| 792 RunPendingTasks(); |
| 793 EXPECT_TRUE(file_util::PathExists(icon_path)); |
| 794 } |
| 795 |
| 796 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) { |
| 797 SetupDefaultProfileShortcut(FROM_HERE); |
| 798 const base::FilePath icon_path_1 = |
| 799 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 800 const base::FilePath icon_path_2 = |
| 801 profiles::internal::GetProfileIconPath(profile_2_path_); |
| 802 |
| 803 // Default profile has unbadged icon to start. |
| 804 std::string unbadged_icon_1; |
| 805 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); |
| 806 |
| 807 // Creating a new profile adds a badge to both the new profile icon and the |
| 808 // default profile icon. Since they use the same icon index, the icon files |
| 809 // should be the same. |
| 810 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 811 |
| 812 std::string badged_icon_1; |
| 813 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); |
| 814 std::string badged_icon_2; |
| 815 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); |
| 816 |
| 817 EXPECT_NE(badged_icon_1, unbadged_icon_1); |
| 818 EXPECT_EQ(badged_icon_1, badged_icon_2); |
| 819 |
| 820 // Deleting the default profile will unbadge the new profile's icon and should |
| 821 // result in an icon that is identical to the unbadged default profile icon. |
| 822 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); |
| 823 RunPendingTasks(); |
| 824 |
| 825 std::string unbadged_icon_2; |
| 826 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &unbadged_icon_2)); |
| 827 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); |
| 828 } |
| 829 |
| 830 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { |
| 831 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 832 const base::FilePath icon_path_1 = |
| 833 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 834 const base::FilePath icon_path_2 = |
| 835 profiles::internal::GetProfileIconPath(profile_2_path_); |
| 836 const size_t profile_index_1 = |
| 837 profile_info_cache_->GetIndexOfProfileWithPath(profile_1_path_); |
| 838 |
| 839 std::string badged_icon_1; |
| 840 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); |
| 841 std::string badged_icon_2; |
| 842 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); |
| 843 |
| 844 // Profile 1 and 2 are created with the same icon. |
| 845 EXPECT_EQ(badged_icon_1, badged_icon_2); |
| 846 |
| 847 // Change profile 1's icon. |
| 848 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); |
| 849 RunPendingTasks(); |
| 850 |
| 851 std::string new_badged_icon_1; |
| 852 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &new_badged_icon_1)); |
| 853 EXPECT_NE(new_badged_icon_1, badged_icon_1); |
| 854 |
| 855 // Ensure the new icon is not the unbadged icon. |
| 856 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 857 RunPendingTasks(); |
| 858 |
| 859 std::string unbadged_icon_1; |
| 860 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); |
| 861 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); |
| 862 |
| 863 // Ensure the icon doesn't change on avatar change without 2 profiles. |
| 864 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); |
| 865 RunPendingTasks(); |
| 866 |
| 867 std::string unbadged_icon_1_a; |
| 868 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); |
| 869 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); |
| 870 } |
| OLD | NEW |