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

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: Removing helper CreateTestDesktopShortcut() in shell_util_unittest.cc; inlining instead. 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
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 kOtherIco[] = L"other.ico";
30 31
31 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific 32 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific
32 // tests. Specifically, we should not overly rely on getting shortcut properties 33 // tests. Specifically, we should not overly rely on getting shortcut properties
33 // from product_->AddDefaultShortcutProperties(). 34 // from product_->AddDefaultShortcutProperties().
34 class ShellUtilShortcutTest : public testing::Test { 35 class ShellUtilShortcutTest : public testing::Test {
35 protected: 36 protected:
36 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {} 37 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {}
37 38
38 virtual void SetUp() OVERRIDE { 39 virtual void SetUp() OVERRIDE {
39 dist_ = BrowserDistribution::GetDistribution(); 40 dist_ = BrowserDistribution::GetDistribution();
40 ASSERT_TRUE(dist_ != NULL); 41 ASSERT_TRUE(dist_ != NULL);
41 product_.reset(new installer::Product(dist_)); 42 product_.reset(new installer::Product(dist_));
42 43
43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
44 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); 45 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe);
45 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0)); 46 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0));
46 47
47 manganese_exe_ = temp_dir_.path().Append(kManganeseExe); 48 manganese_exe_ = temp_dir_.path().Append(kManganeseExe);
48 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0)); 49 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0));
49 50
51 other_ico_ = temp_dir_.path().Append(kOtherIco);
52 EXPECT_EQ(0, file_util::WriteFile(other_ico_, "", 0));
53
50 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); 54 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir());
51 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); 55 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir());
52 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir()); 56 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir());
53 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir()); 57 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir());
54 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir()); 58 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir());
55 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); 59 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir());
56 user_desktop_override_.reset( 60 user_desktop_override_.reset(
57 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, 61 new base::ScopedPathOverride(base::DIR_USER_DESKTOP,
58 fake_user_desktop_.path())); 62 fake_user_desktop_.path()));
59 common_desktop_override_.reset( 63 common_desktop_override_.reset(
(...skipping 10 matching lines...) Expand all
70 fake_start_menu_.path())); 74 fake_start_menu_.path()));
71 common_start_menu_override_.reset( 75 common_start_menu_override_.reset(
72 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, 76 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU,
73 fake_common_start_menu_.path())); 77 fake_common_start_menu_.path()));
74 78
75 base::FilePath icon_path; 79 base::FilePath icon_path;
76 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); 80 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path);
77 test_properties_.set_target(chrome_exe_); 81 test_properties_.set_target(chrome_exe_);
78 test_properties_.set_arguments(L"--test --chrome"); 82 test_properties_.set_arguments(L"--test --chrome");
79 test_properties_.set_description(L"Makes polar bears dance."); 83 test_properties_.set_description(L"Makes polar bears dance.");
80 test_properties_.set_icon(icon_path, 0); 84 test_properties_.set_icon(icon_path, 0);
gab 2014/01/03 18:25:52 I'd suggest changing this away from 0; thanks for
huangs 2014/01/03 20:19:35 Done. Lucky #7.
81 test_properties_.set_app_id(L"Polar.Bear"); 85 test_properties_.set_app_id(L"Polar.Bear");
82 test_properties_.set_dual_mode(true); 86 test_properties_.set_dual_mode(true);
83 } 87 }
84 88
85 // Validates that the shortcut at |location| matches |properties| (and 89 // Returns the expected path of a test shortcut. Returns an empty FilePath on
86 // implicit default properties) for |dist|. 90 // failure.
87 // Note: This method doesn't verify the |pin_to_taskbar| property as it 91 base::FilePath GetExpectedShortcutPath(
88 // implies real (non-mocked) state which is flaky to test.
89 void ValidateChromeShortcut(
90 ShellUtil::ShortcutLocation location, 92 ShellUtil::ShortcutLocation location,
91 BrowserDistribution* dist, 93 BrowserDistribution* dist,
92 const ShellUtil::ShortcutProperties& properties) { 94 const ShellUtil::ShortcutProperties& properties) {
93 base::FilePath expected_path; 95 base::FilePath expected_path;
94 switch (location) { 96 switch (location) {
95 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 97 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
96 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 98 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
97 fake_user_desktop_.path() : fake_common_desktop_.path(); 99 fake_user_desktop_.path() : fake_common_desktop_.path();
98 break; 100 break;
99 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 101 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 102 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
101 fake_user_quick_launch_.path() : 103 fake_user_quick_launch_.path() :
102 fake_default_user_quick_launch_.path(); 104 fake_default_user_quick_launch_.path();
103 break; 105 break;
104 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: 106 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
105 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 107 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
106 fake_start_menu_.path() : fake_common_start_menu_.path(); 108 fake_start_menu_.path() : fake_common_start_menu_.path();
107 expected_path = expected_path.Append( 109 expected_path = expected_path.Append(
108 dist_->GetStartMenuShortcutSubfolder( 110 dist_->GetStartMenuShortcutSubfolder(
109 BrowserDistribution::SUBFOLDER_CHROME)); 111 BrowserDistribution::SUBFOLDER_CHROME));
110 break; 112 break;
111 default: 113 default:
112 ADD_FAILURE() << "Unknown location"; 114 ADD_FAILURE() << "Unknown location";
113 return; 115 return base::FilePath();
114 } 116 }
115 117
116 string16 shortcut_name; 118 string16 shortcut_name = properties.has_shortcut_name() ?
117 if (properties.has_shortcut_name()) { 119 properties.shortcut_name :
118 shortcut_name = properties.shortcut_name; 120 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
119 } else {
120 shortcut_name =
121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME);
122 }
123 shortcut_name.append(installer::kLnkExt); 121 shortcut_name.append(installer::kLnkExt);
124 expected_path = expected_path.Append(shortcut_name); 122 return expected_path.Append(shortcut_name);
123 }
124
125 // Validates that the shortcut at |location| matches |properties| (and
126 // implicit default properties) for |dist|.
127 // Note: This method doesn't verify the |pin_to_taskbar| property as it
128 // implies real (non-mocked) state which is flaky to test.
129 void ValidateChromeShortcut(
130 ShellUtil::ShortcutLocation location,
131 BrowserDistribution* dist,
132 const ShellUtil::ShortcutProperties& properties) {
133 base::FilePath expected_path(
134 GetExpectedShortcutPath(location, dist, properties));
125 135
126 base::win::ShortcutProperties expected_properties; 136 base::win::ShortcutProperties expected_properties;
127 if (properties.has_target()) { 137 if (properties.has_target()) {
128 expected_properties.set_target(properties.target); 138 expected_properties.set_target(properties.target);
129 expected_properties.set_working_dir(properties.target.DirName()); 139 expected_properties.set_working_dir(properties.target.DirName());
130 } else { 140 } else {
131 expected_properties.set_target(chrome_exe_); 141 expected_properties.set_target(chrome_exe_);
132 expected_properties.set_working_dir(chrome_exe_.DirName()); 142 expected_properties.set_working_dir(chrome_exe_.DirName());
133 } 143 }
134 144
135 if (properties.has_arguments()) 145 if (properties.has_arguments())
136 expected_properties.set_arguments(properties.arguments); 146 expected_properties.set_arguments(properties.arguments);
137 else 147 else
138 expected_properties.set_arguments(string16()); 148 expected_properties.set_arguments(string16());
139 149
140 if (properties.has_description()) 150 if (properties.has_description())
141 expected_properties.set_description(properties.description); 151 expected_properties.set_description(properties.description);
142 else 152 else
143 expected_properties.set_description(dist->GetAppDescription()); 153 expected_properties.set_description(dist->GetAppDescription());
144 154
145 if (properties.has_icon()) { 155 if (properties.has_icon()) {
146 expected_properties.set_icon(properties.icon, 0); 156 expected_properties.set_icon(properties.icon, properties.icon_index);
147 } else { 157 } else {
148 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); 158 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME);
149 expected_properties.set_icon(chrome_exe_, icon_index); 159 expected_properties.set_icon(chrome_exe_, icon_index);
150 } 160 }
151 161
152 if (properties.has_app_id()) { 162 if (properties.has_app_id()) {
153 expected_properties.set_app_id(properties.app_id); 163 expected_properties.set_app_id(properties.app_id);
154 } else { 164 } else {
155 // Tests are always seen as user-level installs in ShellUtil. 165 // Tests are always seen as user-level installs in ShellUtil.
156 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); 166 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true));
(...skipping 22 matching lines...) Expand all
179 base::ScopedTempDir fake_common_start_menu_; 189 base::ScopedTempDir fake_common_start_menu_;
180 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 190 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
181 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 191 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
182 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 192 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
183 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; 193 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_;
184 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 194 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
185 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 195 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
186 196
187 base::FilePath chrome_exe_; 197 base::FilePath chrome_exe_;
188 base::FilePath manganese_exe_; 198 base::FilePath manganese_exe_;
199 base::FilePath other_ico_;
189 }; 200 };
190 201
191 } // namespace 202 } // namespace
192 203
193 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { 204 TEST_F(ShellUtilShortcutTest, GetShortcutPath) {
194 base::FilePath path; 205 base::FilePath path;
195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 206 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
196 ShellUtil::CURRENT_USER, &path); 207 ShellUtil::CURRENT_USER, &path);
197 EXPECT_EQ(fake_user_desktop_.path(), path); 208 EXPECT_EQ(fake_user_desktop_.path(), path);
198 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 209 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_, 372 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
362 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 373 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
363 ASSERT_TRUE(base::PathExists( 374 ASSERT_TRUE(base::PathExists(
364 fake_user_desktop_.path().Append(shortcut_name))); 375 fake_user_desktop_.path().Append(shortcut_name)));
365 } 376 }
366 377
367 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { 378 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 379 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 380 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
370 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 381 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
371 382 base::FilePath shortcut_path = GetExpectedShortcutPath(
372 string16 shortcut_name( 383 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)); 384 ASSERT_TRUE(base::PathExists(shortcut_path));
377 385
378 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 386 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 387 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
380 chrome_exe_)); 388 chrome_exe_));
381 ASSERT_FALSE(base::PathExists(shortcut_path)); 389 ASSERT_FALSE(base::PathExists(shortcut_path));
382 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); 390 ASSERT_TRUE(base::PathExists(shortcut_path.DirName()));
383 } 391 }
384 392
385 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { 393 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) {
386 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 394 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 395 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 396 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
389 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 397 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
390 398 base::FilePath shortcut_path = GetExpectedShortcutPath(
391 string16 shortcut_name( 399 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)); 400 ASSERT_TRUE(base::PathExists(shortcut_path));
397 401
398 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 402 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
399 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 403 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
400 chrome_exe_)); 404 chrome_exe_));
401 ASSERT_FALSE(base::PathExists(shortcut_path)); 405 ASSERT_FALSE(base::PathExists(shortcut_path));
402 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); 406 ASSERT_TRUE(base::PathExists(shortcut_path.DirName()));
403 } 407 }
404 408
405 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { 409 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) {
406 const wchar_t kShortcutName1[] = L"Chrome 1"; 410 const wchar_t kShortcutName1[] = L"Chrome 1";
407 const wchar_t kShortcutName2[] = L"Chrome 2"; 411 const wchar_t kShortcutName2[] = L"Chrome 2";
408 412
409 test_properties_.set_shortcut_name(kShortcutName1); 413 test_properties_.set_shortcut_name(kShortcutName1);
410 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 414 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 415 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 416 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
413 string16 shortcut1_name( 417 base::FilePath shortcut1_path = GetExpectedShortcutPath(
414 string16(kShortcutName1).append(installer::kLnkExt)); 418 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)); 419 ASSERT_TRUE(base::PathExists(shortcut1_path));
418 420
419 test_properties_.set_shortcut_name(kShortcutName2); 421 test_properties_.set_shortcut_name(kShortcutName2);
420 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); 422 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 423 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 424 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
423 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 425 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
424 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); 426 base::FilePath shortcut2_path = GetExpectedShortcutPath(
425 base::FilePath shortcut2_path( 427 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_);
426 fake_user_desktop_.path().Append(shortcut2_name));
427 ASSERT_TRUE(base::PathExists(shortcut2_path)); 428 ASSERT_TRUE(base::PathExists(shortcut2_path));
428 429
429 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 430 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 431 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
431 chrome_exe_)); 432 chrome_exe_));
432 ASSERT_FALSE(base::PathExists(shortcut1_path)); 433 ASSERT_FALSE(base::PathExists(shortcut1_path));
433 ASSERT_FALSE(base::PathExists(shortcut2_path)); 434 ASSERT_FALSE(base::PathExists(shortcut2_path));
434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); 435 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName()));
435 } 436 }
436 437
437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) { 438 TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) {
gab 2014/01/03 18:25:52 Seems a test is missing to make sure shortcuts tha
huangs 2014/01/03 20:19:35 Added to the multi-case: {targets "iron.exe", icon
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 439 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 440 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 441 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
441 442 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
442 string16 shortcut_name( 443 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
444 installer::kLnkExt);
445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
446 ASSERT_TRUE(base::PathExists(shortcut_path));
447 444
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 445 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 446 // Relies on fact that |test_properties_| has non-empty arguments.
450 updated_properties.set_target(new_exe); 447 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
451 // |updated_properties| has arguments.
452 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 448 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
454 chrome_exe_, updated_properties)); 449 chrome_exe_, new_exe));
455 450
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); 451 ShellUtil::ShortcutProperties expected_properties(test_properties_);
457 expected_properties.set_target(new_exe); 452 expected_properties.set_target(new_exe);
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 453 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
459 expected_properties); 454 expected_properties);
460 } 455 }
461 456
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) { 457 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) {
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 458 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 459 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 460 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 461 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
467 462 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
468 string16 shortcut_name( 463 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
470 installer::kLnkExt);
471 base::FilePath shortcut_path(
472 fake_common_desktop_.path().Append(shortcut_name));
473 ASSERT_TRUE(base::PathExists(shortcut_path));
474 464
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 465 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 466 // Relies on fact that |test_properties_| has non-empty arguments.
477 updated_properties.set_target(new_exe); 467 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
478 // |updated_properties| has arguments.
479 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 468 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
481 chrome_exe_, updated_properties)); 469 chrome_exe_, new_exe));
482 470
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); 471 ShellUtil::ShortcutProperties expected_properties(test_properties_);
484 expected_properties.set_target(new_exe); 472 expected_properties.set_target(new_exe);
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 473 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
486 expected_properties); 474 expected_properties);
487 } 475 }
488 476
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) { 477 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) {
490 const wchar_t kShortcutName1[] = L"Chrome 1"; 478 const wchar_t kShortcutName1[] = L"Chrome 1";
491 const wchar_t kShortcutName2[] = L"Chrome 2"; 479 const wchar_t kShortcutName2[] = L"Chrome 2";
492 480
493 // Setup shortcut 1, which has empty arguments. 481 // Setup shortcut 1, which has empty arguments.
494 test_properties_.set_shortcut_name(kShortcutName1); 482 test_properties_.set_shortcut_name(kShortcutName1);
495 test_properties_.set_arguments(L""); 483 test_properties_.set_arguments(L"");
496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 484 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 485 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 486 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); 487 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
500 base::FilePath shortcut1_path( 488 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
501 fake_user_desktop_.path().Append(shortcut1_name));
502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); 489 ShellUtil::ShortcutProperties expected_properties1(test_properties_);
503 490
504 // Setup shortcut 2, which has non-empty arguments. 491 // Setup shortcut 2, which has non-empty arguments.
505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\"";
506 test_properties_.set_shortcut_name(kShortcutName2); 492 test_properties_.set_shortcut_name(kShortcutName2);
507 test_properties_.set_arguments(shortcut2_args); 493 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\"");
508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 494 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 495 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 496 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); 497 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
512 base::FilePath shortcut2_path( 498 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_); 499 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
516 500
517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". 501 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only
502 // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated.
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 503 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 504 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
520 updated_properties.set_target(new_exe);
521
522 // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2.
523 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
524 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 505 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
525 chrome_exe_, updated_properties)); 506 chrome_exe_, new_exe));
526 // Verify shortcut 1. 507 // Verify shortcut 1.
527 // |expected_properties1| was unchanged and still targets "chrome.exe", since 508 // |expected_properties1| is unchanged and still targets "chrome.exe", since
528 // it has empty target, yet we passed |require_args| = true. 509 // it has empty target, yet we passed |require_args| = true.
gab 2014/01/03 18:25:52 |require_args| no longer exists right? please upda
huangs 2014/01/03 20:19:35 Done.
529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 510 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
530 expected_properties1); 511 expected_properties1);
531 // Verify shortcut 2. 512 // Verify shortcut 2, which now targets "manganese.exe".
532 expected_properties2.set_target(new_exe); 513 expected_properties2.set_target(new_exe);
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 514 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
534 expected_properties2); 515 expected_properties2);
535 } 516 }
517
518 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) {
519 const wchar_t kShortcutName1[] = L"Chrome 1";
520 const wchar_t kShortcutName2[] = L"Chrome 2";
521
522 // Setup shortcut 1, which has icon set to "chrome.exe".
523 test_properties_.set_shortcut_name(kShortcutName1);
524 test_properties_.set_icon(chrome_exe_, 3);
gab 2014/01/03 18:25:52 Use test_properties_.target instead of chrome_exe_
huangs 2014/01/03 20:19:35 Done.
525 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
526 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
527 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
528 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
529 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
530 ShellUtil::ShortcutProperties expected_properties1(test_properties_);
531
532 // Setup shortcut 2, which has icon set to "other.ico".
533 test_properties_.set_shortcut_name(kShortcutName2);
534 test_properties_.set_icon(other_ico_, 0);
535 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
536 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
537 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
538 ASSERT_TRUE(base::PathExists(GetExpectedShortcutPath(
539 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_)));
540 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
541
542 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe".
543 // Relies on fact that |test_properties_| has non-empty arguments.
gab 2014/01/03 18:25:52 s/Relies on fact/Relies on the fact Here and else
huangs 2014/01/03 20:19:35 Done.
544 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
545 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs(
546 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
547 chrome_exe_, new_exe));
548 // Verify shortcut 1: icon now targets "manganese.exe", with same icon index.
549 expected_properties1.set_target(new_exe);
550 expected_properties1.set_icon(new_exe, 3);
gab 2014/01/03 18:25:52 Move '3' into a local scope constant to be used he
huangs 2014/01/03 20:19:35 Done. The consts for the other 2 cases are only us
551 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
552 expected_properties1);
553 // Verify shortcut 2: icon remains unchanged.
554 expected_properties2.set_target(new_exe);
555 expected_properties2.set_icon(other_ico_, 0);
556 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
557 expected_properties2);
558 }
536 559
537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 560 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 561 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 562 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
540 dist_, test_properties_, 563 dist_, test_properties_,
541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 564 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 565 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 566 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
544 dist_, test_properties_, 567 dist_, test_properties_,
545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 568 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 736
714 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 737 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
715 L"MZXW6YTB", L"MZXW6YTBOI"}; 738 L"MZXW6YTB", L"MZXW6YTBOI"};
716 739
717 // Run the tests, with one more letter in the input every pass. 740 // Run the tests, with one more letter in the input every pass.
718 for (int i = 0; i < arraysize(expected); ++i) { 741 for (int i = 0; i < arraysize(expected); ++i) {
719 ASSERT_EQ(expected[i], 742 ASSERT_EQ(expected[i],
720 ShellUtil::ByteArrayToBase32(test_array, i)); 743 ShellUtil::ByteArrayToBase32(test_array, i));
721 } 744 }
722 } 745 }
OLDNEW
« base/win/shortcut_unittest.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