Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <objbase.h> | 5 #include <objbase.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/test/scoped_path_override.h" | 20 #include "base/test/scoped_path_override.h" |
| 20 #include "base/test/test_shortcut_win.h" | 21 #include "base/test/test_shortcut_win.h" |
| 21 #include "base/version.h" | 22 #include "base/version.h" |
| 22 #include "base/win/shortcut.h" | 23 #include "base/win/shortcut.h" |
| 23 #include "chrome/installer/setup/install.h" | 24 #include "chrome/installer/setup/install.h" |
| 24 #include "chrome/installer/setup/install_worker.h" | 25 #include "chrome/installer/setup/install_worker.h" |
| 25 #include "chrome/installer/setup/setup_constants.h" | 26 #include "chrome/installer/setup/setup_constants.h" |
| 26 #include "chrome/installer/util/browser_distribution.h" | 27 #include "chrome/installer/util/browser_distribution.h" |
| 27 #include "chrome/installer/util/install_util.h" | 28 #include "chrome/installer/util/install_util.h" |
| 28 #include "chrome/installer/util/installer_state.h" | 29 #include "chrome/installer/util/installer_state.h" |
| 29 #include "chrome/installer/util/master_preferences.h" | 30 #include "chrome/installer/util/master_preferences.h" |
| 30 #include "chrome/installer/util/master_preferences_constants.h" | 31 #include "chrome/installer/util/master_preferences_constants.h" |
| 31 #include "chrome/installer/util/product.h" | 32 #include "chrome/installer/util/product.h" |
| 32 #include "chrome/installer/util/shell_util.h" | 33 #include "chrome/installer/util/shell_util.h" |
| 33 #include "chrome/installer/util/util_constants.h" | 34 #include "chrome/installer/util/util_constants.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 39 base::FilePath GetNormalizedFilePath(const base::FilePath& path) { | |
| 40 base::FilePath normalized_path; | |
| 41 ASSERT_TRUE(base::NormalizeFilePath(path, &normalized_path)); | |
| 42 return normalized_path; | |
| 43 } | |
| 44 | |
| 38 class CreateVisualElementsManifestTest : public testing::Test { | 45 class CreateVisualElementsManifestTest : public testing::Test { |
| 39 protected: | 46 protected: |
| 40 void SetUp() override { | 47 void SetUp() override { |
| 41 // Create a temp directory for testing. | 48 // Create a temp directory for testing. |
| 42 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 49 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 43 | 50 |
| 44 version_ = Version("0.0.0.0"); | 51 version_ = Version("0.0.0.0"); |
| 45 | 52 |
| 46 version_dir_ = test_dir_.path().AppendASCII(version_.GetString()); | 53 version_dir_ = test_dir_.path().AppendASCII(version_.GetString()); |
| 47 ASSERT_TRUE(base::CreateDirectory(version_dir_)); | 54 ASSERT_TRUE(base::CreateDirectory(version_dir_)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 63 | 70 |
| 64 // The path to |test_dir_|\|version_|. | 71 // The path to |test_dir_|\|version_|. |
| 65 base::FilePath version_dir_; | 72 base::FilePath version_dir_; |
| 66 | 73 |
| 67 // The path to VisualElementsManifest.xml. | 74 // The path to VisualElementsManifest.xml. |
| 68 base::FilePath manifest_path_; | 75 base::FilePath manifest_path_; |
| 69 }; | 76 }; |
| 70 | 77 |
| 71 class InstallShortcutTest : public testing::Test { | 78 class InstallShortcutTest : public testing::Test { |
| 72 protected: | 79 protected: |
| 80 struct UpdateShortcutsTestCase { | |
| 81 const base::FilePath::CharType* target_path; | |
| 82 const base::FilePath::CharType* icon_path; | |
|
gab
2016/03/18 16:21:24
Comments on each member's meaning (relative path,
fdoray
2016/03/18 17:01:01
Done.
| |
| 83 bool should_update; | |
| 84 }; | |
| 85 | |
| 73 void SetUp() override { | 86 void SetUp() override { |
| 74 EXPECT_EQ(S_OK, CoInitialize(NULL)); | 87 EXPECT_EQ(S_OK, CoInitialize(NULL)); |
| 75 | 88 |
| 76 dist_ = BrowserDistribution::GetDistribution(); | 89 dist_ = BrowserDistribution::GetDistribution(); |
| 77 ASSERT_TRUE(dist_ != NULL); | 90 ASSERT_TRUE(dist_ != NULL); |
| 78 product_.reset(new installer::Product(dist_)); | 91 product_.reset(new installer::Product(dist_)); |
| 79 | 92 |
| 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 93 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 81 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); | 94 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); |
| 82 EXPECT_EQ(0, base::WriteFile(chrome_exe_, "", 0)); | 95 EXPECT_EQ(0, base::WriteFile(chrome_exe_, "", 0)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 master_prefs += (i == 0 ? "\"" : ",\""); | 182 master_prefs += (i == 0 ? "\"" : ",\""); |
| 170 master_prefs += desired_prefs[i].pref_name; | 183 master_prefs += desired_prefs[i].pref_name; |
| 171 master_prefs += "\":"; | 184 master_prefs += "\":"; |
| 172 master_prefs += desired_prefs[i].is_desired ? "true" : "false"; | 185 master_prefs += desired_prefs[i].is_desired ? "true" : "false"; |
| 173 } | 186 } |
| 174 master_prefs += "}}"; | 187 master_prefs += "}}"; |
| 175 | 188 |
| 176 return new installer::MasterPreferences(master_prefs); | 189 return new installer::MasterPreferences(master_prefs); |
| 177 } | 190 } |
| 178 | 191 |
| 192 // Creates the shortcuts defined by |test_cases|. Tries to update the target | |
| 193 // path of these shortcuts to |new_target_path| using | |
|
gab
2016/03/18 16:21:24
|new_target_path_relative|
fdoray
2016/03/18 17:01:01
Done.
| |
| 194 // UpdatePerUserShortcutsInLocation(). Verifies that the right shortcuts have | |
| 195 // been updated. | |
| 196 void TestUpdateShortcuts(const UpdateShortcutsTestCase* test_cases, | |
| 197 size_t num_test_cases, | |
| 198 const base::FilePath& new_target_path_relative) { | |
| 199 // Create shortcuts. | |
| 200 for (size_t i = 0; i < num_test_cases; ++i) { | |
| 201 // Make sure that the target exists. | |
| 202 const base::FilePath target_path = | |
| 203 temp_dir_.path().Append(test_cases[i].target_path); | |
| 204 ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); | |
| 205 base::File file(target_path, | |
| 206 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); | |
| 207 ASSERT_TRUE(file.IsValid()); | |
| 208 static const char kDummyData[] = "dummy"; | |
| 209 ASSERT_EQ(arraysize(kDummyData), | |
| 210 file.WriteAtCurrentPos(kDummyData, arraysize(kDummyData))); | |
|
gab
2016/03/18 16:21:25
Wrap lines 204-210 in
if (!base::PathExists(target
fdoray
2016/03/18 17:01:01
Done.
| |
| 211 | |
| 212 // Create the shortcut. | |
| 213 base::win::ShortcutProperties properties; | |
| 214 properties.set_target(target_path); | |
| 215 properties.set_icon(temp_dir_.path().Append(test_cases[i].icon_path), 1); | |
| 216 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 217 user_desktop_shortcut_.InsertBeforeExtension( | |
| 218 base::SizeTToString16(i)), | |
| 219 properties, base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 220 } | |
| 221 | |
| 222 // Update shortcuts. | |
| 223 const base::FilePath new_target_path = | |
| 224 temp_dir_.path().Append(new_target_path_relative); | |
| 225 installer::UpdatePerUserShortcutsInLocation( | |
| 226 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
| 227 new_target_path.DirName().DirName(), new_target_path.BaseName(), | |
| 228 new_target_path); | |
| 229 | |
| 230 // Verify that shortcuts were updated correctly. | |
| 231 for (size_t i = 0; i < num_test_cases; ++i) { | |
| 232 base::FilePath target_path; | |
| 233 ASSERT_TRUE(base::win::ResolveShortcut( | |
| 234 user_desktop_shortcut_.InsertBeforeExtension( | |
| 235 base::SizeTToString16(i)), | |
| 236 &target_path, nullptr)); | |
| 237 | |
| 238 if (test_cases[i].should_update) { | |
| 239 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | |
| 240 GetNormalizedFilePath(target_path)); | |
| 241 } else { | |
| 242 EXPECT_EQ(GetNormalizedFilePath( | |
| 243 temp_dir_.path().Append(test_cases[i].target_path)), | |
| 244 GetNormalizedFilePath(target_path)); | |
| 245 } | |
| 246 } | |
| 247 } | |
| 248 | |
| 179 base::win::ShortcutProperties expected_properties_; | 249 base::win::ShortcutProperties expected_properties_; |
| 180 base::win::ShortcutProperties expected_start_menu_properties_; | 250 base::win::ShortcutProperties expected_start_menu_properties_; |
| 181 | 251 |
| 182 BrowserDistribution* dist_; | 252 BrowserDistribution* dist_; |
| 183 base::FilePath chrome_exe_; | 253 base::FilePath chrome_exe_; |
| 184 scoped_ptr<installer::Product> product_; | 254 scoped_ptr<installer::Product> product_; |
| 185 scoped_ptr<installer::MasterPreferences> prefs_; | 255 scoped_ptr<installer::MasterPreferences> prefs_; |
| 186 | 256 |
| 187 base::ScopedTempDir temp_dir_; | 257 base::ScopedTempDir temp_dir_; |
| 188 base::ScopedTempDir fake_user_desktop_; | 258 base::ScopedTempDir fake_user_desktop_; |
| 189 base::ScopedTempDir fake_common_desktop_; | 259 base::ScopedTempDir fake_common_desktop_; |
| 190 base::ScopedTempDir fake_user_quick_launch_; | 260 base::ScopedTempDir fake_user_quick_launch_; |
| 191 base::ScopedTempDir fake_start_menu_; | 261 base::ScopedTempDir fake_start_menu_; |
| 192 base::ScopedTempDir fake_common_start_menu_; | 262 base::ScopedTempDir fake_common_start_menu_; |
| 193 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 263 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
| 194 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 264 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
| 195 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 265 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
| 196 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 266 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
| 197 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 267 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
| 198 | 268 |
| 199 base::FilePath user_desktop_shortcut_; | 269 base::FilePath user_desktop_shortcut_; |
| 200 base::FilePath user_quick_launch_shortcut_; | 270 base::FilePath user_quick_launch_shortcut_; |
| 201 base::FilePath user_start_menu_shortcut_; | 271 base::FilePath user_start_menu_shortcut_; |
| 202 base::FilePath user_start_menu_subdir_shortcut_; | 272 base::FilePath user_start_menu_subdir_shortcut_; |
| 203 base::FilePath system_desktop_shortcut_; | 273 base::FilePath system_desktop_shortcut_; |
| 204 base::FilePath system_start_menu_shortcut_; | 274 base::FilePath system_start_menu_shortcut_; |
| 205 base::FilePath system_start_menu_subdir_shortcut_; | 275 base::FilePath system_start_menu_subdir_shortcut_; |
| 206 }; | 276 }; |
| 207 | 277 |
| 208 base::FilePath GetNormalizedFilePath(const base::FilePath& path) { | |
| 209 base::FilePath normalized_path; | |
| 210 base::NormalizeFilePath(path, &normalized_path); | |
| 211 return normalized_path; | |
| 212 } | |
| 213 | |
| 214 } // namespace | 278 } // namespace |
| 215 | 279 |
| 216 // Test that VisualElementsManifest.xml is not created when VisualElements are | 280 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 217 // not present. | 281 // not present. |
| 218 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 282 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 219 ASSERT_TRUE( | 283 ASSERT_TRUE( |
| 220 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); | 284 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| 221 ASSERT_FALSE(base::PathExists(manifest_path_)); | 285 ASSERT_FALSE(base::PathExists(manifest_path_)); |
| 222 } | 286 } |
| 223 | 287 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 installer::CreateOrUpdateShortcuts( | 523 installer::CreateOrUpdateShortcuts( |
| 460 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 524 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 461 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); | 525 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); |
| 462 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); | 526 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); |
| 463 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 527 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 464 expected_properties_); | 528 expected_properties_); |
| 465 base::win::ValidateShortcut(user_start_menu_shortcut_, | 529 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 466 expected_start_menu_properties_); | 530 expected_start_menu_properties_); |
| 467 } | 531 } |
| 468 | 532 |
| 469 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { | 533 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { |
|
gab
2016/03/18 16:21:25
UpdatePerUserChromeShortcuts
fdoray
2016/03/18 17:01:01
Done.
| |
| 470 static const struct TestCase { | 534 static const UpdateShortcutsTestCase kTestCases[] = { |
| 471 const base::FilePath::CharType* relative_target_path; | 535 // Target in the Chrome Canary install directory. No icon. |
|
gab
2016/03/18 16:21:25
s/Target/Shortcut target/ (same below)
(there are
fdoray
2016/03/18 17:01:01
Done.
| |
| 472 bool should_update; | |
| 473 } kTargetPathsToUpdate[] = { | |
| 474 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 536 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 475 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), | 537 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| 476 false}, | 538 nullptr, false}, |
| 477 {FILE_PATH_LITERAL( | 539 {FILE_PATH_LITERAL( |
| 478 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), | 540 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| 479 false}, | 541 nullptr, false}, |
| 480 {FILE_PATH_LITERAL( | 542 {FILE_PATH_LITERAL( |
| 481 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | 543 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| 482 false}, | 544 nullptr, false}, |
| 483 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 545 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 484 "SxS\\Application\\something_else.exe"), | 546 "SxS\\Application\\something_else.exe"), |
| 485 false}, | 547 nullptr, false}, |
| 548 | |
| 549 // Target in the Chrome install directory. No icon. | |
| 486 {FILE_PATH_LITERAL( | 550 {FILE_PATH_LITERAL( |
| 487 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), | 551 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), |
| 488 true}, | 552 nullptr, true}, |
| 489 {FILE_PATH_LITERAL( | 553 {FILE_PATH_LITERAL( |
| 490 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), | 554 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), |
| 491 true}, | 555 nullptr, true}, |
| 492 {FILE_PATH_LITERAL( | 556 {FILE_PATH_LITERAL( |
| 493 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | 557 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| 494 true}, | 558 nullptr, true}, |
| 495 {FILE_PATH_LITERAL( | 559 {FILE_PATH_LITERAL( |
| 496 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), | 560 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), |
| 561 nullptr, false}, | |
| 562 | |
|
gab
2016/03/18 16:21:24
Also add a section pointing to system-level Chrome
fdoray
2016/03/18 17:01:01
Done.
| |
| 563 // Dummy target. Icon in the Chrome Canary install directory. | |
| 564 {FILE_PATH_LITERAL("dummy.exe"), | |
| 565 FILE_PATH_LITERAL( | |
| 566 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | |
| 497 false}, | 567 false}, |
| 498 {FILE_PATH_LITERAL("something_else.exe"), false}, | 568 {FILE_PATH_LITERAL("dummy.exe"), |
| 569 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | |
| 570 "SxS\\Application\\User Data\\Profile 1\\Google " | |
| 571 "Profile.ico"), | |
| 572 false}, | |
| 573 | |
| 574 // Dummy target. Icon in the Chrome install directory. | |
| 575 {FILE_PATH_LITERAL("dummy.exe"), | |
| 576 FILE_PATH_LITERAL( | |
| 577 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | |
| 578 true}, | |
| 579 {FILE_PATH_LITERAL("dummy.exe"), | |
| 580 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\Application\\User " | |
| 581 "Data\\Profile 1\\Google Profile.ico"), | |
| 582 true}, | |
| 583 | |
| 584 // Shortcuts that don't belong to Chrome. | |
| 585 {FILE_PATH_LITERAL("something_else.exe"), nullptr, false}, | |
| 586 {FILE_PATH_LITERAL("something_else.exe"), | |
| 587 FILE_PATH_LITERAL("AppData\\Local\\Google\\Something Else.ico"), false}, | |
| 499 }; | 588 }; |
| 500 | 589 |
| 501 // Create shortcuts. | 590 TestUpdateShortcuts( |
| 502 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { | 591 kTestCases, arraysize(kTestCases), |
| 503 const base::FilePath target_path = | 592 base::FilePath(FILE_PATH_LITERAL( |
| 504 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); | 593 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"))); |
| 505 ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); | |
| 506 base::File file(target_path, base::File::FLAG_CREATE); | |
| 507 ASSERT_TRUE(file.IsValid()); | |
| 508 | |
| 509 base::win::ShortcutProperties properties; | |
| 510 properties.set_target(target_path); | |
| 511 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 512 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 513 properties, base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 514 } | |
| 515 | |
| 516 // Update shortcuts. | |
| 517 const base::FilePath new_target_path = | |
| 518 temp_dir_.path().Append(FILE_PATH_LITERAL( | |
| 519 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe")); | |
| 520 installer::UpdatePerUserShortcutsInLocation( | |
| 521 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
| 522 new_target_path.DirName().DirName(), new_target_path.BaseName(), | |
| 523 new_target_path); | |
| 524 | |
| 525 // Verify that shortcuts were updated correctly. | |
| 526 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { | |
| 527 base::FilePath target_path; | |
| 528 ASSERT_TRUE(base::win::ResolveShortcut( | |
| 529 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 530 &target_path, nullptr)); | |
| 531 | |
| 532 if (kTargetPathsToUpdate[i].should_update) { | |
| 533 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | |
| 534 GetNormalizedFilePath(target_path)); | |
| 535 } else { | |
| 536 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append( | |
| 537 kTargetPathsToUpdate[i].relative_target_path)), | |
| 538 GetNormalizedFilePath(target_path)); | |
| 539 } | |
| 540 } | |
| 541 } | 594 } |
| 542 | 595 |
| 543 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) { | 596 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) { |
|
gab
2016/03/18 16:21:25
UpdatePerUserCanaryShortcuts
fdoray
2016/03/18 17:01:01
Done.
| |
| 544 static const struct TestCase { | 597 static const UpdateShortcutsTestCase kTestCases[] = { |
| 545 const base::FilePath::CharType* relative_target_path; | 598 // Target in the Chrome Canary install directory. No icon. |
| 546 bool should_update; | |
| 547 } kTargetPathsToUpdate[] = { | |
| 548 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 599 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 549 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), | 600 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| 550 true}, | 601 nullptr, true}, |
| 551 {FILE_PATH_LITERAL( | 602 {FILE_PATH_LITERAL( |
| 552 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), | 603 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| 553 true}, | 604 nullptr, true}, |
| 554 {FILE_PATH_LITERAL( | 605 {FILE_PATH_LITERAL( |
| 555 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | 606 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), |
| 556 true}, | 607 nullptr, true}, |
| 557 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 608 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 558 "SxS\\Application\\something_else.exe"), | 609 "SxS\\Application\\something_else.exe"), |
| 559 false}, | 610 nullptr, false}, |
| 611 | |
| 612 // Target in the Chrome install directory. No icon. | |
| 560 {FILE_PATH_LITERAL( | 613 {FILE_PATH_LITERAL( |
| 561 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), | 614 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), |
| 562 false}, | 615 nullptr, false}, |
| 563 {FILE_PATH_LITERAL( | 616 {FILE_PATH_LITERAL( |
| 564 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), | 617 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), |
| 565 false}, | 618 nullptr, false}, |
| 566 {FILE_PATH_LITERAL( | 619 {FILE_PATH_LITERAL( |
| 567 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | 620 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), |
| 568 false}, | 621 nullptr, false}, |
| 569 {FILE_PATH_LITERAL( | 622 {FILE_PATH_LITERAL( |
| 570 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), | 623 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), |
| 624 nullptr, false}, | |
| 625 | |
| 626 // Dummy target. Icon in the Chrome Canary install directory. | |
| 627 {FILE_PATH_LITERAL("dummy.exe"), | |
| 628 FILE_PATH_LITERAL( | |
| 629 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | |
| 630 true}, | |
| 631 {FILE_PATH_LITERAL("dummy.exe"), | |
| 632 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | |
| 633 "SxS\\Application\\User Data\\Profile 1\\Google " | |
| 634 "Profile.ico"), | |
| 635 true}, | |
| 636 | |
| 637 // Dummy target. Icon in the Chrome install directory. | |
| 638 {FILE_PATH_LITERAL("dummy.exe"), | |
| 639 FILE_PATH_LITERAL( | |
| 640 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | |
| 571 false}, | 641 false}, |
| 572 {FILE_PATH_LITERAL("something_else.exe"), false}, | 642 {FILE_PATH_LITERAL("dummy.exe"), |
| 643 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\Application\\User " | |
| 644 "Data\\Profile 1\\Google Profile.ico"), | |
| 645 false}, | |
| 646 | |
| 647 // Shortcuts that don't belong to Chrome. | |
| 648 {FILE_PATH_LITERAL("something_else.exe"), nullptr, false}, | |
| 649 {FILE_PATH_LITERAL("something_else.exe"), | |
| 650 FILE_PATH_LITERAL("AppData\\Local\\Google\\Something Else.ico"), false}, | |
| 573 }; | 651 }; |
| 574 | 652 |
| 575 // Create shortcuts. | 653 TestUpdateShortcuts( |
| 576 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { | 654 kTestCases, arraysize(kTestCases), |
| 577 const base::FilePath target_path = | 655 base::FilePath(FILE_PATH_LITERAL( |
| 578 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); | 656 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"))); |
| 579 ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); | |
| 580 base::File file(target_path, base::File::FLAG_CREATE); | |
| 581 ASSERT_TRUE(file.IsValid()); | |
| 582 | |
| 583 base::win::ShortcutProperties properties; | |
| 584 properties.set_target(target_path); | |
| 585 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 586 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 587 properties, base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 588 } | |
| 589 | |
| 590 // Update shortcuts. | |
| 591 const base::FilePath new_target_path = | |
| 592 temp_dir_.path().Append(FILE_PATH_LITERAL( | |
| 593 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe")); | |
| 594 installer::UpdatePerUserShortcutsInLocation( | |
| 595 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
| 596 new_target_path.DirName().DirName(), new_target_path.BaseName(), | |
| 597 new_target_path); | |
| 598 | |
| 599 // Verify that shortcuts were updated correctly. | |
| 600 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { | |
| 601 base::FilePath target_path; | |
| 602 ASSERT_TRUE(base::win::ResolveShortcut( | |
| 603 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 604 &target_path, nullptr)); | |
| 605 | |
| 606 if (kTargetPathsToUpdate[i].should_update) { | |
| 607 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | |
| 608 GetNormalizedFilePath(target_path)); | |
| 609 } else { | |
| 610 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append( | |
| 611 kTargetPathsToUpdate[i].relative_target_path)), | |
| 612 GetNormalizedFilePath(target_path)); | |
| 613 } | |
| 614 } | |
| 615 } | 657 } |
| 616 | 658 |
| 617 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { | 659 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { |
| 618 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); | 660 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); |
| 619 static const wchar_t kExpectedEscapedVal[] = | 661 static const wchar_t kExpectedEscapedVal[] = |
| 620 L"This has 'crazy' \"chars\" && < and > signs."; | 662 L"This has 'crazy' \"chars\" && < and > signs."; |
| 621 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 663 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 622 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 664 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 623 } | 665 } |
| 624 | 666 |
| 625 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 667 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 626 base::string16 val(L"Google Chrome"); | 668 base::string16 val(L"Google Chrome"); |
| 627 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 669 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 628 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 670 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 629 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 671 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 630 } | 672 } |
| OLD | NEW |