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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 switch (location) { | 89 switch (location) { |
90 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: | 90 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: |
91 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 91 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? |
92 fake_user_desktop_.path() : fake_common_desktop_.path(); | 92 fake_user_desktop_.path() : fake_common_desktop_.path(); |
93 break; | 93 break; |
94 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: | 94 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: |
95 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 95 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? |
96 fake_user_quick_launch_.path() : | 96 fake_user_quick_launch_.path() : |
97 fake_default_user_quick_launch_.path(); | 97 fake_default_user_quick_launch_.path(); |
98 break; | 98 break; |
99 case ShellUtil::SHORTCUT_LOCATION_START_MENU: | 99 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: |
100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? |
101 fake_start_menu_.path() : fake_common_start_menu_.path(); | 101 fake_start_menu_.path() : fake_common_start_menu_.path(); |
102 expected_path = expected_path.Append(dist_->GetAppShortCutName()); | 102 expected_path = expected_path.Append(dist_->GetAppShortCutName()); |
103 break; | 103 break; |
104 default: | 104 default: |
105 ADD_FAILURE() << "Unknown location"; | 105 ADD_FAILURE() << "Unknown location"; |
106 return; | 106 return; |
107 } | 107 } |
108 | 108 |
109 string16 shortcut_name; | 109 string16 shortcut_name; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 EXPECT_EQ(fake_user_desktop_.path(), path); | 182 EXPECT_EQ(fake_user_desktop_.path(), path); |
183 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 183 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
184 ShellUtil::SYSTEM_LEVEL, &path); | 184 ShellUtil::SYSTEM_LEVEL, &path); |
185 EXPECT_EQ(fake_common_desktop_.path(), path); | 185 EXPECT_EQ(fake_common_desktop_.path(), path); |
186 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 186 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
187 ShellUtil::CURRENT_USER, &path); | 187 ShellUtil::CURRENT_USER, &path); |
188 EXPECT_EQ(fake_user_quick_launch_.path(), path); | 188 EXPECT_EQ(fake_user_quick_launch_.path(), path); |
189 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 189 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
190 ShellUtil::SYSTEM_LEVEL, &path); | 190 ShellUtil::SYSTEM_LEVEL, &path); |
191 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); | 191 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); |
192 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 192 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
193 ShellUtil::CURRENT_USER, &path); | 193 dist_, ShellUtil::CURRENT_USER, &path); |
194 EXPECT_EQ(fake_start_menu_.path().Append(dist_->GetAppShortCutName()), path); | 194 EXPECT_EQ(fake_start_menu_.path().Append(dist_->GetAppShortCutName()), path); |
195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
196 ShellUtil::SYSTEM_LEVEL, &path); | 196 dist_, ShellUtil::SYSTEM_LEVEL, &path); |
197 EXPECT_EQ(fake_common_start_menu_.path().Append(dist_->GetAppShortCutName()), | 197 EXPECT_EQ(fake_common_start_menu_.path().Append(dist_->GetAppShortCutName()), |
198 path); | 198 path); |
199 } | 199 } |
200 | 200 |
201 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { | 201 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { |
202 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 202 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
203 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); | 203 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); |
204 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 204 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
205 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, | 205 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, |
206 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 206 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
207 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 207 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
208 properties); | 208 properties); |
209 } | 209 } |
210 | 210 |
211 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { | 211 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { |
212 test_properties_->set_shortcut_name(L"Bobo le shortcut"); | 212 test_properties_->set_shortcut_name(L"Bobo le shortcut"); |
213 test_properties_->level = ShellUtil::SYSTEM_LEVEL; | 213 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
214 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 214 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
215 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 215 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
216 dist_, *test_properties_, | 216 dist_, *test_properties_, |
217 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 217 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
218 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 218 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
219 *test_properties_); | 219 dist_, *test_properties_); |
220 } | 220 } |
221 | 221 |
222 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) { | 222 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) { |
223 test_properties_->level = ShellUtil::SYSTEM_LEVEL; | 223 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
224 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 224 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
225 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 225 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
226 dist_, *test_properties_, | 226 dist_, *test_properties_, |
227 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 227 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
228 | 228 |
229 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); | 229 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 expected_properties.set_arguments(updated_properties.arguments); | 265 expected_properties.set_arguments(updated_properties.arguments); |
266 | 266 |
267 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 267 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
268 expected_properties); | 268 expected_properties); |
269 } | 269 } |
270 | 270 |
271 TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) { | 271 TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) { |
272 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 272 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
273 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); | 273 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); |
274 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 274 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
275 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, properties, | 275 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
276 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 276 dist_, properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
277 | 277 |
278 ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER); | 278 ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER); |
279 added_properties.set_dual_mode(true); | 279 added_properties.set_dual_mode(true); |
280 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 280 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
281 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 281 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_, |
282 added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); | 282 added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); |
283 | 283 |
284 ShellUtil::ShortcutProperties expected_properties(properties); | 284 ShellUtil::ShortcutProperties expected_properties(properties); |
285 expected_properties.set_dual_mode(true); | 285 expected_properties.set_dual_mode(true); |
286 | 286 |
287 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 287 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
288 expected_properties); | 288 dist_, expected_properties); |
289 } | 289 } |
290 | 290 |
291 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { | 291 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { |
292 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 292 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
293 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 293 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
294 *test_properties_, | 294 *test_properties_, |
295 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 295 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
296 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 296 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
297 *test_properties_); | 297 *test_properties_); |
298 } | 298 } |
(...skipping 13 matching lines...) Expand all Loading... |
312 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 312 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
313 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 313 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
314 *test_properties_, | 314 *test_properties_, |
315 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 315 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
316 ASSERT_FALSE(file_util::PathExists( | 316 ASSERT_FALSE(file_util::PathExists( |
317 fake_user_desktop_.path().Append(shortcut_name))); | 317 fake_user_desktop_.path().Append(shortcut_name))); |
318 } | 318 } |
319 | 319 |
320 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { | 320 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { |
321 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 321 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
322 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 322 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
323 dist_, *test_properties_, | 323 dist_, *test_properties_, |
324 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 324 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
325 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 325 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
326 *test_properties_); | 326 dist_, *test_properties_); |
327 } | 327 } |
328 | 328 |
329 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { | 329 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { |
330 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 330 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
331 | 331 |
332 test_properties_->level = ShellUtil::SYSTEM_LEVEL; | 332 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
333 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 333 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
334 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 334 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
335 *test_properties_, | 335 *test_properties_, |
336 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 336 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 base::FilePath target_path2; | 508 base::FilePath target_path2; |
509 string16 shortcut2_args_read; | 509 string16 shortcut2_args_read; |
510 ASSERT_TRUE(base::win::ResolveShortcut(shortcut2_path, &target_path2, | 510 ASSERT_TRUE(base::win::ResolveShortcut(shortcut2_path, &target_path2, |
511 &shortcut2_args_read)); | 511 &shortcut2_args_read)); |
512 ASSERT_EQ(new_exe, target_path2); | 512 ASSERT_EQ(new_exe, target_path2); |
513 ASSERT_EQ(shortcut2_args, shortcut2_args_read); | 513 ASSERT_EQ(shortcut2_args, shortcut2_args_read); |
514 } | 514 } |
515 | 515 |
516 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 516 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
517 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 517 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
518 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 518 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
519 dist_, *test_properties_, | 519 dist_, *test_properties_, |
520 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 520 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
521 test_properties_->set_shortcut_name(L"A second shortcut"); | 521 test_properties_->set_shortcut_name(L"A second shortcut"); |
522 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 522 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
523 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 523 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
524 dist_, *test_properties_, | 524 dist_, *test_properties_, |
525 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 525 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
526 | 526 |
527 base::FilePath shortcut_folder( | 527 base::FilePath shortcut_folder( |
528 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); | 528 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); |
529 file_util::FileEnumerator file_counter(shortcut_folder, false, | 529 file_util::FileEnumerator file_counter(shortcut_folder, false, |
530 file_util::FileEnumerator::FILES); | 530 file_util::FileEnumerator::FILES); |
531 int count = 0; | 531 int count = 0; |
532 while (!file_counter.Next().empty()) | 532 while (!file_counter.Next().empty()) |
533 ++count; | 533 ++count; |
534 EXPECT_EQ(2, count); | 534 EXPECT_EQ(2, count); |
535 | 535 |
536 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); | 536 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); |
537 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 537 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
538 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, | 538 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_, |
539 chrome_exe_)); | 539 ShellUtil::CURRENT_USER, chrome_exe_)); |
540 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); | 540 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); |
541 } | 541 } |
542 | 542 |
543 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 543 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
544 base::ScopedTempDir other_exe_dir; | 544 base::ScopedTempDir other_exe_dir; |
545 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 545 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
546 base::FilePath other_chrome_exe = | 546 base::FilePath other_chrome_exe = |
547 other_exe_dir.path().Append(installer::kChromeExe); | 547 other_exe_dir.path().Append(installer::kChromeExe); |
548 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 548 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
549 | 549 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 638 |
639 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 639 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
640 L"MZXW6YTB", L"MZXW6YTBOI"}; | 640 L"MZXW6YTB", L"MZXW6YTBOI"}; |
641 | 641 |
642 // Run the tests, with one more letter in the input every pass. | 642 // Run the tests, with one more letter in the input every pass. |
643 for (int i = 0; i < arraysize(expected); ++i) { | 643 for (int i = 0; i < arraysize(expected); ++i) { |
644 ASSERT_EQ(expected[i], | 644 ASSERT_EQ(expected[i], |
645 ShellUtil::ByteArrayToBase32(test_array, i)); | 645 ShellUtil::ByteArrayToBase32(test_array, i)); |
646 } | 646 } |
647 } | 647 } |
OLD | NEW |