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 3f2a75d74ebdd418e0b357fee7436f6592271bae..1a8f5d7163c367d63ce2f8e26fcf258037d77e4d 100644 |
| --- a/chrome/installer/setup/install_unittest.cc |
| +++ b/chrome/installer/setup/install_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/string16.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/test/scoped_path_override.h" |
| #include "base/test/test_shortcut_win.h" |
| @@ -459,6 +460,166 @@ TEST_F(InstallShortcutTest, CreateIfNoSystemLevelSomeSystemShortcutsExist) { |
| expected_start_menu_properties_); |
| } |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { |
| + base::FilePath shortcut_path_template; |
| + ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| + dist_, ShellUtil::CURRENT_USER, |
| + &shortcut_path_template)); |
| + shortcut_path_template = |
| + shortcut_path_template.Append(FILE_PATH_LITERAL("shortcut.lnk")); |
|
gab
2016/03/16 21:57:31
You can use the fixture's |user_desktop_shortcut_|
fdoray
2016/03/17 00:50:34
Done.
|
| + |
| + static const struct TestData { |
|
gab
2016/03/16 21:57:30
s/TestData/TestCase/
fdoray
2016/03/17 00:50:34
Done.
|
| + const base::FilePath::CharType* relative_target_path; |
| + bool should_update; |
| + } kTargetPathsToUpdate[] = { |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| + "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| + "SxS\\Application\\something_else.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL("something_else.exe"), false}, |
| + }; |
| + |
| + // Create shortcuts. |
| + for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { |
| + const base::FilePath target_path = |
| + temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); |
| + ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); |
| + base::File file(target_path, base::File::FLAG_CREATE); |
| + ASSERT_TRUE(file.IsValid()); |
| + |
| + base::win::ShortcutProperties properties; |
| + properties.set_target(target_path); |
| + ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| + shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)), |
| + properties, base::win::SHORTCUT_CREATE_ALWAYS)); |
| + } |
| + |
| + // Update shortcuts. |
| + const base::FilePath new_target_path = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe")); |
| + installer::UpdatePerUserShortcutsInLocation( |
| + ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| + new_target_path.DirName().DirName(), new_target_path.BaseName(), |
| + new_target_path); |
| + |
| + // Check if shortcuts were updated correctly. |
|
gab
2016/03/16 21:57:31
s/Check if/Verify that/
fdoray
2016/03/17 00:50:34
Done.
|
| + for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { |
| + base::FilePath target_path; |
| + ASSERT_TRUE(base::win::ResolveShortcut( |
| + shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)), |
| + &target_path, nullptr)); |
| + |
| + if (kTargetPathsToUpdate[i].should_update) { |
| + EXPECT_EQ(new_target_path, target_path); |
| + } else { |
| + EXPECT_EQ( |
| + temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path), |
| + target_path); |
| + } |
| + } |
| +} |
| + |
| +TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) { |
| + base::FilePath shortcut_path_template; |
| + ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| + dist_, ShellUtil::CURRENT_USER, |
| + &shortcut_path_template)); |
| + shortcut_path_template = |
| + shortcut_path_template.Append(FILE_PATH_LITERAL("shortcut.lnk")); |
| + |
| + static const struct TestData { |
| + const base::FilePath::CharType* relative_target_path; |
| + bool should_update; |
| + } kTargetPathsToUpdate[] = { |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| + "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| + true}, |
| + {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| + "SxS\\Application\\something_else.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), |
| + false}, |
| + {FILE_PATH_LITERAL("something_else.exe"), false}, |
| + }; |
| + |
| + // Create shortcuts. |
| + for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { |
| + const base::FilePath target_path = |
| + temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); |
| + ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); |
| + base::File file(target_path, base::File::FLAG_CREATE); |
| + ASSERT_TRUE(file.IsValid()); |
| + |
| + base::win::ShortcutProperties properties; |
| + properties.set_target(target_path); |
| + ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| + shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)), |
| + properties, base::win::SHORTCUT_CREATE_ALWAYS)); |
| + } |
| + |
| + // Update shortcuts. |
| + const base::FilePath new_target_path = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL( |
| + "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe")); |
| + installer::UpdatePerUserShortcutsInLocation( |
| + ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| + new_target_path.DirName().DirName(), new_target_path.BaseName(), |
| + new_target_path); |
| + |
| + // Check if shortcuts were updated correctly. |
| + for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { |
| + base::FilePath target_path; |
| + ASSERT_TRUE(base::win::ResolveShortcut( |
| + shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)), |
| + &target_path, nullptr)); |
| + |
| + if (kTargetPathsToUpdate[i].should_update) { |
| + EXPECT_EQ(new_target_path, target_path); |
| + } else { |
| + EXPECT_EQ( |
| + temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path), |
| + target_path); |
| + } |
| + } |
| +} |
| + |
| TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { |
| base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); |
| static const wchar_t kExpectedEscapedVal[] = |