Chromium Code Reviews| Index: chrome/installer/setup/install_unittest.cc |
| diff --git a/chrome/installer/setup/install_unittest.cc b/chrome/installer/setup/install_unittest.cc |
| index 44ad12126b18b25e92a14a675cd2a289d1956935..aeb98cfb3fa410942eccb2f81acab31b61825a6d 100644 |
| --- a/chrome/installer/setup/install_unittest.cc |
| +++ b/chrome/installer/setup/install_unittest.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/path_service.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -466,7 +467,68 @@ TEST_F(InstallShortcutTest, CreateIfNoSystemLevelSomeSystemShortcutsExist) { |
| expected_start_menu_properties_); |
| } |
| -TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcutsIcon) { |
|
gab
2016/03/17 20:14:23
Since all of these tests essentially more or less
fdoray
2016/03/18 14:08:59
Done.
|
| + static const struct TestCase { |
| + const base::FilePath::CharType* icon; |
| + bool should_update; |
| + } kTestCases[] = { |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\User Data\\Profile " |
| + "1\\Google Profile.ico"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS\\User " |
| + "Data\\Profile 1\\Google Profile.ico"), |
| + false}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Something Else.ico"), false}, |
| + }; |
| + |
| + base::FilePath target_path; |
| + ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &target_path)); |
| + |
| + // Create shortcuts. |
| + for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| + base::win::ShortcutProperties properties; |
| + properties.set_target(target_path); |
| + properties.set_icon(temp_dir_.path().Append(kTestCases[i].icon), 1); |
| + ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| + user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), |
| + properties, base::win::SHORTCUT_CREATE_ALWAYS)); |
| + } |
| + |
| + // Update shortcuts. |
| + base::FilePath new_target_path = |
| + temp_dir_.path().Append(target_path.BaseName()); |
| + ASSERT_TRUE(base::CopyFile(target_path, new_target_path)); |
| + |
| + installer::UpdatePerUserShortcutsInLocation( |
| + ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| + temp_dir_.path().Append( |
| + FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome")), |
| + base::FilePath(FILE_PATH_LITERAL("dummy.exe")), new_target_path); |
| + |
| + // Verify that shortcuts were updated correctly. |
| + for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| + base::FilePath actual_target_path; |
| + ASSERT_TRUE(base::win::ResolveShortcut( |
| + user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), |
| + &actual_target_path, nullptr)); |
| + |
| + if (kTestCases[i].should_update) { |
| + EXPECT_EQ(GetNormalizedFilePath(new_target_path), |
| + GetNormalizedFilePath(actual_target_path)); |
| + } else { |
| + EXPECT_EQ(GetNormalizedFilePath(target_path), |
| + GetNormalizedFilePath(actual_target_path)); |
| + } |
| + } |
| +} |
| + |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcutsTarget) { |
| static const struct TestCase { |
| const base::FilePath::CharType* relative_target_path; |
| bool should_update; |
| @@ -540,7 +602,68 @@ TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { |
| } |
| } |
| -TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) { |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcutsIconCanary) { |
| + static const struct TestCase { |
| + const base::FilePath::CharType* icon; |
| + bool should_update; |
| + } kTestCases[] = { |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\User Data\\Profile " |
| + "1\\Google Profile.ico"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS\\User " |
| + "Data\\Profile 1\\Google Profile.ico"), |
| + true}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Something Else.ico"), false}, |
| + }; |
| + |
| + base::FilePath target_path; |
| + ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &target_path)); |
| + |
| + // Create shortcuts. |
| + for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| + base::win::ShortcutProperties properties; |
| + properties.set_target(target_path); |
| + properties.set_icon(temp_dir_.path().Append(kTestCases[i].icon), 1); |
| + ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| + user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), |
| + properties, base::win::SHORTCUT_CREATE_ALWAYS)); |
| + } |
| + |
| + // Update shortcuts. |
| + base::FilePath new_target_path = |
| + temp_dir_.path().Append(target_path.BaseName()); |
| + ASSERT_TRUE(base::CopyFile(target_path, new_target_path)); |
| + |
| + installer::UpdatePerUserShortcutsInLocation( |
| + ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| + temp_dir_.path().Append( |
| + FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS")), |
| + base::FilePath(FILE_PATH_LITERAL("dummy.exe")), new_target_path); |
| + |
| + // Verify that shortcuts were updated correctly. |
| + for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| + base::FilePath actual_target_path; |
| + ASSERT_TRUE(base::win::ResolveShortcut( |
| + user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), |
| + &actual_target_path, nullptr)); |
| + |
| + if (kTestCases[i].should_update) { |
| + EXPECT_EQ(GetNormalizedFilePath(new_target_path), |
| + GetNormalizedFilePath(actual_target_path)); |
| + } else { |
| + EXPECT_EQ(GetNormalizedFilePath(target_path), |
| + GetNormalizedFilePath(actual_target_path)); |
| + } |
| + } |
| +} |
| + |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcutsTargetCanary) { |
| static const struct TestCase { |
| const base::FilePath::CharType* relative_target_path; |
| bool should_update; |