| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 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 // The icon file is not deleted until the profile directory is deleted. |
| 74 const base::FilePath icon_path = | 75 const base::FilePath icon_path = |
| 75 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 76 profiles::internal::GetProfileIconPath(profile_path); |
| 76 ASSERT_FALSE(base::PathExists(icon_path)); | 77 ASSERT_TRUE(base::PathExists(icon_path)); |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 base::FilePath CreateProfileDirectory(const string16& profile_name) { | 81 base::FilePath CreateProfileDirectory(const string16& profile_name) { |
| 81 const base::FilePath profile_path = | 82 const base::FilePath profile_path = |
| 82 profile_info_cache_->GetUserDataDir().Append(profile_name); | 83 profile_info_cache_->GetUserDataDir().Append(profile_name); |
| 83 file_util::CreateDirectoryW(profile_path); | 84 file_util::CreateDirectory(profile_path); |
| 84 return profile_path; | 85 return profile_path; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void RunPendingTasks() { | 88 void RunPendingTasks() { |
| 88 base::MessageLoop::current()->PostTask(FROM_HERE, | 89 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 89 base::MessageLoop::QuitClosure()); | 90 base::MessageLoop::QuitClosure()); |
| 90 base::MessageLoop::current()->Run(); | 91 base::MessageLoop::current()->Run(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { | 94 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 128 |
| 128 // Calls base::win::ValidateShortcut() with expected properties for the | 129 // Calls base::win::ValidateShortcut() with expected properties for the |
| 129 // shortcut at |shortcut_path| for the profile at |profile_path|. | 130 // shortcut at |shortcut_path| for the profile at |profile_path|. |
| 130 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, | 131 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, |
| 131 const base::FilePath& shortcut_path, | 132 const base::FilePath& shortcut_path, |
| 132 const base::FilePath& profile_path) { | 133 const base::FilePath& profile_path) { |
| 133 EXPECT_TRUE(base::PathExists(shortcut_path)) << location.ToString(); | 134 EXPECT_TRUE(base::PathExists(shortcut_path)) << location.ToString(); |
| 134 | 135 |
| 135 // Ensure that the corresponding icon exists. | 136 // Ensure that the corresponding icon exists. |
| 136 const base::FilePath icon_path = | 137 const base::FilePath icon_path = |
| 137 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 138 profiles::internal::GetProfileIconPath(profile_path); |
| 138 EXPECT_TRUE(base::PathExists(icon_path)) << location.ToString(); | 139 EXPECT_TRUE(base::PathExists(icon_path)) << location.ToString(); |
| 139 | 140 |
| 140 base::win::ShortcutProperties expected_properties; | 141 base::win::ShortcutProperties expected_properties; |
| 141 expected_properties.set_app_id( | 142 expected_properties.set_app_id( |
| 142 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); | 143 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); |
| 143 expected_properties.set_target(GetExePath()); | 144 expected_properties.set_target(GetExePath()); |
| 144 expected_properties.set_description(GetDistribution()->GetAppDescription()); | 145 expected_properties.set_description(GetDistribution()->GetAppDescription()); |
| 145 expected_properties.set_dual_mode(false); | 146 expected_properties.set_dual_mode(false); |
| 146 expected_properties.set_arguments( | 147 expected_properties.set_arguments( |
| 147 profiles::internal::CreateProfileShortcutFlags(profile_path)); | 148 profiles::internal::CreateProfileShortcutFlags(profile_path)); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 754 |
| 754 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 755 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
| 755 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); | 756 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); |
| 756 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 757 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
| 757 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); | 758 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); |
| 758 | 759 |
| 759 const base::FilePath system_level_shortcut_path = | 760 const base::FilePath system_level_shortcut_path = |
| 760 CreateRegularSystemLevelShortcut(FROM_HERE); | 761 CreateRegularSystemLevelShortcut(FROM_HERE); |
| 761 | 762 |
| 762 // Delete the profile that has a shortcut, which will exercise the non-profile | 763 // Delete the profile that has a shortcut, which will exercise the non-profile |
| 763 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is | 764 // shortcut creation path in |DeleteDesktopShortcuts()|, which is |
| 764 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | 765 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. |
| 765 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | 766 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 766 RunPendingTasks(); | 767 RunPendingTasks(); |
| 767 | 768 |
| 768 // Verify that only the system-level shortcut still exists. | 769 // Verify that only the system-level shortcut still exists. |
| 769 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 770 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
| 770 EXPECT_FALSE(base::PathExists( | 771 EXPECT_FALSE(base::PathExists( |
| 771 GetDefaultShortcutPathForProfile(string16()))); | 772 GetDefaultShortcutPathForProfile(string16()))); |
| 772 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); | 773 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); |
| 773 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); | 774 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); |
| 774 } | 775 } |
| 776 |
| 777 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) { |
| 778 SetupDefaultProfileShortcut(FROM_HERE); |
| 779 |
| 780 const base::FilePath icon_path = |
| 781 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 782 |
| 783 EXPECT_TRUE(base::PathExists(icon_path)); |
| 784 EXPECT_TRUE(base::DeleteFile(icon_path, false)); |
| 785 EXPECT_FALSE(base::PathExists(icon_path)); |
| 786 |
| 787 profile_shortcut_manager_->CreateOrUpdateProfileIcon(profile_1_path_, |
| 788 base::Closure()); |
| 789 RunPendingTasks(); |
| 790 EXPECT_TRUE(base::PathExists(icon_path)); |
| 791 } |
| 792 |
| 793 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) { |
| 794 SetupDefaultProfileShortcut(FROM_HERE); |
| 795 const base::FilePath icon_path_1 = |
| 796 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 797 const base::FilePath icon_path_2 = |
| 798 profiles::internal::GetProfileIconPath(profile_2_path_); |
| 799 |
| 800 // Default profile has unbadged icon to start. |
| 801 std::string unbadged_icon_1; |
| 802 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); |
| 803 |
| 804 // Creating a new profile adds a badge to both the new profile icon and the |
| 805 // default profile icon. Since they use the same icon index, the icon files |
| 806 // should be the same. |
| 807 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
| 808 |
| 809 std::string badged_icon_1; |
| 810 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); |
| 811 std::string badged_icon_2; |
| 812 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); |
| 813 |
| 814 EXPECT_NE(badged_icon_1, unbadged_icon_1); |
| 815 EXPECT_EQ(badged_icon_1, badged_icon_2); |
| 816 |
| 817 // Deleting the default profile will unbadge the new profile's icon and should |
| 818 // result in an icon that is identical to the unbadged default profile icon. |
| 819 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); |
| 820 RunPendingTasks(); |
| 821 |
| 822 std::string unbadged_icon_2; |
| 823 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &unbadged_icon_2)); |
| 824 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); |
| 825 } |
| 826 |
| 827 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { |
| 828 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 829 const base::FilePath icon_path_1 = |
| 830 profiles::internal::GetProfileIconPath(profile_1_path_); |
| 831 const base::FilePath icon_path_2 = |
| 832 profiles::internal::GetProfileIconPath(profile_2_path_); |
| 833 const size_t profile_index_1 = |
| 834 profile_info_cache_->GetIndexOfProfileWithPath(profile_1_path_); |
| 835 |
| 836 std::string badged_icon_1; |
| 837 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1)); |
| 838 std::string badged_icon_2; |
| 839 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2)); |
| 840 |
| 841 // Profile 1 and 2 are created with the same icon. |
| 842 EXPECT_EQ(badged_icon_1, badged_icon_2); |
| 843 |
| 844 // Change profile 1's icon. |
| 845 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); |
| 846 RunPendingTasks(); |
| 847 |
| 848 std::string new_badged_icon_1; |
| 849 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &new_badged_icon_1)); |
| 850 EXPECT_NE(new_badged_icon_1, badged_icon_1); |
| 851 |
| 852 // Ensure the new icon is not the unbadged icon. |
| 853 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
| 854 RunPendingTasks(); |
| 855 |
| 856 std::string unbadged_icon_1; |
| 857 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1)); |
| 858 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); |
| 859 |
| 860 // Ensure the icon doesn't change on avatar change without 2 profiles. |
| 861 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); |
| 862 RunPendingTasks(); |
| 863 |
| 864 std::string unbadged_icon_1_a; |
| 865 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); |
| 866 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); |
| 867 } |
| OLD | NEW |