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

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: Nits; fixing test comments and coverage. 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
« no previous file with comments | « 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 string16 shortcut_name; 122 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(string16()); 152 expected_properties.set_arguments(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 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 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 string16 shortcut1_name( 421 base::FilePath shortcut1_path = GetExpectedShortcutPath(
414 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 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); 432 base::FilePath shortcut2_path = GetExpectedShortcutPath(
425 base::FilePath shortcut2_path( 433 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
426 fake_user_desktop_.path().Append(shortcut2_name));
427 ASSERT_TRUE(base::PathExists(shortcut2_path)); 434 ASSERT_TRUE(base::PathExists(shortcut2_path));
428 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".
429 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 448 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 449 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
431 chrome_exe_)); 450 chrome_exe_));
432 ASSERT_FALSE(base::PathExists(shortcut1_path)); 451 ASSERT_FALSE(base::PathExists(shortcut1_path));
433 ASSERT_FALSE(base::PathExists(shortcut2_path)); 452 ASSERT_FALSE(base::PathExists(shortcut2_path));
453 ASSERT_TRUE(base::PathExists(shortcut3_path));
434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); 454 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName()));
435 } 455 }
436 456
437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) { 457 TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) {
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 458 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 459 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
440 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_)));
441 463
442 string16 shortcut_name( 464 base::FilePath new_exe = manganese_exe_;
443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 465 // Relies on the fact that |test_properties_| has non-empty arguments.
444 installer::kLnkExt); 466 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
446 ASSERT_TRUE(base::PathExists(shortcut_path));
447
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
450 updated_properties.set_target(new_exe);
451 // |updated_properties| has arguments.
452 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 467 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
454 chrome_exe_, updated_properties)); 468 chrome_exe_, new_exe));
455 469
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); 470 ShellUtil::ShortcutProperties expected_properties(test_properties_);
457 expected_properties.set_target(new_exe); 471 expected_properties.set_target(new_exe);
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 472 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
459 expected_properties); 473 expected_properties);
460 } 474 }
461 475
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) { 476 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) {
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 477 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 478 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 479 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
466 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_)));
467 483
468 string16 shortcut_name( 484 base::FilePath new_exe = manganese_exe_;
469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 485 // Relies on the fact that |test_properties_| has non-empty arguments.
470 installer::kLnkExt); 486 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
471 base::FilePath shortcut_path(
472 fake_common_desktop_.path().Append(shortcut_name));
473 ASSERT_TRUE(base::PathExists(shortcut_path));
474
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
477 updated_properties.set_target(new_exe);
478 // |updated_properties| has arguments.
479 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 487 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
481 chrome_exe_, updated_properties)); 488 chrome_exe_, new_exe));
482 489
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); 490 ShellUtil::ShortcutProperties expected_properties(test_properties_);
484 expected_properties.set_target(new_exe); 491 expected_properties.set_target(new_exe);
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 492 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
486 expected_properties); 493 expected_properties);
487 } 494 }
488 495
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) { 496 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) {
490 const wchar_t kShortcutName1[] = L"Chrome 1"; 497 // Shortcut 1: targets "chrome.exe"; no arguments.
491 const wchar_t kShortcutName2[] = L"Chrome 2"; 498 test_properties_.set_shortcut_name(L"Chrome 1");
492
493 // Setup shortcut 1, which has empty arguments.
494 test_properties_.set_shortcut_name(kShortcutName1);
495 test_properties_.set_arguments(L""); 499 test_properties_.set_arguments(L"");
496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 500 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 501 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 502 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); 503 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
500 base::FilePath shortcut1_path( 504 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
501 fake_user_desktop_.path().Append(shortcut1_name));
502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); 505 ShellUtil::ShortcutProperties expected_properties1(test_properties_);
503 506
504 // Setup shortcut 2, which has non-empty arguments. 507 // Shortcut 2: targets "chrome.exe"; has arguments.
505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; 508 test_properties_.set_shortcut_name(L"Chrome 2");
506 test_properties_.set_shortcut_name(kShortcutName2); 509 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
507 test_properties_.set_arguments(shortcut2_args);
508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 510 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 511 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 512 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); 513 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
512 base::FilePath shortcut2_path( 514 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
513 fake_user_desktop_.path().Append(shortcut2_name));
514 ASSERT_TRUE(base::PathExists(shortcut2_path));
515 ShellUtil::ShortcutProperties expected_properties2(test_properties_); 515 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
516 516
517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". 517 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 518 // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated.
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 519 base::FilePath new_exe = manganese_exe_;
520 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));
521 523
522 // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2. 524 // Verify shortcut 1: no change.
523 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
524 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
525 chrome_exe_, updated_properties));
526 // Verify shortcut 1.
527 // |expected_properties1| was unchanged and still targets "chrome.exe", since
528 // it has empty target, yet we passed |require_args| = true.
529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 525 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
530 expected_properties1); 526 expected_properties1);
531 // Verify shortcut 2. 527
528 // Verify shortcut 2: target => "manganese.exe".
532 expected_properties2.set_target(new_exe); 529 expected_properties2.set_target(new_exe);
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 530 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
534 expected_properties2); 531 expected_properties2);
535 } 532 }
536 533
534 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) {
535 const int kTest1IconIndex = 3;
gab 2014/01/03 21:01:13 nit: name these kTestIconIndexX instead of kTestXI
huangs 2014/01/03 22:30:38 Done.
536 const int kTest2IconIndex = 5;
537 const int kTest3IconIndex = 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, kTest1IconIndex);
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_, kTest2IconIndex);
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_, kTest3IconIndex);
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, kTest1IconIndex);
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
537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 593 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 594 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 595 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
540 dist_, test_properties_, 596 dist_, test_properties_,
541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 597 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 598 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 599 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
544 dist_, test_properties_, 600 dist_, test_properties_,
545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 601 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
546 test_properties_.set_shortcut_name(L"A second shortcut"); 602 test_properties_.set_shortcut_name(L"A second shortcut");
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 769
714 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 770 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
715 L"MZXW6YTB", L"MZXW6YTBOI"}; 771 L"MZXW6YTB", L"MZXW6YTBOI"};
716 772
717 // Run the tests, with one more letter in the input every pass. 773 // Run the tests, with one more letter in the input every pass.
718 for (int i = 0; i < arraysize(expected); ++i) { 774 for (int i = 0; i < arraysize(expected); ++i) {
719 ASSERT_EQ(expected[i], 775 ASSERT_EQ(expected[i],
720 ShellUtil::ByteArrayToBase32(test_array, i)); 776 ShellUtil::ByteArrayToBase32(test_array, i));
721 } 777 }
722 } 778 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698