OLD | NEW |
---|---|
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 15 matching lines...) Expand all Loading... | |
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); |
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); |
gab
2014/01/02 21:01:46
I typically indent the two items of a ternary oper
huangs
2014/01/02 23:22:37
Done.
| |
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 // Helper to create a test shortcut on the (fake) desktop, and returns the | |
126 // path to the new shortcut. | |
127 base::FilePath CreateTestDesktopShortcut( | |
128 const ShellUtil::ShortcutProperties& properties) { | |
129 ShellUtil::ShortcutLocation location = ShellUtil::SHORTCUT_LOCATION_DESKTOP; | |
130 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | |
131 location, dist_, properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
132 return GetExpectedShortcutPath(location, dist_, properties); | |
133 } | |
134 | |
135 // Validates that the shortcut at |location| matches |properties| (and | |
136 // implicit default properties) for |dist|. | |
137 // Note: This method doesn't verify the |pin_to_taskbar| property as it | |
138 // implies real (non-mocked) state which is flaky to test. | |
139 void ValidateChromeShortcut( | |
140 ShellUtil::ShortcutLocation location, | |
141 BrowserDistribution* dist, | |
142 const ShellUtil::ShortcutProperties& properties) { | |
143 base::FilePath expected_path( | |
144 GetExpectedShortcutPath(location, dist, properties)); | |
125 | 145 |
126 base::win::ShortcutProperties expected_properties; | 146 base::win::ShortcutProperties expected_properties; |
127 if (properties.has_target()) { | 147 if (properties.has_target()) { |
128 expected_properties.set_target(properties.target); | 148 expected_properties.set_target(properties.target); |
129 expected_properties.set_working_dir(properties.target.DirName()); | 149 expected_properties.set_working_dir(properties.target.DirName()); |
130 } else { | 150 } else { |
131 expected_properties.set_target(chrome_exe_); | 151 expected_properties.set_target(chrome_exe_); |
132 expected_properties.set_working_dir(chrome_exe_.DirName()); | 152 expected_properties.set_working_dir(chrome_exe_.DirName()); |
133 } | 153 } |
134 | 154 |
135 if (properties.has_arguments()) | 155 if (properties.has_arguments()) |
136 expected_properties.set_arguments(properties.arguments); | 156 expected_properties.set_arguments(properties.arguments); |
137 else | 157 else |
138 expected_properties.set_arguments(string16()); | 158 expected_properties.set_arguments(string16()); |
139 | 159 |
140 if (properties.has_description()) | 160 if (properties.has_description()) |
141 expected_properties.set_description(properties.description); | 161 expected_properties.set_description(properties.description); |
142 else | 162 else |
143 expected_properties.set_description(dist->GetAppDescription()); | 163 expected_properties.set_description(dist->GetAppDescription()); |
144 | 164 |
145 if (properties.has_icon()) { | 165 if (properties.has_icon()) { |
146 expected_properties.set_icon(properties.icon, 0); | 166 expected_properties.set_icon(properties.icon, properties.icon_index); |
147 } else { | 167 } else { |
148 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); | 168 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); |
149 expected_properties.set_icon(chrome_exe_, icon_index); | 169 expected_properties.set_icon(chrome_exe_, icon_index); |
150 } | 170 } |
151 | 171 |
152 if (properties.has_app_id()) { | 172 if (properties.has_app_id()) { |
153 expected_properties.set_app_id(properties.app_id); | 173 expected_properties.set_app_id(properties.app_id); |
154 } else { | 174 } else { |
155 // Tests are always seen as user-level installs in ShellUtil. | 175 // Tests are always seen as user-level installs in ShellUtil. |
156 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); | 176 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
(...skipping 22 matching lines...) Expand all Loading... | |
179 base::ScopedTempDir fake_common_start_menu_; | 199 base::ScopedTempDir fake_common_start_menu_; |
180 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 200 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
181 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 201 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
182 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 202 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
183 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; | 203 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; |
184 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 204 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
185 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 205 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
186 | 206 |
187 base::FilePath chrome_exe_; | 207 base::FilePath chrome_exe_; |
188 base::FilePath manganese_exe_; | 208 base::FilePath manganese_exe_; |
209 base::FilePath other_ico_; | |
189 }; | 210 }; |
190 | 211 |
191 } // namespace | 212 } // namespace |
192 | 213 |
193 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { | 214 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { |
194 base::FilePath path; | 215 base::FilePath path; |
195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 216 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
196 ShellUtil::CURRENT_USER, &path); | 217 ShellUtil::CURRENT_USER, &path); |
197 EXPECT_EQ(fake_user_desktop_.path(), path); | 218 EXPECT_EQ(fake_user_desktop_.path(), path); |
198 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 219 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 379 |
359 test_properties_.level = ShellUtil::CURRENT_USER; | 380 test_properties_.level = ShellUtil::CURRENT_USER; |
360 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 381 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
361 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 382 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
362 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 383 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
363 ASSERT_TRUE(base::PathExists( | 384 ASSERT_TRUE(base::PathExists( |
364 fake_user_desktop_.path().Append(shortcut_name))); | 385 fake_user_desktop_.path().Append(shortcut_name))); |
365 } | 386 } |
366 | 387 |
367 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { | 388 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { |
368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 389 base::FilePath shortcut_path = CreateTestDesktopShortcut(test_properties_); |
gab
2014/01/02 21:01:46
So I really like that the refactoring is getting r
huangs
2014/01/02 23:22:37
If we get rid of the routine, we would replace eac
| |
369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 390 EXPECT_TRUE(base::PathExists(shortcut_path)); |
370 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
371 | |
372 string16 shortcut_name( | |
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)); | |
377 | 391 |
378 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 392 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 393 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
380 chrome_exe_)); | 394 chrome_exe_)); |
381 ASSERT_FALSE(base::PathExists(shortcut_path)); | 395 ASSERT_FALSE(base::PathExists(shortcut_path)); |
382 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 396 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
383 } | 397 } |
384 | 398 |
385 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { | 399 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { |
386 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 400 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 401 base::FilePath shortcut_path = CreateTestDesktopShortcut(test_properties_); |
388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 402 EXPECT_TRUE(base::PathExists(shortcut_path)); |
389 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
390 | |
391 string16 shortcut_name( | |
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)); | |
397 | 403 |
398 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 404 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
399 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 405 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
400 chrome_exe_)); | 406 chrome_exe_)); |
401 ASSERT_FALSE(base::PathExists(shortcut_path)); | 407 ASSERT_FALSE(base::PathExists(shortcut_path)); |
402 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 408 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
403 } | 409 } |
404 | 410 |
405 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { | 411 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { |
406 const wchar_t kShortcutName1[] = L"Chrome 1"; | 412 const wchar_t kShortcutName1[] = L"Chrome 1"; |
407 const wchar_t kShortcutName2[] = L"Chrome 2"; | 413 const wchar_t kShortcutName2[] = L"Chrome 2"; |
408 | 414 |
409 test_properties_.set_shortcut_name(kShortcutName1); | 415 test_properties_.set_shortcut_name(kShortcutName1); |
410 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 416 base::FilePath shortcut1_path = CreateTestDesktopShortcut(test_properties_); |
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 417 EXPECT_TRUE(base::PathExists(shortcut1_path)); |
412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
413 string16 shortcut1_name( | |
414 string16(kShortcutName1).append(installer::kLnkExt)); | |
415 base::FilePath shortcut1_path( | |
416 fake_user_desktop_.path().Append(shortcut1_name)); | |
417 ASSERT_TRUE(base::PathExists(shortcut1_path)); | |
418 | 418 |
419 test_properties_.set_shortcut_name(kShortcutName2); | 419 test_properties_.set_shortcut_name(kShortcutName2); |
420 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); | 420 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); |
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 421 base::FilePath shortcut2_path = CreateTestDesktopShortcut(test_properties_); |
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 422 EXPECT_TRUE(base::PathExists(shortcut2_path)); |
423 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
424 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | |
425 base::FilePath shortcut2_path( | |
426 fake_user_desktop_.path().Append(shortcut2_name)); | |
427 ASSERT_TRUE(base::PathExists(shortcut2_path)); | |
428 | 423 |
429 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 424 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 425 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
431 chrome_exe_)); | 426 chrome_exe_)); |
432 ASSERT_FALSE(base::PathExists(shortcut1_path)); | 427 ASSERT_FALSE(base::PathExists(shortcut1_path)); |
433 ASSERT_FALSE(base::PathExists(shortcut2_path)); | 428 ASSERT_FALSE(base::PathExists(shortcut2_path)); |
434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); | 429 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); |
435 } | 430 } |
436 | 431 |
437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) { | 432 TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) { |
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 433 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); |
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
441 | |
442 string16 shortcut_name( | |
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 | 434 |
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 435 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 436 // Relies on fact that |test_properties_| has non-empty arguments. |
450 updated_properties.set_target(new_exe); | 437 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( |
451 // |updated_properties| has arguments. | |
452 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs( | |
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 438 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
454 chrome_exe_, updated_properties)); | 439 chrome_exe_, new_exe)); |
455 | 440 |
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 441 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
457 expected_properties.set_target(new_exe); | 442 expected_properties.set_target(new_exe); |
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 443 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
459 expected_properties); | 444 expected_properties); |
460 } | 445 } |
461 | 446 |
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) { | 447 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) { |
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 448 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 449 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); |
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
467 | |
468 string16 shortcut_name( | |
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 | 450 |
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 451 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 452 // Relies on fact that |test_properties_| has non-empty arguments. |
477 updated_properties.set_target(new_exe); | 453 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( |
478 // |updated_properties| has arguments. | |
479 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs( | |
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 454 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
481 chrome_exe_, updated_properties)); | 455 chrome_exe_, new_exe)); |
482 | 456 |
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 457 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
484 expected_properties.set_target(new_exe); | 458 expected_properties.set_target(new_exe); |
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 459 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
486 expected_properties); | 460 expected_properties); |
487 } | 461 } |
488 | 462 |
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) { | 463 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) { |
490 const wchar_t kShortcutName1[] = L"Chrome 1"; | 464 const wchar_t kShortcutName1[] = L"Chrome 1"; |
491 const wchar_t kShortcutName2[] = L"Chrome 2"; | 465 const wchar_t kShortcutName2[] = L"Chrome 2"; |
492 | 466 |
493 // Setup shortcut 1, which has empty arguments. | 467 // Setup shortcut 1, which has empty arguments. |
494 test_properties_.set_shortcut_name(kShortcutName1); | 468 test_properties_.set_shortcut_name(kShortcutName1); |
495 test_properties_.set_arguments(L""); | 469 test_properties_.set_arguments(L""); |
496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 470 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); |
497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); | |
500 base::FilePath shortcut1_path( | |
501 fake_user_desktop_.path().Append(shortcut1_name)); | |
502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); | 471 ShellUtil::ShortcutProperties expected_properties1(test_properties_); |
503 | 472 |
504 // Setup shortcut 2, which has non-empty arguments. | 473 // Setup shortcut 2, which has non-empty arguments. |
505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; | |
506 test_properties_.set_shortcut_name(kShortcutName2); | 474 test_properties_.set_shortcut_name(kShortcutName2); |
507 test_properties_.set_arguments(shortcut2_args); | 475 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); |
508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 476 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); |
509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | |
512 base::FilePath shortcut2_path( | |
513 fake_user_desktop_.path().Append(shortcut2_name)); | |
514 ASSERT_TRUE(base::PathExists(shortcut2_path)); | |
515 ShellUtil::ShortcutProperties expected_properties2(test_properties_); | 477 ShellUtil::ShortcutProperties expected_properties2(test_properties_); |
516 | 478 |
517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". | 479 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only |
480 // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated. | |
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 481 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 482 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, | 483 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
525 chrome_exe_, updated_properties)); | 484 chrome_exe_, new_exe)); |
526 // Verify shortcut 1. | 485 // Verify shortcut 1. |
527 // |expected_properties1| was unchanged and still targets "chrome.exe", since | 486 // |expected_properties1| is unchanged and still targets "chrome.exe", since |
528 // it has empty target, yet we passed |require_args| = true. | 487 // it has empty target, yet we passed |require_args| = true. |
529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 488 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
530 expected_properties1); | 489 expected_properties1); |
531 // Verify shortcut 2. | 490 // Verify shortcut 2, which now targets "manganese.exe". |
532 expected_properties2.set_target(new_exe); | 491 expected_properties2.set_target(new_exe); |
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 492 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
534 expected_properties2); | 493 expected_properties2); |
535 } | 494 } |
495 | |
496 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) { | |
497 const wchar_t kShortcutName1[] = L"Chrome 1"; | |
498 const wchar_t kShortcutName2[] = L"Chrome 2"; | |
499 | |
500 // Setup shortcut 1, which has icon set to "chrome.exe". | |
501 test_properties_.set_shortcut_name(kShortcutName1); | |
502 test_properties_.set_icon(chrome_exe_, 3); | |
503 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); | |
504 ShellUtil::ShortcutProperties expected_properties1(test_properties_); | |
505 | |
506 // Setup shortcut 2, which has icon set to "other.ico". | |
507 test_properties_.set_shortcut_name(kShortcutName2); | |
508 test_properties_.set_icon(other_ico_, 0); | |
509 EXPECT_TRUE(base::PathExists(CreateTestDesktopShortcut(test_properties_))); | |
510 ShellUtil::ShortcutProperties expected_properties2(test_properties_); | |
511 | |
512 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". | |
513 // Relies on fact that |test_properties_| has non-empty arguments. | |
514 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | |
515 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( | |
516 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | |
517 chrome_exe_, new_exe)); | |
518 // Verify shortcut 1: icon now targets "manganese.exe", with same icon index. | |
519 expected_properties1.set_target(new_exe); | |
520 expected_properties1.set_icon(new_exe, 3); | |
521 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
522 expected_properties1); | |
523 // Verify shortcut 2: icon remains unchanged. | |
524 expected_properties2.set_target(new_exe); | |
525 expected_properties2.set_icon(other_ico_, 0); | |
526 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
527 expected_properties2); | |
528 } | |
536 | 529 |
537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 530 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 531 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 532 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
540 dist_, test_properties_, | 533 dist_, test_properties_, |
541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 534 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 535 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, | 536 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
544 dist_, test_properties_, | 537 dist_, test_properties_, |
545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 538 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 706 |
714 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 707 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
715 L"MZXW6YTB", L"MZXW6YTBOI"}; | 708 L"MZXW6YTB", L"MZXW6YTBOI"}; |
716 | 709 |
717 // Run the tests, with one more letter in the input every pass. | 710 // Run the tests, with one more letter in the input every pass. |
718 for (int i = 0; i < arraysize(expected); ++i) { | 711 for (int i = 0; i < arraysize(expected); ++i) { |
719 ASSERT_EQ(expected[i], | 712 ASSERT_EQ(expected[i], |
720 ShellUtil::ByteArrayToBase32(test_array, i)); | 713 ShellUtil::ByteArrayToBase32(test_array, i)); |
721 } | 714 } |
722 } | 715 } |
OLD | NEW |