diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 14:21:46 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 14:21:46 +0000 |
commit | 502c984377dc52fee8362588177d7365a639d5b2 (patch) | |
tree | c5b200fd7385f01a76c64779575318fb07fe50ee | |
parent | 42edf9b0e192fb9a7e1f9f9cf8f696f0f7290c05 (diff) | |
download | chromium_src-502c984377dc52fee8362588177d7365a639d5b2.zip chromium_src-502c984377dc52fee8362588177d7365a639d5b2.tar.gz chromium_src-502c984377dc52fee8362588177d7365a639d5b2.tar.bz2 |
Fix a regression in the creation or updating of the Chrome desktop shortcut.
BUG=78938,78143
TEST=Icon updates correctly between versions and is created correctly on first install.
Review URL: http://codereview.chromium.org/6865004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81744 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/installer/util/shell_util.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/shell_util_unittest.cc | 114 |
2 files changed, 115 insertions, 1 deletions
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index c746719..1d30439 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -458,7 +458,7 @@ bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, // desktop folder. bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path); FilePath shortcut = shortcut_path.Append(shortcut_name); - if (!got_system_desktop || !file_util::PathExists(shortcut_path)) { + if (!got_system_desktop || !file_util::PathExists(shortcut)) { // Either we couldn't query the "All Users" Desktop folder or there's // nothing in it, so let's continue. if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc index 345c1e7..7839f2b 100644 --- a/chrome/installer/util/shell_util_unittest.cc +++ b/chrome/installer/util/shell_util_unittest.cc @@ -12,6 +12,7 @@ #include "base/path_service.h" #include "base/memory/scoped_temp_dir.h" #include "base/win/scoped_comptr.h" +#include "base/win/windows_version.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/shell_util.h" @@ -146,3 +147,116 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { shortcut_path.value(), description2, 1)); } + +TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { + // Run this test on Vista+ only if we are running elevated. + if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { + LOG(ERROR) << "Must be admin to run this test on Vista+"; + return; + } + + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + ASSERT_TRUE(dist != NULL); + // Create an executable in test path by copying ourself to it. + wchar_t exe_full_path_str[MAX_PATH]; + EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); + FilePath exe_full_path(exe_full_path_str); + + FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); + EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); + + const std::wstring description(L"dummy description"); + + FilePath user_desktop_path; + EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); + FilePath system_desktop_path; + EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); + + std::wstring shortcut_name; + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)); + + FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); + FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); + + // Test simple creation of a user-level shortcut. + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::CURRENT_USER, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + user_shortcut_path.value(), + description, + 0)); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, + ShellUtil::CURRENT_USER, + false)); + + // Test simple creation of a system-level shortcut. + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::SYSTEM_LEVEL, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + system_shortcut_path.value(), + description, + 0)); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, + ShellUtil::SYSTEM_LEVEL, + false)); + + // Test creation of a user-level shortcut when a system-level shortcut + // is already present (should fail). + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::SYSTEM_LEVEL, + false, + true)); + EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::CURRENT_USER, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + system_shortcut_path.value(), + description, + 0)); + EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, + ShellUtil::SYSTEM_LEVEL, + false)); + + // Test creation of a system-level shortcut when a user-level shortcut + // is already present (should succeed). + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::CURRENT_USER, + false, + true)); + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, + exe_path.value(), + description, + ShellUtil::SYSTEM_LEVEL, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + user_shortcut_path.value(), + description, + 0)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + system_shortcut_path.value(), + description, + 0)); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, + ShellUtil::CURRENT_USER, + false)); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, + ShellUtil::SYSTEM_LEVEL, + false)); +} |