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

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

Powered by Google App Engine
This is Rietveld 408576698