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

Unified Diff: chrome/installer/util/shell_util_unittest.cc

Issue 108193019: Installer: adding ResolveShortcutProperties(); updating shortcut icons during shortcut migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing 'shortcut update' flow; adding unit tests for shortcut retargeting; refactoring unittests. Created 7 years 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 side-by-side diff with in-line comments
Download patch
« chrome/installer/util/shell_util.cc ('K') | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/util/shell_util_unittest.cc
diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc
index 1d51b3ca731b15b90ee32684c57902e07999c15e..7f4912c2e5e3334f38a1bf7ed2b87385b994b9b8 100644
--- a/chrome/installer/util/shell_util_unittest.cc
+++ b/chrome/installer/util/shell_util_unittest.cc
@@ -27,6 +27,7 @@
namespace {
const wchar_t kManganeseExe[] = L"manganese.exe";
+const wchar_t kOtherIco[] = L"other.ico";
// TODO(huangs): Separate this into generic shortcut tests and Chrome-specific
// tests. Specifically, we should not overly rely on getting shortcut properties
@@ -47,6 +48,9 @@ class ShellUtilShortcutTest : public testing::Test {
manganese_exe_ = temp_dir_.path().Append(kManganeseExe);
EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0));
+ other_ico_ = temp_dir_.path().Append(kOtherIco);
+ EXPECT_EQ(0, file_util::WriteFile(other_ico_, "", 0));
+
ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir());
ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir());
ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir());
@@ -82,6 +86,29 @@ class ShellUtilShortcutTest : public testing::Test {
test_properties_.set_dual_mode(true);
}
+ // Helper to create a shortcut on the desktop, using |test_properties_|. Also
+ // asserts that creation was successful. |shortcut_path_out| is an optional
+ // output parameter, for the path to the shortcut created.
+ void CreateTestDesktopShortcut(base::FilePath* shortcut_path_out) {
huangs 2013/12/30 20:19:32 Cannot simply return base::FilePath, because ASSER
gab 2014/01/02 15:51:46 Right, that's because ASSERTs force a "return;", a
huangs 2014/01/02 19:58:22 Key changes: - Returning base::FilePath now. - Che
+ ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
+ ShellUtil::SHORTCUT_LOCATION_DESKTOP,
+ dist_,
+ test_properties_,
+ ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
+ // Compute |shortcut_path|, deducing specified or default values.
+ const base::FilePath& base_path(
+ (test_properties_.level == ShellUtil::CURRENT_USER) ?
+ fake_user_desktop_.path() : fake_common_desktop_.path());
+ string16 shortcut_name = test_properties_.has_shortcut_name() ?
+ test_properties_.shortcut_name :
+ dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
+ base::FilePath shortcut_path(
+ base_path.Append(shortcut_name + installer::kLnkExt));
+ ASSERT_TRUE(base::PathExists(shortcut_path));
+ if (shortcut_path_out)
+ *shortcut_path_out = shortcut_path;
+ }
+
// Validates that the shortcut at |location| matches |properties| (and
// implicit default properties) for |dist|.
// Note: This method doesn't verify the |pin_to_taskbar| property as it
@@ -143,7 +170,7 @@ class ShellUtilShortcutTest : public testing::Test {
expected_properties.set_description(dist->GetAppDescription());
if (properties.has_icon()) {
- expected_properties.set_icon(properties.icon, 0);
+ expected_properties.set_icon(properties.icon, properties.icon_index);
} else {
int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME);
expected_properties.set_icon(chrome_exe_, icon_index);
@@ -186,6 +213,7 @@ class ShellUtilShortcutTest : public testing::Test {
base::FilePath chrome_exe_;
base::FilePath manganese_exe_;
+ base::FilePath other_ico_;
};
} // namespace
@@ -365,15 +393,8 @@ TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) {
}
TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
-
- string16 shortcut_name(
- dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
- installer::kLnkExt);
- base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
- ASSERT_TRUE(base::PathExists(shortcut_path));
+ base::FilePath shortcut_path;
+ CreateTestDesktopShortcut(&shortcut_path);
ASSERT_TRUE(ShellUtil::RemoveShortcuts(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
@@ -384,16 +405,8 @@ TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) {
test_properties_.level = ShellUtil::SYSTEM_LEVEL;
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
-
- string16 shortcut_name(
- dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
- installer::kLnkExt);
- base::FilePath shortcut_path(
- fake_common_desktop_.path().Append(shortcut_name));
- ASSERT_TRUE(base::PathExists(shortcut_path));
+ base::FilePath shortcut_path;
+ CreateTestDesktopShortcut(&shortcut_path);
ASSERT_TRUE(ShellUtil::RemoveShortcuts(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
@@ -407,24 +420,13 @@ TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) {
const wchar_t kShortcutName2[] = L"Chrome 2";
test_properties_.set_shortcut_name(kShortcutName1);
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
- string16 shortcut1_name(
- string16(kShortcutName1).append(installer::kLnkExt));
- base::FilePath shortcut1_path(
- fake_user_desktop_.path().Append(shortcut1_name));
- ASSERT_TRUE(base::PathExists(shortcut1_path));
+ base::FilePath shortcut1_path;
+ CreateTestDesktopShortcut(&shortcut1_path);
test_properties_.set_shortcut_name(kShortcutName2);
test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
- string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt));
- base::FilePath shortcut2_path(
- fake_user_desktop_.path().Append(shortcut2_name));
- ASSERT_TRUE(base::PathExists(shortcut2_path));
+ base::FilePath shortcut2_path;
+ CreateTestDesktopShortcut(&shortcut2_path);
ASSERT_TRUE(ShellUtil::RemoveShortcuts(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
@@ -434,24 +436,14 @@ TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) {
ASSERT_TRUE(base::PathExists(shortcut1_path.DirName()));
}
-TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) {
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
-
- string16 shortcut_name(
- dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
- installer::kLnkExt);
- base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
- ASSERT_TRUE(base::PathExists(shortcut_path));
+TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) {
+ CreateTestDesktopShortcut(NULL);
base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
- ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
- updated_properties.set_target(new_exe);
- // |updated_properties| has arguments.
- ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
+ // Relies on fact that |test_properties_| has non-empty arguments.
+ ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
- chrome_exe_, updated_properties));
+ chrome_exe_, new_exe));
ShellUtil::ShortcutProperties expected_properties(test_properties_);
expected_properties.set_target(new_exe);
@@ -459,26 +451,15 @@ TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) {
expected_properties);
}
-TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) {
+TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) {
test_properties_.level = ShellUtil::SYSTEM_LEVEL;
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
-
- string16 shortcut_name(
- dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
- installer::kLnkExt);
- base::FilePath shortcut_path(
- fake_common_desktop_.path().Append(shortcut_name));
- ASSERT_TRUE(base::PathExists(shortcut_path));
+ CreateTestDesktopShortcut(NULL);
base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
- ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
- updated_properties.set_target(new_exe);
- // |updated_properties| has arguments.
- ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
+ // Relies on fact that |test_properties_| has non-empty arguments.
+ ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
- chrome_exe_, updated_properties));
+ chrome_exe_, new_exe));
ShellUtil::ShortcutProperties expected_properties(test_properties_);
expected_properties.set_target(new_exe);
@@ -486,50 +467,69 @@ TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) {
expected_properties);
}
-TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) {
+TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) {
const wchar_t kShortcutName1[] = L"Chrome 1";
const wchar_t kShortcutName2[] = L"Chrome 2";
// Setup shortcut 1, which has empty arguments.
test_properties_.set_shortcut_name(kShortcutName1);
test_properties_.set_arguments(L"");
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
- string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt));
- base::FilePath shortcut1_path(
- fake_user_desktop_.path().Append(shortcut1_name));
+ CreateTestDesktopShortcut(NULL);
ShellUtil::ShortcutProperties expected_properties1(test_properties_);
// Setup shortcut 2, which has non-empty arguments.
- string16 shortcut2_args = L"--profile-directory=\"Profile 2\"";
test_properties_.set_shortcut_name(kShortcutName2);
- test_properties_.set_arguments(shortcut2_args);
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
- string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt));
- base::FilePath shortcut2_path(
- fake_user_desktop_.path().Append(shortcut2_name));
- ASSERT_TRUE(base::PathExists(shortcut2_path));
+ test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
+ CreateTestDesktopShortcut(NULL);
ShellUtil::ShortcutProperties expected_properties2(test_properties_);
- // Update shortcuts: target "manganese.exe" instead of "chrome.exe".
+ // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only
+ // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated.
base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
- ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
- updated_properties.set_target(new_exe);
-
- // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2.
- ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
+ ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
- chrome_exe_, updated_properties));
+ chrome_exe_, new_exe));
// Verify shortcut 1.
- // |expected_properties1| was unchanged and still targets "chrome.exe", since
+ // |expected_properties1| is unchanged and still targets "chrome.exe", since
// it has empty target, yet we passed |require_args| = true.
ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
expected_properties1);
- // Verify shortcut 2.
+ // Verify shortcut 2, which now targets "manganese.exe".
+ expected_properties2.set_target(new_exe);
+ ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
+ expected_properties2);
+}
+
+TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) {
+ const wchar_t kShortcutName1[] = L"Chrome 1";
+ const wchar_t kShortcutName2[] = L"Chrome 2";
+
+ // Setup shortcut 1, which has icon set to "chrome.exe".
+ test_properties_.set_shortcut_name(kShortcutName1);
+ test_properties_.set_icon(chrome_exe_, 3);
+ CreateTestDesktopShortcut(NULL);
+ ShellUtil::ShortcutProperties expected_properties1(test_properties_);
+
+ // Setup shortcut 2, which has icon set to "other.ico".
+ test_properties_.set_shortcut_name(kShortcutName2);
+ test_properties_.set_icon(other_ico_, 0);
+ CreateTestDesktopShortcut(NULL);
+ ShellUtil::ShortcutProperties expected_properties2(test_properties_);
+
+ // Retarget shortcuts: replace "chrome.exe" with "manganese.exe".
+ // Relies on fact that |test_properties_| has non-empty arguments.
gab 2014/01/02 15:51:46 To strengthen my point about not needing the helpe
huangs 2014/01/02 19:58:22 Passing test_properties_ as parameter to the routi
+ base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
+ ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
+ ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
+ chrome_exe_, new_exe));
+ // Verify shortcut 1: icon now targets "manganese.exe", with same icon index.
+ expected_properties1.set_target(new_exe);
+ expected_properties1.set_icon(new_exe, 3);
+ ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
+ expected_properties1);
+ // Verify shortcut 2: icon remains unchanged.
expected_properties2.set_target(new_exe);
+ expected_properties2.set_icon(other_ico_, 0);
ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
expected_properties2);
}
« chrome/installer/util/shell_util.cc ('K') | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698