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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 installer::kLnkExt); | 444 installer::kLnkExt); |
445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
446 ASSERT_TRUE(base::PathExists(shortcut_path)); | 446 ASSERT_TRUE(base::PathExists(shortcut_path)); |
447 | 447 |
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
450 updated_properties.set_target(new_exe); | 450 updated_properties.set_target(new_exe); |
451 | 451 |
452 ASSERT_TRUE(ShellUtil::UpdateShortcuts( | 452 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
454 chrome_exe_, updated_properties)); | 454 chrome_exe_, false, updated_properties)); |
455 | 455 |
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 456 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
457 expected_properties.set_target(new_exe); | 457 expected_properties.set_target(new_exe); |
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
459 expected_properties); | 459 expected_properties); |
460 } | 460 } |
461 | 461 |
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcut) { | 462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcut) { |
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
467 | 467 |
468 string16 shortcut_name( | 468 string16 shortcut_name( |
469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | 469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
470 installer::kLnkExt); | 470 installer::kLnkExt); |
471 base::FilePath shortcut_path( | 471 base::FilePath shortcut_path( |
472 fake_common_desktop_.path().Append(shortcut_name)); | 472 fake_common_desktop_.path().Append(shortcut_name)); |
473 ASSERT_TRUE(base::PathExists(shortcut_path)); | 473 ASSERT_TRUE(base::PathExists(shortcut_path)); |
474 | 474 |
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
477 updated_properties.set_target(new_exe); | 477 updated_properties.set_target(new_exe); |
478 | 478 |
479 ASSERT_TRUE(ShellUtil::UpdateShortcuts( | 479 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
481 chrome_exe_, updated_properties)); | 481 chrome_exe_, false, updated_properties)); |
482 | 482 |
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 483 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
484 expected_properties.set_target(new_exe); | 484 expected_properties.set_target(new_exe); |
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
486 expected_properties); | 486 expected_properties); |
487 } | 487 } |
488 | 488 |
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcuts) { | 489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcuts) { |
490 const wchar_t kShortcutName1[] = L"Chrome 1"; | 490 const wchar_t kShortcutName1[] = L"Chrome 1"; |
491 const wchar_t kShortcutName2[] = L"Chrome 2"; | 491 const wchar_t kShortcutName2[] = L"Chrome 2"; |
492 | 492 |
493 // Setup shortcut 1. | 493 // Setup shortcut 1, which has empty arguments. |
494 test_properties_.set_shortcut_name(kShortcutName1); | 494 test_properties_.set_shortcut_name(kShortcutName1); |
| 495 test_properties_.set_arguments(L""); |
495 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
496 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
497 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
498 string16 shortcut1_name( | 499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); |
499 string16(kShortcutName1).append(installer::kLnkExt)); | |
500 base::FilePath shortcut1_path( | 500 base::FilePath shortcut1_path( |
501 fake_user_desktop_.path().Append(shortcut1_name)); | 501 fake_user_desktop_.path().Append(shortcut1_name)); |
502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); | 502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); |
503 | 503 |
504 // Setup shortcut 2, which also has arguments. | 504 // Setup shortcut 2, which has non-empty arguments. |
505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; | 505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; |
506 test_properties_.set_shortcut_name(kShortcutName2); | 506 test_properties_.set_shortcut_name(kShortcutName2); |
507 test_properties_.set_arguments(shortcut2_args); | 507 test_properties_.set_arguments(shortcut2_args); |
508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | 511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); |
512 base::FilePath shortcut2_path( | 512 base::FilePath shortcut2_path( |
513 fake_user_desktop_.path().Append(shortcut2_name)); | 513 fake_user_desktop_.path().Append(shortcut2_name)); |
514 ASSERT_TRUE(base::PathExists(shortcut2_path)); | 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 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". |
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
520 updated_properties.set_target(new_exe); | 520 updated_properties.set_target(new_exe); |
| 521 |
| 522 // |require_args| = true, so only changing shrotcuts that have non-empty |
| 523 // arguments; only shortcut 2 is updated. |
521 ASSERT_TRUE(ShellUtil::UpdateShortcuts( | 524 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
522 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 525 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
523 chrome_exe_, updated_properties)); | 526 chrome_exe_, /*require_args*/ true, updated_properties)); |
| 527 // Verify shortcut 1. |
| 528 // |expected_properties1| was unchanged and still targets "chrome.exe", since |
| 529 // it has empty target, yet we passed |require_args| = true. |
| 530 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 531 expected_properties1); |
| 532 // Verify shortcut 2. |
| 533 expected_properties2.set_target(new_exe); |
| 534 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 535 expected_properties2); |
524 | 536 |
| 537 // |require_args| = false, now both shortcuts are updated. |
| 538 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
| 539 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 540 chrome_exe_, /*require_args*/ false, updated_properties)); |
525 // Verify shortcut 1. | 541 // Verify shortcut 1. |
526 expected_properties1.set_target(new_exe); | 542 expected_properties1.set_target(new_exe); |
527 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 543 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
528 expected_properties1); | 544 expected_properties1); |
529 | |
530 // Verify shortcut 2. | 545 // Verify shortcut 2. |
531 expected_properties2.set_target(new_exe); | |
532 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 546 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
533 expected_properties2); | 547 expected_properties2); |
534 } | 548 } |
535 | 549 |
536 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 550 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
537 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 551 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
538 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 552 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
539 dist_, test_properties_, | 553 dist_, test_properties_, |
540 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 554 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
541 test_properties_.set_shortcut_name(L"A second shortcut"); | 555 test_properties_.set_shortcut_name(L"A second shortcut"); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 675 |
662 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 676 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
663 L"MZXW6YTB", L"MZXW6YTBOI"}; | 677 L"MZXW6YTB", L"MZXW6YTBOI"}; |
664 | 678 |
665 // Run the tests, with one more letter in the input every pass. | 679 // Run the tests, with one more letter in the input every pass. |
666 for (int i = 0; i < arraysize(expected); ++i) { | 680 for (int i = 0; i < arraysize(expected); ++i) { |
667 ASSERT_EQ(expected[i], | 681 ASSERT_EQ(expected[i], |
668 ShellUtil::ByteArrayToBase32(test_array, i)); | 682 ShellUtil::ByteArrayToBase32(test_array, i)); |
669 } | 683 } |
670 } | 684 } |
OLD | NEW |