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

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

Issue 15255004: Refactor of BrowserDistribution. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework Created 7 years, 5 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const tracked_objects::Location& location) { 215 const tracked_objects::Location& location) {
216 BrowserDistribution* distribution = GetDistribution(); 216 BrowserDistribution* distribution = GetDistribution();
217 installer::Product product(distribution); 217 installer::Product product(distribution);
218 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); 218 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL);
219 product.AddDefaultShortcutProperties(GetExePath(), &properties); 219 product.AddDefaultShortcutProperties(GetExePath(), &properties);
220 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( 220 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut(
221 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties, 221 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties,
222 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); 222 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString();
223 const base::FilePath system_level_shortcut_path = 223 const base::FilePath system_level_shortcut_path =
224 GetSystemShortcutsDirectory().Append( 224 GetSystemShortcutsDirectory().Append(
225 distribution->GetAppShortCutName() + installer::kLnkExt); 225 distribution->
226 GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
227 installer::kLnkExt);
226 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)) 228 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path))
227 << location.ToString(); 229 << location.ToString();
228 return system_level_shortcut_path; 230 return system_level_shortcut_path;
229 } 231 }
230 232
231 void RenameProfile(const tracked_objects::Location& location, 233 void RenameProfile(const tracked_objects::Location& location,
232 const base::FilePath& profile_path, 234 const base::FilePath& profile_path,
233 const string16& new_profile_name) { 235 const string16& new_profile_name) {
234 const size_t profile_index = 236 const size_t profile_index =
235 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); 237 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 profiles::internal::GetShortcutFilenameForProfile(kLongProfileName, 305 profiles::internal::GetShortcutFilenameForProfile(kLongProfileName,
304 GetDistribution()); 306 GetDistribution());
305 EXPECT_LT(file_name.size(), kLongProfileName.size()); 307 EXPECT_LT(file_name.size(), kLongProfileName.size());
306 } 308 }
307 309
308 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameStripsReservedCharacters) { 310 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameStripsReservedCharacters) {
309 const string16 kProfileName = L"<Harry/>"; 311 const string16 kProfileName = L"<Harry/>";
310 const string16 kSanitizedProfileName = L"Harry"; 312 const string16 kSanitizedProfileName = L"Harry";
311 BrowserDistribution* distribution = GetDistribution(); 313 BrowserDistribution* distribution = GetDistribution();
312 const string16 expected_name = kSanitizedProfileName + L" - " + 314 const string16 expected_name = kSanitizedProfileName + L" - " +
313 distribution->GetAppShortCutName() + installer::kLnkExt; 315 distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
316 installer::kLnkExt;
314 EXPECT_EQ(expected_name, 317 EXPECT_EQ(expected_name,
315 profiles::internal::GetShortcutFilenameForProfile(kProfileName, 318 profiles::internal::GetShortcutFilenameForProfile(kProfileName,
316 distribution)); 319 distribution));
317 } 320 }
318 321
319 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { 322 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) {
320 BrowserDistribution* distribution = GetDistribution(); 323 BrowserDistribution* distribution = GetDistribution();
321 EXPECT_EQ(distribution->GetAppShortCutName() + installer::kLnkExt, 324 EXPECT_EQ(
322 profiles::internal::GetShortcutFilenameForProfile(string16(), 325 distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
323 distribution)); 326 installer::kLnkExt,
327 profiles::internal::GetShortcutFilenameForProfile(string16(),
328 distribution));
324 } 329 }
325 330
326 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) { 331 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) {
327 const string16 kProfileName = L"MyProfileX"; 332 const string16 kProfileName = L"MyProfileX";
328 const base::FilePath profile_path = 333 const base::FilePath profile_path =
329 profile_info_cache_->GetUserDataDir().Append(kProfileName); 334 profile_info_cache_->GetUserDataDir().Append(kProfileName);
330 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"", 335 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"",
331 profiles::internal::CreateProfileShortcutFlags(profile_path)); 336 profiles::internal::CreateProfileShortcutFlags(profile_path));
332 } 337 }
333 338
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 576
572 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { 577 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) {
573 SetupDefaultProfileShortcut(FROM_HERE); 578 SetupDefaultProfileShortcut(FROM_HERE);
574 579
575 // Delete the shortcut that got created for this profile and instead make 580 // Delete the shortcut that got created for this profile and instead make
576 // a new one without any command-line flags. 581 // a new one without any command-line flags.
577 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), 582 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()),
578 false)); 583 false));
579 const base::FilePath regular_shortcut_path = 584 const base::FilePath regular_shortcut_path =
580 CreateRegularShortcutWithName(FROM_HERE, 585 CreateRegularShortcutWithName(FROM_HERE,
581 GetDistribution()->GetAppShortCutName()); 586 GetDistribution()->GetShortcutName(
587 BrowserDistribution::SHORTCUT_CHROME));
582 588
583 // Add another profile and check that the shortcut was replaced with 589 // Add another profile and check that the shortcut was replaced with
584 // a badged shortcut with the right command line for the profile 590 // a badged shortcut with the right command line for the profile
585 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 591 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
586 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); 592 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
587 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 593 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
588 } 594 }
589 595
590 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { 596 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) {
591 SetupDefaultProfileShortcut(FROM_HERE); 597 SetupDefaultProfileShortcut(FROM_HERE);
592 598
593 // Delete the shortcut that got created for this profile and instead make 599 // Delete the shortcut that got created for this profile and instead make
594 // two new ones without any command-line flags. 600 // two new ones without any command-line flags.
595 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), 601 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()),
596 false)); 602 false));
597 const base::FilePath regular_shortcut_path = 603 const base::FilePath regular_shortcut_path =
598 CreateRegularShortcutWithName(FROM_HERE, 604 CreateRegularShortcutWithName(FROM_HERE,
599 GetDistribution()->GetAppShortCutName()); 605 GetDistribution()->GetShortcutName(
606 BrowserDistribution::SHORTCUT_CHROME));
600 const base::FilePath customized_regular_shortcut_path = 607 const base::FilePath customized_regular_shortcut_path =
601 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); 608 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome");
602 609
603 // 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
604 // other shortcut was updated but kept the same name. 611 // other shortcut was updated but kept the same name.
605 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 612 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
606 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); 613 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
607 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, 614 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path,
608 profile_1_path_); 615 profile_1_path_);
609 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 616 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 772 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
766 RunPendingTasks(); 773 RunPendingTasks();
767 774
768 // Verify that only the system-level shortcut still exists. 775 // Verify that only the system-level shortcut still exists.
769 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); 776 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path));
770 EXPECT_FALSE(file_util::PathExists( 777 EXPECT_FALSE(file_util::PathExists(
771 GetDefaultShortcutPathForProfile(string16()))); 778 GetDefaultShortcutPathForProfile(string16())));
772 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 779 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path));
773 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 780 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
774 } 781 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_shortcut_manager_win.cc » ('j') | chrome/installer/setup/install_worker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698