Index: chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc |
=================================================================== |
--- chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc (revision 176381) |
+++ chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc (working copy) |
@@ -4,6 +4,7 @@ |
#include <objbase.h> // For CoInitialize(). |
+#include "base/base_paths.h" |
#include "base/file_util.h" |
#include "base/location.h" |
#include "base/message_loop.h" |
@@ -34,8 +35,7 @@ |
ui_thread_(BrowserThread::UI, &message_loop_), |
file_thread_(BrowserThread::FILE, &message_loop_), |
profile_shortcut_manager_(NULL), |
- profile_info_cache_(NULL), |
- fake_user_desktop_(base::DIR_USER_DESKTOP) { |
+ profile_info_cache_(NULL) { |
} |
virtual void SetUp() OVERRIDE { |
@@ -52,11 +52,18 @@ |
ProfileShortcutManager::Create(profile_manager_->profile_manager())); |
ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); |
+ fake_user_desktop_.reset( |
sail
2013/01/14 21:45:19
Are you moving this here to ensure that it runs on
Alexei Svitkine (slow)
2013/01/14 22:40:24
Ah, that makes sense. Thanks for letting me know,
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
|
+ new base::ScopedPathOverride(base::DIR_USER_DESKTOP)); |
ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
distribution_, |
ShellUtil::CURRENT_USER, |
&shortcuts_directory_)); |
- |
+ fake_system_desktop_.reset( |
sail
2013/01/14 21:45:19
same here
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
|
+ new base::ScopedPathOverride(base::DIR_COMMON_DESKTOP)); |
+ ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
+ distribution_, |
+ ShellUtil::SYSTEM_LEVEL, |
+ &system_shortcuts_directory_)); |
profile_1_name_ = L"My profile"; |
profile_1_path_ = CreateProfileDirectory(profile_1_name_); |
profile_2_name_ = L"My profile 2"; |
@@ -216,6 +223,22 @@ |
return shortcut_path; |
} |
+ FilePath CreateRegularSystemLevelShortcut( |
+ const tracked_objects::Location& location) { |
+ installer::Product product(distribution_); |
+ ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); |
+ product.AddDefaultShortcutProperties(exe_path_, &properties); |
+ EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
+ ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, |
+ ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); |
+ const FilePath system_level_shortcut_path = |
+ system_shortcuts_directory_.Append(distribution_->GetAppShortCutName() + |
+ installer::kLnkExt); |
+ EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)) |
+ << location.ToString(); |
+ return system_level_shortcut_path; |
+ } |
+ |
void RenameProfile(const tracked_objects::Location& location, |
const FilePath& profile_path, |
const string16& new_profile_name) { |
@@ -236,9 +259,11 @@ |
scoped_ptr<TestingProfileManager> profile_manager_; |
scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
ProfileInfoCache* profile_info_cache_; |
- base::ScopedPathOverride fake_user_desktop_; |
FilePath exe_path_; |
+ scoped_ptr<base::ScopedPathOverride> fake_user_desktop_; |
FilePath shortcuts_directory_; |
+ scoped_ptr<base::ScopedPathOverride> fake_system_desktop_; |
+ FilePath system_shortcuts_directory_; |
sail
2013/01/14 21:45:19
Ideally we shouldn't cache things in member variab
Alexei Svitkine (slow)
2013/01/14 22:40:24
Things are cached in member variables to make the
sail
2013/01/14 22:43:55
It's not too bad, GetFakeUserDesktop(). That's onl
|
string16 profile_1_name_; |
FilePath profile_1_path_; |
string16 profile_2_name_; |
@@ -629,3 +654,78 @@ |
RunPendingTasks(); |
EXPECT_FALSE(result.has_shortcuts); |
} |
+ |
+TEST_F(ProfileShortcutManagerTest, |
+ ShortcutNotCreatedWhenSystemLevelShortcutExists) { |
+ const FilePath system_level_shortcut_path = |
+ CreateRegularSystemLevelShortcut(FROM_HERE); |
+ |
+ // Create the initial profile. |
+ profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, |
+ string16(), 0, false); |
+ RunPendingTasks(); |
+ ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); |
+ |
+ // Ensure system level continues to exist and user level was not created. |
+ EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
+ EXPECT_FALSE(file_util::PathExists( |
+ GetDefaultShortcutPathForProfile(string16()))); |
+} |
+ |
+TEST_F(ProfileShortcutManagerTest, |
+ DeleteSecondToLastProfileWithoutShortcutWhenSystemLevelShortcutExists) { |
+ SetupAndCreateTwoShortcuts(FROM_HERE); |
+ |
+ const FilePath profile_1_shortcut_path = |
+ GetDefaultShortcutPathForProfile(profile_1_name_); |
+ const FilePath profile_2_shortcut_path = |
+ GetDefaultShortcutPathForProfile(profile_2_name_); |
+ |
+ // Delete the shortcut for the first profile, but keep the one for the 2nd. |
gab
2013/01/14 21:49:30
Why is it necessary to delete shortcut 1 first?
I
Alexei Svitkine (slow)
2013/01/14 22:40:24
These two tests are based on the existing tests De
gab
2013/01/14 22:49:55
Right that sgtm.
|
+ ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); |
+ ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
+ ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); |
+ |
+ const FilePath system_level_shortcut_path = |
+ CreateRegularSystemLevelShortcut(FROM_HERE); |
+ |
+ // Delete the profile that doesn't have a shortcut. |
+ profile_info_cache_->DeleteProfileFromCache(profile_1_path_); |
+ RunPendingTasks(); |
+ |
+ // Verify that only the system level shortcut still exists. |
+ EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
+ EXPECT_FALSE(file_util::PathExists( |
+ GetDefaultShortcutPathForProfile(string16()))); |
+ EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
+ EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
+} |
+ |
+TEST_F(ProfileShortcutManagerTest, |
+ DeleteSecondToLastProfileWithShortcutWhenSystemShortcutLevelExists) { |
+ SetupAndCreateTwoShortcuts(FROM_HERE); |
+ |
+ const FilePath profile_1_shortcut_path = |
+ GetDefaultShortcutPathForProfile(profile_1_name_); |
+ const FilePath profile_2_shortcut_path = |
+ GetDefaultShortcutPathForProfile(profile_2_name_); |
+ |
+ // Delete the shortcut for the first profile, but keep the one for the 2nd. |
+ ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); |
gab
2013/01/14 21:49:30
Same comment about why deleting shortcut 1? It pro
|
+ ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
+ ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); |
+ |
+ const FilePath system_level_shortcut_path = |
+ CreateRegularSystemLevelShortcut(FROM_HERE); |
+ |
+ // Delete the profile that has a shortcut. |
+ profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
+ RunPendingTasks(); |
+ |
+ // Verify that only the system level shortcut still exists. |
+ EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); |
+ EXPECT_FALSE(file_util::PathExists( |
+ GetDefaultShortcutPathForProfile(string16()))); |
+ EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
+ EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
+} |