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

Side by Side Diff: chrome/installer/util/shell_util_unittest.cc

Issue 108193019: Installer: adding ResolveShortcutProperties(); updating shortcut icons during shortcut migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing path comparison in ShortcutTest. Created 6 years, 11 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 | Annotate | Revision Log
« base/win/shortcut.cc ('K') | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/installer/util/shell_util.h" 5 #include "chrome/installer/util/shell_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/base_paths_win.h" 10 #include "base/base_paths_win.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/md5.h" 14 #include "base/md5.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/test/scoped_path_override.h" 18 #include "base/test/scoped_path_override.h"
19 #include "base/test/test_shortcut_win.h" 19 #include "base/test/test_shortcut_win.h"
20 #include "base/win/shortcut.h" 20 #include "base/win/shortcut.h"
21 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
22 #include "chrome/installer/util/browser_distribution.h" 22 #include "chrome/installer/util/browser_distribution.h"
23 #include "chrome/installer/util/product.h" 23 #include "chrome/installer/util/product.h"
24 #include "chrome/installer/util/util_constants.h" 24 #include "chrome/installer/util/util_constants.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 namespace { 27 namespace {
28 28
29 const wchar_t kManganeseExe[] = L"manganese.exe"; 29 const wchar_t kManganeseExe[] = L"manganese.exe";
30 const wchar_t kIronExe[] = L"iron.exe";
31 const wchar_t kOtherIco[] = L"other.ico";
30 32
31 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific 33 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific
32 // tests. Specifically, we should not overly rely on getting shortcut properties 34 // tests. Specifically, we should not overly rely on getting shortcut properties
33 // from product_->AddDefaultShortcutProperties(). 35 // from product_->AddDefaultShortcutProperties().
34 class ShellUtilShortcutTest : public testing::Test { 36 class ShellUtilShortcutTest : public testing::Test {
35 protected: 37 protected:
36 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {} 38 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {}
37 39
38 virtual void SetUp() OVERRIDE { 40 virtual void SetUp() OVERRIDE {
39 dist_ = BrowserDistribution::GetDistribution(); 41 dist_ = BrowserDistribution::GetDistribution();
40 ASSERT_TRUE(dist_ != NULL); 42 ASSERT_TRUE(dist_ != NULL);
41 product_.reset(new installer::Product(dist_)); 43 product_.reset(new installer::Product(dist_));
42 44
43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
44 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); 46 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe);
45 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0)); 47 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0));
46 48
47 manganese_exe_ = temp_dir_.path().Append(kManganeseExe); 49 manganese_exe_ = temp_dir_.path().Append(kManganeseExe);
48 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0)); 50 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0));
49 51
52 iron_exe_ = temp_dir_.path().Append(kIronExe);
53 EXPECT_EQ(0, file_util::WriteFile(iron_exe_, "", 0));
54
55 other_ico_ = temp_dir_.path().Append(kOtherIco);
56 EXPECT_EQ(0, file_util::WriteFile(other_ico_, "", 0));
57
50 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); 58 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir());
51 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); 59 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir());
52 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir()); 60 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir());
53 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir()); 61 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir());
54 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir()); 62 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir());
55 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); 63 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir());
56 user_desktop_override_.reset( 64 user_desktop_override_.reset(
57 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, 65 new base::ScopedPathOverride(base::DIR_USER_DESKTOP,
58 fake_user_desktop_.path())); 66 fake_user_desktop_.path()));
59 common_desktop_override_.reset( 67 common_desktop_override_.reset(
(...skipping 10 matching lines...) Expand all
70 fake_start_menu_.path())); 78 fake_start_menu_.path()));
71 common_start_menu_override_.reset( 79 common_start_menu_override_.reset(
72 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, 80 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU,
73 fake_common_start_menu_.path())); 81 fake_common_start_menu_.path()));
74 82
75 base::FilePath icon_path; 83 base::FilePath icon_path;
76 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); 84 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path);
77 test_properties_.set_target(chrome_exe_); 85 test_properties_.set_target(chrome_exe_);
78 test_properties_.set_arguments(L"--test --chrome"); 86 test_properties_.set_arguments(L"--test --chrome");
79 test_properties_.set_description(L"Makes polar bears dance."); 87 test_properties_.set_description(L"Makes polar bears dance.");
80 test_properties_.set_icon(icon_path, 0); 88 test_properties_.set_icon(icon_path, 7);
81 test_properties_.set_app_id(L"Polar.Bear"); 89 test_properties_.set_app_id(L"Polar.Bear");
82 test_properties_.set_dual_mode(true); 90 test_properties_.set_dual_mode(true);
83 } 91 }
84 92
85 // Validates that the shortcut at |location| matches |properties| (and 93 // Returns the expected path of a test shortcut. Returns an empty FilePath on
86 // implicit default properties) for |dist|. 94 // failure.
87 // Note: This method doesn't verify the |pin_to_taskbar| property as it 95 base::FilePath GetExpectedShortcutPath(
88 // implies real (non-mocked) state which is flaky to test.
89 void ValidateChromeShortcut(
90 ShellUtil::ShortcutLocation location, 96 ShellUtil::ShortcutLocation location,
91 BrowserDistribution* dist, 97 BrowserDistribution* dist,
92 const ShellUtil::ShortcutProperties& properties) { 98 const ShellUtil::ShortcutProperties& properties) {
93 base::FilePath expected_path; 99 base::FilePath expected_path;
94 switch (location) { 100 switch (location) {
95 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 101 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
96 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 102 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
97 fake_user_desktop_.path() : fake_common_desktop_.path(); 103 fake_user_desktop_.path() : fake_common_desktop_.path();
98 break; 104 break;
99 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 105 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 106 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
101 fake_user_quick_launch_.path() : 107 fake_user_quick_launch_.path() :
102 fake_default_user_quick_launch_.path(); 108 fake_default_user_quick_launch_.path();
103 break; 109 break;
104 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: 110 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
105 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 111 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
106 fake_start_menu_.path() : fake_common_start_menu_.path(); 112 fake_start_menu_.path() : fake_common_start_menu_.path();
107 expected_path = expected_path.Append( 113 expected_path = expected_path.Append(
108 dist_->GetStartMenuShortcutSubfolder( 114 dist_->GetStartMenuShortcutSubfolder(
109 BrowserDistribution::SUBFOLDER_CHROME)); 115 BrowserDistribution::SUBFOLDER_CHROME));
110 break; 116 break;
111 default: 117 default:
112 ADD_FAILURE() << "Unknown location"; 118 ADD_FAILURE() << "Unknown location";
113 return; 119 return base::FilePath();
114 } 120 }
115 121
116 base::string16 shortcut_name; 122 base::string16 shortcut_name = properties.has_shortcut_name() ?
117 if (properties.has_shortcut_name()) { 123 properties.shortcut_name :
118 shortcut_name = properties.shortcut_name; 124 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
119 } else {
120 shortcut_name =
121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
122 }
123 shortcut_name.append(installer::kLnkExt); 125 shortcut_name.append(installer::kLnkExt);
124 expected_path = expected_path.Append(shortcut_name); 126 return expected_path.Append(shortcut_name);
127 }
128
129 // Validates that the shortcut at |location| matches |properties| (and
130 // implicit default properties) for |dist|.
131 // Note: This method doesn't verify the |pin_to_taskbar| property as it
132 // implies real (non-mocked) state which is flaky to test.
133 void ValidateChromeShortcut(
134 ShellUtil::ShortcutLocation location,
135 BrowserDistribution* dist,
136 const ShellUtil::ShortcutProperties& properties) {
137 base::FilePath expected_path(
138 GetExpectedShortcutPath(location, dist, properties));
125 139
126 base::win::ShortcutProperties expected_properties; 140 base::win::ShortcutProperties expected_properties;
127 if (properties.has_target()) { 141 if (properties.has_target()) {
128 expected_properties.set_target(properties.target); 142 expected_properties.set_target(properties.target);
129 expected_properties.set_working_dir(properties.target.DirName()); 143 expected_properties.set_working_dir(properties.target.DirName());
130 } else { 144 } else {
131 expected_properties.set_target(chrome_exe_); 145 expected_properties.set_target(chrome_exe_);
132 expected_properties.set_working_dir(chrome_exe_.DirName()); 146 expected_properties.set_working_dir(chrome_exe_.DirName());
133 } 147 }
134 148
135 if (properties.has_arguments()) 149 if (properties.has_arguments())
136 expected_properties.set_arguments(properties.arguments); 150 expected_properties.set_arguments(properties.arguments);
137 else 151 else
138 expected_properties.set_arguments(base::string16()); 152 expected_properties.set_arguments(base::string16());
139 153
140 if (properties.has_description()) 154 if (properties.has_description())
141 expected_properties.set_description(properties.description); 155 expected_properties.set_description(properties.description);
142 else 156 else
143 expected_properties.set_description(dist->GetAppDescription()); 157 expected_properties.set_description(dist->GetAppDescription());
144 158
145 if (properties.has_icon()) { 159 if (properties.has_icon()) {
146 expected_properties.set_icon(properties.icon, 0); 160 expected_properties.set_icon(properties.icon, properties.icon_index);
147 } else { 161 } else {
148 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); 162 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME);
149 expected_properties.set_icon(chrome_exe_, icon_index); 163 expected_properties.set_icon(chrome_exe_, icon_index);
150 } 164 }
151 165
152 if (properties.has_app_id()) { 166 if (properties.has_app_id()) {
153 expected_properties.set_app_id(properties.app_id); 167 expected_properties.set_app_id(properties.app_id);
154 } else { 168 } else {
155 // Tests are always seen as user-level installs in ShellUtil. 169 // Tests are always seen as user-level installs in ShellUtil.
156 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); 170 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true));
(...skipping 22 matching lines...) Expand all
179 base::ScopedTempDir fake_common_start_menu_; 193 base::ScopedTempDir fake_common_start_menu_;
180 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 194 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
181 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 195 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
182 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 196 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
183 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; 197 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_;
184 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 198 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
185 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 199 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
186 200
187 base::FilePath chrome_exe_; 201 base::FilePath chrome_exe_;
188 base::FilePath manganese_exe_; 202 base::FilePath manganese_exe_;
203 base::FilePath iron_exe_;
204 base::FilePath other_ico_;
189 }; 205 };
190 206
191 } // namespace 207 } // namespace
192 208
193 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { 209 TEST_F(ShellUtilShortcutTest, GetShortcutPath) {
194 base::FilePath path; 210 base::FilePath path;
195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 211 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
196 ShellUtil::CURRENT_USER, &path); 212 ShellUtil::CURRENT_USER, &path);
197 EXPECT_EQ(fake_user_desktop_.path(), path); 213 EXPECT_EQ(fake_user_desktop_.path(), path);
198 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 214 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 377 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
362 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 378 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
363 ASSERT_TRUE(base::PathExists( 379 ASSERT_TRUE(base::PathExists(
364 fake_user_desktop_.path().Append(shortcut_name))); 380 fake_user_desktop_.path().Append(shortcut_name)));
365 } 381 }
366 382
367 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { 383 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 384 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 385 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
370 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 386 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
371 387 base::FilePath shortcut_path = GetExpectedShortcutPath(
372 base::string16 shortcut_name( 388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
373 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
374 installer::kLnkExt);
375 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
376 ASSERT_TRUE(base::PathExists(shortcut_path)); 389 ASSERT_TRUE(base::PathExists(shortcut_path));
377 390
378 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 391 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 392 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
380 chrome_exe_)); 393 chrome_exe_));
381 ASSERT_FALSE(base::PathExists(shortcut_path)); 394 ASSERT_FALSE(base::PathExists(shortcut_path));
382 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); 395 ASSERT_TRUE(base::PathExists(shortcut_path.DirName()));
383 } 396 }
384 397
385 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { 398 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) {
386 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 399 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 400 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 401 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
389 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 402 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
390 403 base::FilePath shortcut_path = GetExpectedShortcutPath(
391 base::string16 shortcut_name( 404 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
392 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
393 installer::kLnkExt);
394 base::FilePath shortcut_path(
395 fake_common_desktop_.path().Append(shortcut_name));
396 ASSERT_TRUE(base::PathExists(shortcut_path)); 405 ASSERT_TRUE(base::PathExists(shortcut_path));
397 406
398 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 407 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
399 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 408 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
400 chrome_exe_)); 409 chrome_exe_));
401 ASSERT_FALSE(base::PathExists(shortcut_path)); 410 ASSERT_FALSE(base::PathExists(shortcut_path));
402 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); 411 ASSERT_TRUE(base::PathExists(shortcut_path.DirName()));
403 } 412 }
404 413
405 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { 414 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) {
406 const wchar_t kShortcutName1[] = L"Chrome 1"; 415 // Shortcut 1: targets "chrome.exe"; no arguments.
407 const wchar_t kShortcutName2[] = L"Chrome 2"; 416 test_properties_.set_shortcut_name(L"Chrome 1");
408 417 test_properties_.set_arguments(L"");
409 test_properties_.set_shortcut_name(kShortcutName1);
410 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 418 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 419 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 420 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
413 base::string16 shortcut1_name( 421 base::FilePath shortcut1_path = GetExpectedShortcutPath(
414 base::string16(kShortcutName1).append(installer::kLnkExt)); 422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
415 base::FilePath shortcut1_path(
416 fake_user_desktop_.path().Append(shortcut1_name));
417 ASSERT_TRUE(base::PathExists(shortcut1_path)); 423 ASSERT_TRUE(base::PathExists(shortcut1_path));
418 424
419 test_properties_.set_shortcut_name(kShortcutName2); 425 // Shortcut 2: targets "chrome.exe"; has arguments; icon set to "other.ico".
426 test_properties_.set_shortcut_name(L"Chrome 2");
420 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); 427 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
428 test_properties_.set_icon(other_ico_, 0);
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 429 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
423 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 431 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
424 base::string16 shortcut2_name( 432 base::FilePath shortcut2_path = GetExpectedShortcutPath(
425 base::string16(kShortcutName2).append(installer::kLnkExt)); 433 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
426 base::FilePath shortcut2_path(
427 fake_user_desktop_.path().Append(shortcut2_name));
428 ASSERT_TRUE(base::PathExists(shortcut2_path)); 434 ASSERT_TRUE(base::PathExists(shortcut2_path));
429 435
436 // Shortcut 3: targets "iron.exe"; has arguments; icon set to "chrome.exe".
437 test_properties_.set_shortcut_name(L"Iron 3");
438 test_properties_.set_target(iron_exe_);
439 test_properties_.set_icon(chrome_exe_, 3);
440 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
441 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
442 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
443 base::FilePath shortcut3_path = GetExpectedShortcutPath(
444 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
445 ASSERT_TRUE(base::PathExists(shortcut3_path));
446
447 // Remove shortcuts that target "chrome.exe".
430 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 448 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
431 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 449 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
432 chrome_exe_)); 450 chrome_exe_));
433 ASSERT_FALSE(base::PathExists(shortcut1_path)); 451 ASSERT_FALSE(base::PathExists(shortcut1_path));
434 ASSERT_FALSE(base::PathExists(shortcut2_path)); 452 ASSERT_FALSE(base::PathExists(shortcut2_path));
453 ASSERT_TRUE(base::PathExists(shortcut3_path));
435 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); 454 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName()));
436 } 455 }
437 456
438 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) { 457 TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) {
439 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 458 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
440 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 459 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
441 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 460 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
461 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
462 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
442 463
443 base::string16 shortcut_name( 464 base::FilePath new_exe = manganese_exe_;
444 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 465 // Relies on the fact that |test_properties_| has non-empty arguments.
445 installer::kLnkExt); 466 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
446 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
447 ASSERT_TRUE(base::PathExists(shortcut_path));
448
449 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
450 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
451 updated_properties.set_target(new_exe);
452 // |updated_properties| has arguments.
453 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
454 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 467 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
455 chrome_exe_, updated_properties)); 468 chrome_exe_, new_exe));
456 469
457 ShellUtil::ShortcutProperties expected_properties(test_properties_); 470 ShellUtil::ShortcutProperties expected_properties(test_properties_);
458 expected_properties.set_target(new_exe); 471 expected_properties.set_target(new_exe);
459 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 472 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
460 expected_properties); 473 expected_properties);
461 } 474 }
462 475
463 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) { 476 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) {
464 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 477 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
465 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 478 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
466 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 479 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
467 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 480 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
481 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
482 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
468 483
469 base::string16 shortcut_name( 484 base::FilePath new_exe = manganese_exe_;
470 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 485 // Relies on the fact that |test_properties_| has non-empty arguments.
471 installer::kLnkExt); 486 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
472 base::FilePath shortcut_path(
473 fake_common_desktop_.path().Append(shortcut_name));
474 ASSERT_TRUE(base::PathExists(shortcut_path));
475
476 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
477 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
478 updated_properties.set_target(new_exe);
479 // |updated_properties| has arguments.
480 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
481 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 487 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
482 chrome_exe_, updated_properties)); 488 chrome_exe_, new_exe));
483 489
484 ShellUtil::ShortcutProperties expected_properties(test_properties_); 490 ShellUtil::ShortcutProperties expected_properties(test_properties_);
485 expected_properties.set_target(new_exe); 491 expected_properties.set_target(new_exe);
486 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 492 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
487 expected_properties); 493 expected_properties);
488 } 494 }
489 495
490 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) { 496 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) {
491 const wchar_t kShortcutName1[] = L"Chrome 1"; 497 // Shortcut 1: targets "chrome.exe"; no arguments.
492 const wchar_t kShortcutName2[] = L"Chrome 2"; 498 test_properties_.set_shortcut_name(L"Chrome 1");
493
494 // Setup shortcut 1, which has empty arguments.
495 test_properties_.set_shortcut_name(kShortcutName1);
496 test_properties_.set_arguments(L""); 499 test_properties_.set_arguments(L"");
497 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 500 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
498 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 501 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
499 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 502 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
500 base::string16 shortcut1_name( 503 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
501 base::string16(kShortcutName1).append(installer::kLnkExt)); 504 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
502 base::FilePath shortcut1_path(
503 fake_user_desktop_.path().Append(shortcut1_name));
504 ShellUtil::ShortcutProperties expected_properties1(test_properties_); 505 ShellUtil::ShortcutProperties expected_properties1(test_properties_);
505 506
506 // Setup shortcut 2, which has non-empty arguments. 507 // Shortcut 2: targets "chrome.exe"; has arguments.
507 base::string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; 508 test_properties_.set_shortcut_name(L"Chrome 2");
508 test_properties_.set_shortcut_name(kShortcutName2); 509 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
509 test_properties_.set_arguments(shortcut2_args);
510 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 510 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
511 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 511 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
512 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 512 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
513 base::string16 shortcut2_name( 513 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
514 base::string16(kShortcutName2).append(installer::kLnkExt)); 514 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
515 base::FilePath shortcut2_path(
516 fake_user_desktop_.path().Append(shortcut2_name));
517 ASSERT_TRUE(base::PathExists(shortcut2_path));
518 ShellUtil::ShortcutProperties expected_properties2(test_properties_); 515 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
519 516
520 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". 517 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only
521 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 518 // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated.
522 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 519 base::FilePath new_exe = manganese_exe_;
523 updated_properties.set_target(new_exe); 520 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
521 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
522 chrome_exe_, new_exe));
524 523
525 // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2. 524 // Verify shortcut 1: no change.
526 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
527 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
528 chrome_exe_, updated_properties));
529 // Verify shortcut 1.
530 // |expected_properties1| was unchanged and still targets "chrome.exe", since
531 // it has empty target, yet we passed |require_args| = true.
532 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 525 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
533 expected_properties1); 526 expected_properties1);
534 // Verify shortcut 2. 527
528 // Verify shortcut 2: target => "manganese.exe".
535 expected_properties2.set_target(new_exe); 529 expected_properties2.set_target(new_exe);
536 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 530 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
537 expected_properties2); 531 expected_properties2);
538 } 532 }
539 533
534 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) {
535 const int kTestIconIndex1 = 3;
536 const int kTestIconIndex2 = 5;
537 const int kTestIconIndex3 = 8;
538
539 // Shortcut 1: targets "chrome.exe"; icon same as target.
540 test_properties_.set_shortcut_name(L"Chrome 1");
541 test_properties_.set_icon(test_properties_.target, kTestIconIndex1);
542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
543 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
544 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
545 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
546 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
547 ShellUtil::ShortcutProperties expected_properties1(test_properties_);
548
549 // Shortcut 2: targets "chrome.exe"; icon set to "other.ico".
550 test_properties_.set_shortcut_name(L"Chrome 2");
551 test_properties_.set_icon(other_ico_, kTestIconIndex2);
552 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
553 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
554 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
555 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
556 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
557 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
558
559 // Shortcut 3: targets "iron.exe"; icon set to "chrome.exe".
560 test_properties_.set_target(iron_exe_);
561 test_properties_.set_shortcut_name(L"Iron 3");
562 test_properties_.set_icon(chrome_exe_, kTestIconIndex3);
563 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
564 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
565 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
566 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
567 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
568 ShellUtil::ShortcutProperties expected_properties3(test_properties_);
569
570 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe".
571 // Relies on the fact that |test_properties_| has non-empty arguments.
572 base::FilePath new_exe = manganese_exe_;
573 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
574 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
575 chrome_exe_, new_exe));
576
577 // Verify shortcut 1: target & icon => "manganese.exe", kept same icon index.
578 expected_properties1.set_target(new_exe);
579 expected_properties1.set_icon(new_exe, kTestIconIndex1);
580 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
581 expected_properties1);
582
583 // Verify shortcut 2: target => "manganese.exe", kept icon.
584 expected_properties2.set_target(new_exe);
585 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
586 expected_properties2);
587
588 // Verify shortcut 3: no change, since target doesn't match.
589 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
590 expected_properties3);
591 }
592
540 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 593 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
541 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 594 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
542 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 595 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
543 dist_, test_properties_, 596 dist_, test_properties_,
544 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 597 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
545 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 598 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
546 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 599 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
547 dist_, test_properties_, 600 dist_, test_properties_,
548 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 601 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
549 test_properties_.set_shortcut_name(L"A second shortcut"); 602 test_properties_.set_shortcut_name(L"A second shortcut");
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 770
718 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 771 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
719 L"MZXW6YTB", L"MZXW6YTBOI"}; 772 L"MZXW6YTB", L"MZXW6YTBOI"};
720 773
721 // Run the tests, with one more letter in the input every pass. 774 // Run the tests, with one more letter in the input every pass.
722 for (int i = 0; i < arraysize(expected); ++i) { 775 for (int i = 0; i < arraysize(expected); ++i) {
723 ASSERT_EQ(expected[i], 776 ASSERT_EQ(expected[i],
724 ShellUtil::ByteArrayToBase32(test_array, i)); 777 ShellUtil::ByteArrayToBase32(test_array, i));
725 } 778 }
726 } 779 }
OLDNEW
« base/win/shortcut.cc ('K') | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698