Chromium Code Reviews| 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 <objbase.h> | 5 #include <objbase.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/test/scoped_path_override.h" | 20 #include "base/test/scoped_path_override.h" |
| 20 #include "base/test/test_shortcut_win.h" | 21 #include "base/test/test_shortcut_win.h" |
| 21 #include "base/version.h" | 22 #include "base/version.h" |
| 22 #include "base/win/shortcut.h" | 23 #include "base/win/shortcut.h" |
| 23 #include "chrome/installer/setup/install.h" | 24 #include "chrome/installer/setup/install.h" |
| 24 #include "chrome/installer/setup/install_worker.h" | 25 #include "chrome/installer/setup/install_worker.h" |
| 25 #include "chrome/installer/setup/setup_constants.h" | 26 #include "chrome/installer/setup/setup_constants.h" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 installer::CreateOrUpdateShortcuts( | 460 installer::CreateOrUpdateShortcuts( |
| 460 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 461 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 461 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); | 462 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); |
| 462 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); | 463 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); |
| 463 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 464 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 464 expected_properties_); | 465 expected_properties_); |
| 465 base::win::ValidateShortcut(user_start_menu_shortcut_, | 466 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 466 expected_start_menu_properties_); | 467 expected_start_menu_properties_); |
| 467 } | 468 } |
| 468 | 469 |
| 469 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) { | 470 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsIcon) { |
|
gab
2016/03/17 20:14:23
Since all of these tests essentially more or less
fdoray
2016/03/18 14:08:59
Done.
| |
| 471 static const struct TestCase { | |
| 472 const base::FilePath::CharType* icon; | |
| 473 bool should_update; | |
| 474 } kTestCases[] = { | |
| 475 {FILE_PATH_LITERAL( | |
| 476 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | |
| 477 true}, | |
| 478 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\User Data\\Profile " | |
| 479 "1\\Google Profile.ico"), | |
| 480 true}, | |
| 481 {FILE_PATH_LITERAL( | |
| 482 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | |
| 483 false}, | |
| 484 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS\\User " | |
| 485 "Data\\Profile 1\\Google Profile.ico"), | |
| 486 false}, | |
| 487 {FILE_PATH_LITERAL("AppData\\Local\\Something Else.ico"), false}, | |
| 488 }; | |
| 489 | |
| 490 base::FilePath target_path; | |
| 491 ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &target_path)); | |
| 492 | |
| 493 // Create shortcuts. | |
| 494 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 495 base::win::ShortcutProperties properties; | |
| 496 properties.set_target(target_path); | |
| 497 properties.set_icon(temp_dir_.path().Append(kTestCases[i].icon), 1); | |
| 498 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 499 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 500 properties, base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 501 } | |
| 502 | |
| 503 // Update shortcuts. | |
| 504 base::FilePath new_target_path = | |
| 505 temp_dir_.path().Append(target_path.BaseName()); | |
| 506 ASSERT_TRUE(base::CopyFile(target_path, new_target_path)); | |
| 507 | |
| 508 installer::UpdatePerUserShortcutsInLocation( | |
| 509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
| 510 temp_dir_.path().Append( | |
| 511 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome")), | |
| 512 base::FilePath(FILE_PATH_LITERAL("dummy.exe")), new_target_path); | |
| 513 | |
| 514 // Verify that shortcuts were updated correctly. | |
| 515 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 516 base::FilePath actual_target_path; | |
| 517 ASSERT_TRUE(base::win::ResolveShortcut( | |
| 518 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 519 &actual_target_path, nullptr)); | |
| 520 | |
| 521 if (kTestCases[i].should_update) { | |
| 522 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | |
| 523 GetNormalizedFilePath(actual_target_path)); | |
| 524 } else { | |
| 525 EXPECT_EQ(GetNormalizedFilePath(target_path), | |
| 526 GetNormalizedFilePath(actual_target_path)); | |
| 527 } | |
| 528 } | |
| 529 } | |
| 530 | |
| 531 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsTarget) { | |
| 470 static const struct TestCase { | 532 static const struct TestCase { |
| 471 const base::FilePath::CharType* relative_target_path; | 533 const base::FilePath::CharType* relative_target_path; |
| 472 bool should_update; | 534 bool should_update; |
| 473 } kTargetPathsToUpdate[] = { | 535 } kTargetPathsToUpdate[] = { |
| 474 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 536 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 475 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), | 537 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| 476 false}, | 538 false}, |
| 477 {FILE_PATH_LITERAL( | 539 {FILE_PATH_LITERAL( |
| 478 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), | 540 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| 479 false}, | 541 false}, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | 595 EXPECT_EQ(GetNormalizedFilePath(new_target_path), |
| 534 GetNormalizedFilePath(target_path)); | 596 GetNormalizedFilePath(target_path)); |
| 535 } else { | 597 } else { |
| 536 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append( | 598 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append( |
| 537 kTargetPathsToUpdate[i].relative_target_path)), | 599 kTargetPathsToUpdate[i].relative_target_path)), |
| 538 GetNormalizedFilePath(target_path)); | 600 GetNormalizedFilePath(target_path)); |
| 539 } | 601 } |
| 540 } | 602 } |
| 541 } | 603 } |
| 542 | 604 |
| 543 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) { | 605 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsIconCanary) { |
| 606 static const struct TestCase { | |
| 607 const base::FilePath::CharType* icon; | |
| 608 bool should_update; | |
| 609 } kTestCases[] = { | |
| 610 {FILE_PATH_LITERAL( | |
| 611 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"), | |
| 612 false}, | |
| 613 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome\\User Data\\Profile " | |
| 614 "1\\Google Profile.ico"), | |
| 615 false}, | |
| 616 {FILE_PATH_LITERAL( | |
| 617 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"), | |
| 618 true}, | |
| 619 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS\\User " | |
| 620 "Data\\Profile 1\\Google Profile.ico"), | |
| 621 true}, | |
| 622 {FILE_PATH_LITERAL("AppData\\Local\\Something Else.ico"), false}, | |
| 623 }; | |
| 624 | |
| 625 base::FilePath target_path; | |
| 626 ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &target_path)); | |
| 627 | |
| 628 // Create shortcuts. | |
| 629 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 630 base::win::ShortcutProperties properties; | |
| 631 properties.set_target(target_path); | |
| 632 properties.set_icon(temp_dir_.path().Append(kTestCases[i].icon), 1); | |
| 633 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 634 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 635 properties, base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 636 } | |
| 637 | |
| 638 // Update shortcuts. | |
| 639 base::FilePath new_target_path = | |
| 640 temp_dir_.path().Append(target_path.BaseName()); | |
| 641 ASSERT_TRUE(base::CopyFile(target_path, new_target_path)); | |
| 642 | |
| 643 installer::UpdatePerUserShortcutsInLocation( | |
| 644 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
| 645 temp_dir_.path().Append( | |
| 646 FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome SxS")), | |
| 647 base::FilePath(FILE_PATH_LITERAL("dummy.exe")), new_target_path); | |
| 648 | |
| 649 // Verify that shortcuts were updated correctly. | |
| 650 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 651 base::FilePath actual_target_path; | |
| 652 ASSERT_TRUE(base::win::ResolveShortcut( | |
| 653 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)), | |
| 654 &actual_target_path, nullptr)); | |
| 655 | |
| 656 if (kTestCases[i].should_update) { | |
| 657 EXPECT_EQ(GetNormalizedFilePath(new_target_path), | |
| 658 GetNormalizedFilePath(actual_target_path)); | |
| 659 } else { | |
| 660 EXPECT_EQ(GetNormalizedFilePath(target_path), | |
| 661 GetNormalizedFilePath(actual_target_path)); | |
| 662 } | |
| 663 } | |
| 664 } | |
| 665 | |
| 666 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsTargetCanary) { | |
| 544 static const struct TestCase { | 667 static const struct TestCase { |
| 545 const base::FilePath::CharType* relative_target_path; | 668 const base::FilePath::CharType* relative_target_path; |
| 546 bool should_update; | 669 bool should_update; |
| 547 } kTargetPathsToUpdate[] = { | 670 } kTargetPathsToUpdate[] = { |
| 548 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " | 671 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome " |
| 549 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), | 672 "SxS\\Temp\\scoped_dir\\new_chrome.exe"), |
| 550 true}, | 673 true}, |
| 551 {FILE_PATH_LITERAL( | 674 {FILE_PATH_LITERAL( |
| 552 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), | 675 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"), |
| 553 true}, | 676 true}, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 744 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 622 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 745 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 623 } | 746 } |
| 624 | 747 |
| 625 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 748 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 626 base::string16 val(L"Google Chrome"); | 749 base::string16 val(L"Google Chrome"); |
| 627 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 750 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 628 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 751 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 629 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 752 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 630 } | 753 } |
| OLD | NEW |