Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc

Issue 14137032: Create profile .ico file on profile creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test, fix nits Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Delete all profiles and ensure their shortcuts got removed. 66 // Delete all profiles and ensure their shortcuts got removed.
67 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); 67 const int num_profiles = profile_info_cache_->GetNumberOfProfiles();
68 for (int i = 0; i < num_profiles; ++i) { 68 for (int i = 0; i < num_profiles; ++i) {
69 const base::FilePath profile_path = 69 const base::FilePath profile_path =
70 profile_info_cache_->GetPathOfProfileAtIndex(0); 70 profile_info_cache_->GetPathOfProfileAtIndex(0);
71 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); 71 string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0);
72 profile_info_cache_->DeleteProfileFromCache(profile_path); 72 profile_info_cache_->DeleteProfileFromCache(profile_path);
73 RunPendingTasks(); 73 RunPendingTasks();
74 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); 74 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name));
75 const base::FilePath icon_path = 75 const base::FilePath icon_path =
76 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); 76 profiles::internal::GetProfileIconPath(profile_path);
77 ASSERT_FALSE(file_util::PathExists(icon_path)); 77 // The icon file should not be deleted on shortcut deletion.
78 ASSERT_TRUE(file_util::PathExists(icon_path));
79 ASSERT_TRUE(file_util::Delete(icon_path, false));
78 } 80 }
79 } 81 }
80 82
81 base::FilePath CreateProfileDirectory(const string16& profile_name) { 83 base::FilePath CreateProfileDirectory(const string16& profile_name) {
82 const base::FilePath profile_path = 84 const base::FilePath profile_path =
83 profile_info_cache_->GetUserDataDir().Append(profile_name); 85 profile_info_cache_->GetUserDataDir().Append(profile_name);
84 file_util::CreateDirectoryW(profile_path); 86 file_util::CreateDirectoryW(profile_path);
85 return profile_path; 87 return profile_path;
86 } 88 }
87 89
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 130
129 // Calls base::win::ValidateShortcut() with expected properties for the 131 // Calls base::win::ValidateShortcut() with expected properties for the
130 // shortcut at |shortcut_path| for the profile at |profile_path|. 132 // shortcut at |shortcut_path| for the profile at |profile_path|.
131 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, 133 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location,
132 const base::FilePath& shortcut_path, 134 const base::FilePath& shortcut_path,
133 const base::FilePath& profile_path) { 135 const base::FilePath& profile_path) {
134 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); 136 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString();
135 137
136 // Ensure that the corresponding icon exists. 138 // Ensure that the corresponding icon exists.
137 const base::FilePath icon_path = 139 const base::FilePath icon_path =
138 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); 140 profiles::internal::GetProfileIconPath(profile_path);
139 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString(); 141 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString();
140 142
141 base::win::ShortcutProperties expected_properties; 143 base::win::ShortcutProperties expected_properties;
142 expected_properties.set_app_id( 144 expected_properties.set_app_id(
143 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); 145 ShellIntegration::GetChromiumModelIdForProfile(profile_path));
144 expected_properties.set_target(GetExePath()); 146 expected_properties.set_target(GetExePath());
145 expected_properties.set_description(GetDistribution()->GetAppDescription()); 147 expected_properties.set_description(GetDistribution()->GetAppDescription());
146 expected_properties.set_dual_mode(false); 148 expected_properties.set_dual_mode(false);
147 expected_properties.set_arguments( 149 expected_properties.set_arguments(
148 profiles::internal::CreateProfileShortcutFlags(profile_path)); 150 profiles::internal::CreateProfileShortcutFlags(profile_path));
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 756
755 // Delete the shortcut for the first profile, but keep the one for the 2nd. 757 // 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)); 758 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false));
757 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 759 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path));
758 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); 760 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path));
759 761
760 const base::FilePath system_level_shortcut_path = 762 const base::FilePath system_level_shortcut_path =
761 CreateRegularSystemLevelShortcut(FROM_HERE); 763 CreateRegularSystemLevelShortcut(FROM_HERE);
762 764
763 // Delete the profile that has a shortcut, which will exercise the non-profile 765 // Delete the profile that has a shortcut, which will exercise the non-profile
764 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is 766 // shortcut creation path in |DeleteDesktopShortcuts()|, which is
765 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. 767 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test.
766 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 768 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
767 RunPendingTasks(); 769 RunPendingTasks();
768 770
769 // Verify that only the system-level shortcut still exists. 771 // Verify that only the system-level shortcut still exists.
770 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); 772 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path));
771 EXPECT_FALSE(file_util::PathExists( 773 EXPECT_FALSE(file_util::PathExists(
772 GetDefaultShortcutPathForProfile(string16()))); 774 GetDefaultShortcutPathForProfile(string16())));
773 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 775 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path));
774 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 776 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
775 } 777 }
778
779 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) {
780 SetupDefaultProfileShortcut(FROM_HERE);
781
782 const base::FilePath icon_path =
783 profiles::internal::GetProfileIconPath(profile_1_path_);
784
785 EXPECT_TRUE(file_util::PathExists(icon_path));
786 EXPECT_TRUE(file_util::Delete(icon_path, false));
787 EXPECT_FALSE(file_util::PathExists(icon_path));
788
789 profile_shortcut_manager_->CreateProfileIcon(profile_1_path_,
790 base::Closure());
791 RunPendingTasks();
792 EXPECT_TRUE(file_util::PathExists(icon_path));
793 }
794
795 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) {
Alexei Svitkine (slow) 2013/06/13 13:16:05 Sweet test! Can you also test the avatar change sc
calamity 2013/06/14 04:09:05 Done.
796 SetupDefaultProfileShortcut(FROM_HERE);
797 const base::FilePath icon_path_1 =
798 profiles::internal::GetProfileIconPath(profile_1_path_);
799 const base::FilePath icon_path_2 =
800 profiles::internal::GetProfileIconPath(profile_2_path_);
801
802 // Default profile has unbadged icon to start.
803 std::string unbadged_icon_1;
804 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &unbadged_icon_1));
805
806 // Creating a new profile adds a badge to both the new profile icon and the
807 // default profile icon. Since they use the same icon index, the icon files
808 // should be the same.
809 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
810
811 std::string badged_icon_1;
812 EXPECT_TRUE(file_util::ReadFileToString(icon_path_1, &badged_icon_1));
813 std::string badged_icon_2;
814 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &badged_icon_2));
815
816 EXPECT_NE(badged_icon_1, unbadged_icon_1);
817 EXPECT_EQ(badged_icon_1, badged_icon_2);
818
819 // Deleting the default profile will unbadge the new profile's icon and should
820 // result in an icon that is identical to the unbadged default profile icon.
821 profile_info_cache_->DeleteProfileFromCache(profile_1_path_);
822 RunPendingTasks();
823
824 std::string unbadged_icon_2;
825 EXPECT_TRUE(file_util::ReadFileToString(icon_path_2, &unbadged_icon_2));
826 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2);
827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698