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

Side by Side Diff: chrome/installer/setup/install_unittest.cc

Issue 1800303006: Fix the path of shortcuts with an icon in the current install dir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nit Created 4 years, 9 months 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 unified diff | Download patch
OLDNEW
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 EXPECT_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
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 // Shortcut target path, relative to |temp_dir_|.
82 const base::FilePath::CharType* target_path;
83
84 // Shortcut icon path, relative to |temp_dir_|. Can be null to create a
85 // shortcut without an icon.
86 const base::FilePath::CharType* icon_path;
87
88 // Whether the shortcut's target path should be updated by
89 // UpdatePerUserShortcutsInLocation().
90 bool should_update;
91 };
92
73 void SetUp() override { 93 void SetUp() override {
74 EXPECT_EQ(S_OK, CoInitialize(NULL)); 94 EXPECT_EQ(S_OK, CoInitialize(NULL));
75 95
76 dist_ = BrowserDistribution::GetDistribution(); 96 dist_ = BrowserDistribution::GetDistribution();
77 ASSERT_TRUE(dist_ != NULL); 97 ASSERT_TRUE(dist_ != NULL);
78 product_.reset(new installer::Product(dist_)); 98 product_.reset(new installer::Product(dist_));
79 99
80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
81 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); 101 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe);
82 EXPECT_EQ(0, base::WriteFile(chrome_exe_, "", 0)); 102 EXPECT_EQ(0, base::WriteFile(chrome_exe_, "", 0));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 master_prefs += (i == 0 ? "\"" : ",\""); 189 master_prefs += (i == 0 ? "\"" : ",\"");
170 master_prefs += desired_prefs[i].pref_name; 190 master_prefs += desired_prefs[i].pref_name;
171 master_prefs += "\":"; 191 master_prefs += "\":";
172 master_prefs += desired_prefs[i].is_desired ? "true" : "false"; 192 master_prefs += desired_prefs[i].is_desired ? "true" : "false";
173 } 193 }
174 master_prefs += "}}"; 194 master_prefs += "}}";
175 195
176 return new installer::MasterPreferences(master_prefs); 196 return new installer::MasterPreferences(master_prefs);
177 } 197 }
178 198
199 // Creates the shortcuts defined by |test_cases|. Tries to update the target
200 // path of these shortcuts to |new_target_path_relative| using
201 // UpdatePerUserShortcutsInLocation(). Verifies that the right shortcuts have
202 // been updated.
203 void TestUpdateShortcuts(const UpdateShortcutsTestCase* test_cases,
204 size_t num_test_cases,
205 const base::FilePath& new_target_path_relative) {
206 // Create shortcuts.
207 for (size_t i = 0; i < num_test_cases; ++i) {
208 // Make sure that the target exists.
209 const base::FilePath target_path =
210 temp_dir_.path().Append(test_cases[i].target_path);
211 if (!base::PathExists(target_path)) {
212 ASSERT_TRUE(base::CreateDirectory(target_path.DirName()));
213 base::File file(target_path, base::File::FLAG_CREATE_ALWAYS |
214 base::File::FLAG_WRITE);
215 ASSERT_TRUE(file.IsValid());
216 static const char kDummyData[] = "dummy";
217 ASSERT_EQ(arraysize(kDummyData),
218 file.WriteAtCurrentPos(kDummyData, arraysize(kDummyData)));
219 }
220
221 // Create the shortcut.
222 base::win::ShortcutProperties properties;
223 properties.set_target(target_path);
224 properties.set_icon(temp_dir_.path().Append(test_cases[i].icon_path), 1);
225 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
226 user_desktop_shortcut_.InsertBeforeExtension(
227 base::SizeTToString16(i)),
228 properties, base::win::SHORTCUT_CREATE_ALWAYS));
229 }
230
231 // Update shortcuts.
232 const base::FilePath new_target_path =
233 temp_dir_.path().Append(new_target_path_relative);
234 installer::UpdatePerUserShortcutsInLocation(
235 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
236 new_target_path.DirName().DirName(), new_target_path.BaseName(),
237 new_target_path);
238
239 // Verify that shortcuts were updated correctly.
240 for (size_t i = 0; i < num_test_cases; ++i) {
241 base::FilePath target_path;
242 ASSERT_TRUE(base::win::ResolveShortcut(
243 user_desktop_shortcut_.InsertBeforeExtension(
244 base::SizeTToString16(i)),
245 &target_path, nullptr));
246
247 if (test_cases[i].should_update) {
248 EXPECT_EQ(GetNormalizedFilePath(new_target_path),
249 GetNormalizedFilePath(target_path));
250 } else {
251 EXPECT_EQ(GetNormalizedFilePath(
252 temp_dir_.path().Append(test_cases[i].target_path)),
253 GetNormalizedFilePath(target_path));
254 }
255 }
256 }
257
179 base::win::ShortcutProperties expected_properties_; 258 base::win::ShortcutProperties expected_properties_;
180 base::win::ShortcutProperties expected_start_menu_properties_; 259 base::win::ShortcutProperties expected_start_menu_properties_;
181 260
182 BrowserDistribution* dist_; 261 BrowserDistribution* dist_;
183 base::FilePath chrome_exe_; 262 base::FilePath chrome_exe_;
184 scoped_ptr<installer::Product> product_; 263 scoped_ptr<installer::Product> product_;
185 scoped_ptr<installer::MasterPreferences> prefs_; 264 scoped_ptr<installer::MasterPreferences> prefs_;
186 265
187 base::ScopedTempDir temp_dir_; 266 base::ScopedTempDir temp_dir_;
188 base::ScopedTempDir fake_user_desktop_; 267 base::ScopedTempDir fake_user_desktop_;
189 base::ScopedTempDir fake_common_desktop_; 268 base::ScopedTempDir fake_common_desktop_;
190 base::ScopedTempDir fake_user_quick_launch_; 269 base::ScopedTempDir fake_user_quick_launch_;
191 base::ScopedTempDir fake_start_menu_; 270 base::ScopedTempDir fake_start_menu_;
192 base::ScopedTempDir fake_common_start_menu_; 271 base::ScopedTempDir fake_common_start_menu_;
193 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 272 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
194 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 273 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
195 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 274 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
196 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 275 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
197 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 276 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
198 277
199 base::FilePath user_desktop_shortcut_; 278 base::FilePath user_desktop_shortcut_;
200 base::FilePath user_quick_launch_shortcut_; 279 base::FilePath user_quick_launch_shortcut_;
201 base::FilePath user_start_menu_shortcut_; 280 base::FilePath user_start_menu_shortcut_;
202 base::FilePath user_start_menu_subdir_shortcut_; 281 base::FilePath user_start_menu_subdir_shortcut_;
203 base::FilePath system_desktop_shortcut_; 282 base::FilePath system_desktop_shortcut_;
204 base::FilePath system_start_menu_shortcut_; 283 base::FilePath system_start_menu_shortcut_;
205 base::FilePath system_start_menu_subdir_shortcut_; 284 base::FilePath system_start_menu_subdir_shortcut_;
206 }; 285 };
207 286
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 287 } // namespace
215 288
216 // Test that VisualElementsManifest.xml is not created when VisualElements are 289 // Test that VisualElementsManifest.xml is not created when VisualElements are
217 // not present. 290 // not present.
218 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { 291 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) {
219 ASSERT_TRUE( 292 ASSERT_TRUE(
220 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); 293 installer::CreateVisualElementsManifest(test_dir_.path(), version_));
221 ASSERT_FALSE(base::PathExists(manifest_path_)); 294 ASSERT_FALSE(base::PathExists(manifest_path_));
222 } 295 }
223 296
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 installer::CreateOrUpdateShortcuts( 532 installer::CreateOrUpdateShortcuts(
460 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 533 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
461 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 534 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
462 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); 535 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_));
463 base::win::ValidateShortcut(user_quick_launch_shortcut_, 536 base::win::ValidateShortcut(user_quick_launch_shortcut_,
464 expected_properties_); 537 expected_properties_);
465 base::win::ValidateShortcut(user_start_menu_shortcut_, 538 base::win::ValidateShortcut(user_start_menu_shortcut_,
466 expected_start_menu_properties_); 539 expected_start_menu_properties_);
467 } 540 }
468 541
469 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { 542 TEST_F(InstallShortcutTest, UpdatePerUserChromeUserLevelShortcuts) {
470 static const struct TestCase { 543 static const UpdateShortcutsTestCase kTestCases[] = {
471 const base::FilePath::CharType* relative_target_path; 544 // Shortcut target in the Chrome Canary install directory. No icon.
472 bool should_update; 545 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
473 } kTargetPathsToUpdate[] = {
474 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
475 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), 546 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
476 false}, 547 nullptr, false},
477 {FILE_PATH_LITERAL( 548 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
478 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), 549 "SxS\\Temp\\scoped_dir\\chrome.exe"),
479 false}, 550 nullptr, false},
480 {FILE_PATH_LITERAL( 551 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
481 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), 552 "SxS\\Application\\chrome.exe"),
482 false}, 553 nullptr, false},
483 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " 554 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
484 "SxS\\Application\\something_else.exe"), 555 "SxS\\Application\\something_else.exe"),
485 false}, 556 nullptr, false},
486 {FILE_PATH_LITERAL( 557
487 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), 558 // Shortcut target in the user-level Chrome install directory. No icon.
488 true}, 559 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
489 {FILE_PATH_LITERAL( 560 "d_dir\\new_chrome.exe"),
490 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), 561 nullptr, true},
491 true}, 562 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
492 {FILE_PATH_LITERAL( 563 "d_dir\\chrome.exe"),
493 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), 564 nullptr, true},
494 true}, 565 {FILE_PATH_LITERAL(
495 {FILE_PATH_LITERAL( 566 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
496 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), 567 nullptr, true},
497 false}, 568 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Application"
498 {FILE_PATH_LITERAL("something_else.exe"), false}, 569 "\\something_else.exe"),
570 nullptr, false},
571
572 // Shortcut target in the system-level Chrome install directory. No icon.
573 {FILE_PATH_LITERAL("Program Files "
574 "(x86)\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome."
575 "exe"),
576 nullptr, false},
577 {FILE_PATH_LITERAL(
578 "Program Files (x86)\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
579 nullptr, false},
580 {FILE_PATH_LITERAL(
581 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
582 nullptr, false},
583 {FILE_PATH_LITERAL("Program Files "
584 "(x86)\\Google\\Chrome\\Application\\something_else."
585 "exe"),
586 nullptr, false},
587
588 // Dummy shortcut target. Icon in the Chrome Canary install directory.
589 {FILE_PATH_LITERAL("dummy.exe"),
590 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
591 "SxS\\Application\\chrome.exe"),
592 false},
593 {FILE_PATH_LITERAL("dummy.exe"),
594 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
595 "SxS\\Application\\User Data\\Profile 1\\Google "
596 "Profile.ico"),
597 false},
598
599 // Dummy shortcut target. Icon in the user-level Chrome install directory.
600 {FILE_PATH_LITERAL("dummy.exe"),
601 FILE_PATH_LITERAL(
602 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
603 true},
604 {FILE_PATH_LITERAL("dummy.exe"),
605 FILE_PATH_LITERAL(
606 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\User "
607 "Data\\Profile 1\\Google Profile.ico"),
608 true},
609
610 // Dummy shortcut target. Icon in the system-level Chrome install
611 // directory.
612 {FILE_PATH_LITERAL("dummy.exe"),
613 FILE_PATH_LITERAL(
614 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
615 false},
616
617 // Shortcuts that don't belong to Chrome.
618 {FILE_PATH_LITERAL("something_else.exe"), nullptr, false},
619 {FILE_PATH_LITERAL("something_else.exe"),
620 FILE_PATH_LITERAL(
621 "Users\\x\\AppData\\Local\\Google\\Something Else.ico"),
622 false},
499 }; 623 };
500 624
501 // Create shortcuts. 625 TestUpdateShortcuts(
502 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { 626 kTestCases, arraysize(kTestCases),
503 const base::FilePath target_path = 627 base::FilePath(FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrom"
504 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); 628 "e\\Application\\chrome.exe")));
505 ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); 629 }
506 base::File file(target_path, base::File::FLAG_CREATE); 630
507 ASSERT_TRUE(file.IsValid()); 631 TEST_F(InstallShortcutTest, UpdatePerUserCanaryShortcuts) {
508 632 static const UpdateShortcutsTestCase kTestCases[] = {
509 base::win::ShortcutProperties properties; 633 // Shortcut target in the Chrome Canary install directory. No icon.
510 properties.set_target(target_path); 634 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
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 }
542
543 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) {
544 static const struct TestCase {
545 const base::FilePath::CharType* relative_target_path;
546 bool should_update;
547 } kTargetPathsToUpdate[] = {
548 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
549 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), 635 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
550 true}, 636 nullptr, true},
551 {FILE_PATH_LITERAL( 637 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
552 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), 638 "SxS\\Temp\\scoped_dir\\chrome.exe"),
553 true}, 639 nullptr, true},
554 {FILE_PATH_LITERAL( 640 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
555 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), 641 "SxS\\Application\\chrome.exe"),
556 true}, 642 nullptr, true},
557 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " 643 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
558 "SxS\\Application\\something_else.exe"), 644 "SxS\\Application\\something_else.exe"),
559 false}, 645 nullptr, false},
560 {FILE_PATH_LITERAL( 646
561 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"), 647 // Shortcut target in the user-level Chrome install directory. No icon.
562 false}, 648 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
563 {FILE_PATH_LITERAL( 649 "d_dir\\new_chrome.exe"),
564 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"), 650 nullptr, false},
565 false}, 651 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
566 {FILE_PATH_LITERAL( 652 "d_dir\\chrome.exe"),
567 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), 653 nullptr, false},
568 false}, 654 {FILE_PATH_LITERAL(
569 {FILE_PATH_LITERAL( 655 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
570 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"), 656 nullptr, false},
571 false}, 657 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Application"
572 {FILE_PATH_LITERAL("something_else.exe"), false}, 658 "\\something_else.exe"),
659 nullptr, false},
660
661 // Shortcut target in the system-level Chrome install directory. No icon.
662 {FILE_PATH_LITERAL("Program Files "
663 "(x86)\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome."
664 "exe"),
665 nullptr, false},
666 {FILE_PATH_LITERAL(
667 "Program Files (x86)\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
668 nullptr, false},
669 {FILE_PATH_LITERAL(
670 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
671 nullptr, false},
672 {FILE_PATH_LITERAL("Program Files "
673 "(x86)\\Google\\Chrome\\Application\\something_else."
674 "exe"),
675 nullptr, false},
676
677 // Dummy shortcut target. Icon in the Chrome Canary install directory.
678 {FILE_PATH_LITERAL("dummy.exe"),
679 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
680 "SxS\\Application\\chrome.exe"),
681 true},
682 {FILE_PATH_LITERAL("dummy.exe"),
683 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
684 "SxS\\Application\\User Data\\Profile 1\\Google "
685 "Profile.ico"),
686 true},
687
688 // Dummy shortcut target. Icon in the user-level Chrome install directory.
689 {FILE_PATH_LITERAL("dummy.exe"),
690 FILE_PATH_LITERAL(
691 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
692 false},
693 {FILE_PATH_LITERAL("dummy.exe"),
694 FILE_PATH_LITERAL(
695 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\User "
696 "Data\\Profile 1\\Google Profile.ico"),
697 false},
698
699 // Dummy shortcut target. Icon in the system-level Chrome install
700 // directory.
701 {FILE_PATH_LITERAL("dummy.exe"),
702 FILE_PATH_LITERAL(
703 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
704 false},
705
706 // Shortcuts that don't belong to Chrome.
707 {FILE_PATH_LITERAL("something_else.exe"), nullptr, false},
708 {FILE_PATH_LITERAL("something_else.exe"),
709 FILE_PATH_LITERAL(
710 "Users\\x\\AppData\\Local\\Google\\Something Else.ico"),
711 false},
573 }; 712 };
574 713
575 // Create shortcuts. 714 TestUpdateShortcuts(
576 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { 715 kTestCases, arraysize(kTestCases),
577 const base::FilePath target_path = 716 base::FilePath(FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrom"
578 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path); 717 "e SxS\\Application\\chrome.exe")));
579 ASSERT_TRUE(base::CreateDirectory(target_path.DirName())); 718 }
580 base::File file(target_path, base::File::FLAG_CREATE); 719
581 ASSERT_TRUE(file.IsValid()); 720 TEST_F(InstallShortcutTest, UpdatePerUserChromeSystemLevelShortcuts) {
582 721 static const UpdateShortcutsTestCase kTestCases[] = {
583 base::win::ShortcutProperties properties; 722 // Shortcut target in the Chrome Canary install directory. No icon.
584 properties.set_target(target_path); 723 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
585 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 724 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
586 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), 725 nullptr, false},
587 properties, base::win::SHORTCUT_CREATE_ALWAYS)); 726 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
588 } 727 "SxS\\Temp\\scoped_dir\\chrome.exe"),
589 728 nullptr, false},
590 // Update shortcuts. 729 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
591 const base::FilePath new_target_path = 730 "SxS\\Application\\chrome.exe"),
592 temp_dir_.path().Append(FILE_PATH_LITERAL( 731 nullptr, false},
593 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe")); 732 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
594 installer::UpdatePerUserShortcutsInLocation( 733 "SxS\\Application\\something_else.exe"),
595 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 734 nullptr, false},
596 new_target_path.DirName().DirName(), new_target_path.BaseName(), 735
597 new_target_path); 736 // Shortcut target in the user-level Chrome install directory. No icon.
598 737 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
599 // Verify that shortcuts were updated correctly. 738 "d_dir\\new_chrome.exe"),
600 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) { 739 nullptr, false},
601 base::FilePath target_path; 740 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Temp\\scope"
602 ASSERT_TRUE(base::win::ResolveShortcut( 741 "d_dir\\chrome.exe"),
603 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), 742 nullptr, false},
604 &target_path, nullptr)); 743 {FILE_PATH_LITERAL(
605 744 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
606 if (kTargetPathsToUpdate[i].should_update) { 745 nullptr, false},
607 EXPECT_EQ(GetNormalizedFilePath(new_target_path), 746 {FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome\\Application"
608 GetNormalizedFilePath(target_path)); 747 "\\something_else.exe"),
609 } else { 748 nullptr, false},
610 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append( 749
611 kTargetPathsToUpdate[i].relative_target_path)), 750 // Shortcut target in the system-level Chrome install directory. No icon.
612 GetNormalizedFilePath(target_path)); 751 {FILE_PATH_LITERAL("Program Files "
613 } 752 "(x86)\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome."
614 } 753 "exe"),
754 nullptr, true},
755 {FILE_PATH_LITERAL(
756 "Program Files (x86)\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
757 nullptr, true},
758 {FILE_PATH_LITERAL(
759 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
760 nullptr, true},
761 {FILE_PATH_LITERAL("Program Files "
762 "(x86)\\Google\\Chrome\\Application\\something_else."
763 "exe"),
764 nullptr, false},
765
766 // Dummy shortcut target. Icon in the Chrome Canary install directory.
767 {FILE_PATH_LITERAL("dummy.exe"),
768 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
769 "SxS\\Application\\chrome.exe"),
770 false},
771 {FILE_PATH_LITERAL("dummy.exe"),
772 FILE_PATH_LITERAL("Users\\x\\AppData\\Local\\Google\\Chrome "
773 "SxS\\Application\\User Data\\Profile 1\\Google "
774 "Profile.ico"),
775 false},
776
777 // Dummy shortcut target. Icon in the user-level Chrome install directory.
778 {FILE_PATH_LITERAL("dummy.exe"),
779 FILE_PATH_LITERAL(
780 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
781 false},
782 {FILE_PATH_LITERAL("dummy.exe"),
783 FILE_PATH_LITERAL(
784 "Users\\x\\AppData\\Local\\Google\\Chrome\\Application\\User "
785 "Data\\Profile 1\\Google Profile.ico"),
786 false},
787
788 // Dummy shortcut target. Icon in the system-level Chrome install
789 // directory.
790 {FILE_PATH_LITERAL("dummy.exe"),
791 FILE_PATH_LITERAL(
792 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"),
793 true},
794
795 // Shortcuts that don't belong to Chrome.
796 {FILE_PATH_LITERAL("something_else.exe"), nullptr, false},
797 {FILE_PATH_LITERAL("something_else.exe"),
798 FILE_PATH_LITERAL(
799 "Users\\x\\AppData\\Local\\Google\\Something Else.ico"),
800 false},
801 };
802
803 TestUpdateShortcuts(
804 kTestCases, arraysize(kTestCases),
805 base::FilePath(FILE_PATH_LITERAL(
806 "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")));
615 } 807 }
616 808
617 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { 809 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) {
618 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); 810 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs.");
619 static const wchar_t kExpectedEscapedVal[] = 811 static const wchar_t kExpectedEscapedVal[] =
620 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs."; 812 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs.";
621 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 813 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
622 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 814 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
623 } 815 }
624 816
625 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 817 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
626 base::string16 val(L"Google Chrome"); 818 base::string16 val(L"Google Chrome");
627 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 819 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
628 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 820 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
629 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 821 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
630 } 822 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698