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

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

Issue 1614943004: Revert of Uniquify profile shortcut name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_shortcut_manager_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file_util.h" 8 #include "base/files/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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 installer::kLnkExt); 231 installer::kLnkExt);
232 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)) 232 EXPECT_TRUE(base::PathExists(system_level_shortcut_path))
233 << location.ToString(); 233 << location.ToString();
234 return system_level_shortcut_path; 234 return system_level_shortcut_path;
235 } 235 }
236 236
237 void RenameProfile(const tracked_objects::Location& location, 237 void RenameProfile(const tracked_objects::Location& location,
238 const base::FilePath& profile_path, 238 const base::FilePath& profile_path,
239 const base::string16& new_profile_name) { 239 const base::string16& new_profile_name) {
240 const size_t profile_index = 240 const size_t profile_index =
241 profile_info_cache_->GetIndexOfProfileWithPath(profile_path); 241 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_);
242 ASSERT_NE(std::string::npos, profile_index); 242 ASSERT_NE(std::string::npos, profile_index);
243 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), 243 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index),
244 new_profile_name); 244 new_profile_name);
245 profile_info_cache_->SetNameOfProfileAtIndex(profile_index, 245 profile_info_cache_->SetNameOfProfileAtIndex(profile_index,
246 new_profile_name); 246 new_profile_name);
247 RunPendingTasks(); 247 RunPendingTasks();
248 } 248 }
249 249
250 BrowserDistribution* GetDistribution() { 250 BrowserDistribution* GetDistribution() {
251 return BrowserDistribution::GetDistribution(); 251 return BrowserDistribution::GetDistribution();
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); 870 EXPECT_NE(unbadged_icon_1, new_badged_icon_1);
871 871
872 // Ensure the icon doesn't change on avatar change without 2 profiles. 872 // Ensure the icon doesn't change on avatar change without 2 profiles.
873 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); 873 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1);
874 RunPendingTasks(); 874 RunPendingTasks();
875 875
876 std::string unbadged_icon_1_a; 876 std::string unbadged_icon_1_a;
877 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); 877 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a));
878 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); 878 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a);
879 } 879 }
880
881 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameUniquified) {
882 const auto suffix =
883 GetDistribution()->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
884 std::set<base::FilePath> excludes;
885
886 auto shortcut_filename =
887 profiles::internal::GetUniqueShortcutFilenameForProfile(
888 L"Carrie", excludes, GetDistribution());
889 EXPECT_EQ(L"Carrie - " + suffix + L".lnk", shortcut_filename);
890 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
891
892 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
893 L"Carrie", excludes, GetDistribution());
894 EXPECT_EQ(L"Carrie - " + suffix + L" (1).lnk", shortcut_filename);
895 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
896
897 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
898 L"Carrie", excludes, GetDistribution());
899 EXPECT_EQ(L"Carrie - " + suffix + L" (2).lnk", shortcut_filename);
900 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
901
902 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
903 L"Steven", excludes, GetDistribution());
904 EXPECT_EQ(L"Steven - " + suffix + L".lnk", shortcut_filename);
905 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
906
907 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
908 L"Steven", excludes, GetDistribution());
909 EXPECT_EQ(L"Steven - " + suffix + L" (1).lnk", shortcut_filename);
910 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
911
912 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
913 L"Carrie", excludes, GetDistribution());
914 EXPECT_EQ(L"Carrie - " + suffix + L" (3).lnk", shortcut_filename);
915 excludes.insert(GetUserShortcutsDirectory().Append(shortcut_filename));
916
917 excludes.erase(
918 GetUserShortcutsDirectory().Append(L"Carrie - " + suffix + L".lnk"));
919 shortcut_filename = profiles::internal::GetUniqueShortcutFilenameForProfile(
920 L"Carrie", excludes, GetDistribution());
921 EXPECT_EQ(L"Carrie - " + suffix + L".lnk", shortcut_filename);
922 }
923
924 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameMatcher) {
925 profiles::internal::ShortcutFilenameMatcher matcher(L"Carrie",
926 GetDistribution());
927 const auto suffix =
928 GetDistribution()->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
929 EXPECT_TRUE(matcher.IsCanonical(L"Carrie - " + suffix + L" (2).lnk"));
930 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L"(2).lnk"));
931 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L" 2.lnk"));
932 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L"2.lnk"));
933 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L" - 2.lnk"));
934 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L" (a).lnk"));
935 EXPECT_TRUE(matcher.IsCanonical(L"Carrie - " + suffix + L" (11).lnk"));
936 EXPECT_TRUE(matcher.IsCanonical(L"Carrie - " + suffix + L" (03).lnk"));
937 EXPECT_TRUE(matcher.IsCanonical(L"Carrie - " + suffix + L" (999).lnk"));
938 EXPECT_FALSE(matcher.IsCanonical(L"Carrie - " + suffix + L" (999).lin"));
939 EXPECT_FALSE(matcher.IsCanonical(L"ABC Carrie - " + suffix + L" DEF.lnk"));
940 EXPECT_FALSE(matcher.IsCanonical(L"ABC Carrie DEF.lnk"));
941 EXPECT_FALSE(matcher.IsCanonical(L"Carrie.lnk"));
942 }
943
944 TEST_F(ProfileShortcutManagerTest, ShortcutsForProfilesWithIdenticalNames) {
945 SetupDefaultProfileShortcut(FROM_HERE);
946
947 // Create new profile - profile2.
948 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
949 // Check that nothing is changed for profile1.
950 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
951
952 // Give to profile1 the same name as profile2.
953 base::string16 new_profile_1_name = profile_2_name_;
954 RenameProfile(FROM_HERE, profile_1_path_, new_profile_1_name);
955 const auto profile_1_shortcut_name = new_profile_1_name + L" - " +
956 GetDistribution()->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
957 L" (1)";
958 const auto profile_1_shortcut_path = GetUserShortcutsDirectory()
959 .Append(profile_1_shortcut_name + installer::kLnkExt);
960 ValidateProfileShortcutAtPath(FROM_HERE,
961 profile_1_shortcut_path,
962 profile_1_path_);
963 // Check that nothing is changed for profile2.
964 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
965
966 // Create new profile - profile3.
967 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_);
968 // Check that nothing is changed for profile1 and profile2.
969 ValidateProfileShortcutAtPath(FROM_HERE,
970 profile_1_shortcut_path,
971 profile_1_path_);
972 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
973
974 // Give to profile3 the same name as profile2.
975 const base::string16 new_profile_3_name = profile_2_name_;
976 RenameProfile(FROM_HERE, profile_3_path_, new_profile_3_name);
977 const auto profile_3_shortcut_name = new_profile_3_name + L" - " +
978 GetDistribution()->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
979 L" (2)";
980 const auto profile_3_shortcut_path = GetUserShortcutsDirectory()
981 .Append(profile_3_shortcut_name + installer::kLnkExt);
982 ValidateProfileShortcutAtPath(FROM_HERE,
983 profile_3_shortcut_path,
984 profile_3_path_);
985 // Check that nothing is changed for profile1 and profile2.
986 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
987 ValidateProfileShortcutAtPath(FROM_HERE,
988 profile_1_shortcut_path,
989 profile_1_path_);
990
991 // Rename profile1 again.
992 new_profile_1_name = L"Carrie";
993 RenameProfile(FROM_HERE, profile_1_path_, new_profile_1_name);
994 ValidateProfileShortcut(FROM_HERE, new_profile_1_name, profile_1_path_);
995 // Check that nothing is changed for profile2 and profile3.
996 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
997 ValidateProfileShortcutAtPath(FROM_HERE,
998 profile_3_shortcut_path,
999 profile_3_path_);
1000
1001 // Delete profile1.
1002 profile_info_cache_->DeleteProfileFromCache(profile_1_path_);
1003 RunPendingTasks();
1004 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_1_name));
1005 // Check that nothing is changed for profile2 and profile3.
1006 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
1007 ValidateProfileShortcutAtPath(FROM_HERE,
1008 profile_3_shortcut_path,
1009 profile_3_path_);
1010
1011 // Delete profile2.
1012 EXPECT_TRUE(base::PathExists(
1013 GetDefaultShortcutPathForProfile(profile_2_name_)));
1014 EXPECT_TRUE(base::PathExists(profile_3_shortcut_path));
1015 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
1016 RunPendingTasks();
1017 EXPECT_FALSE(base::PathExists(
1018 GetDefaultShortcutPathForProfile(profile_2_name_)));
1019 // Only profile3 exists. There should be non-profile shortcut only.
1020 EXPECT_FALSE(base::PathExists(profile_3_shortcut_path));
1021 ValidateNonProfileShortcut(FROM_HERE);
1022 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_shortcut_manager_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698