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/setup/setup_util_unittest.h" | 5 #include "chrome/installer/setup/setup_util_unittest.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
17 #include "base/process/kill.h" | 18 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
19 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/test/histogram_tester.h" | 22 #include "base/test/histogram_tester.h" |
22 #include "base/test/test_reg_util_win.h" | 23 #include "base/test/test_reg_util_win.h" |
23 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
24 #include "base/threading/platform_thread.h" | 25 #include "base/threading/platform_thread.h" |
25 #include "base/version.h" | 26 #include "base/version.h" |
26 #include "base/win/registry.h" | 27 #include "base/win/registry.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 506 } |
506 | 507 |
507 TEST_F(FindArchiveToPatchTest, DesiredVersionNotFound) { | 508 TEST_F(FindArchiveToPatchTest, DesiredVersionNotFound) { |
508 base::FilePath patch_source(installer::FindArchiveToPatch( | 509 base::FilePath patch_source(installer::FindArchiveToPatch( |
509 *original_state_, *installer_state_, base::Version("1.2.3.4"))); | 510 *original_state_, *installer_state_, base::Version("1.2.3.4"))); |
510 EXPECT_EQ(base::FilePath().value(), patch_source.value()); | 511 EXPECT_EQ(base::FilePath().value(), patch_source.value()); |
511 } | 512 } |
512 | 513 |
513 #if defined(GOOGLE_CHROME_BUILD) | 514 #if defined(GOOGLE_CHROME_BUILD) |
514 namespace { | 515 namespace { |
| 516 |
515 const bool kSystemLevel = false; | 517 const bool kSystemLevel = false; |
516 const HKEY kRootKey = kSystemLevel ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 518 const HKEY kRootKey = kSystemLevel ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
517 const wchar_t kVersionString[] = L"30.0.1574.0"; | 519 const wchar_t kVersionString[] = L"30.0.1574.0"; |
518 const wchar_t kMultiChannel[] = L"2.0-dev-multi-chromeframe"; | 520 const wchar_t kMultiChannel[] = L"2.0-dev-multi-chromeframe"; |
519 | 521 |
520 class MigrateMultiToSingleTest : public testing::Test { | 522 class MigrateMultiToSingleTest : public testing::Test { |
521 protected: | 523 protected: |
522 void SetUp() override { | 524 void SetUp() override { |
523 registry_override_manager_.OverrideRegistry(kRootKey); | 525 registry_override_manager_.OverrideRegistry(kRootKey); |
524 } | 526 } |
525 | 527 |
526 private: | 528 private: |
527 registry_util::RegistryOverrideManager registry_override_manager_; | 529 registry_util::RegistryOverrideManager registry_override_manager_; |
528 }; | 530 }; |
| 531 |
529 } // namespace | 532 } // namespace |
530 | 533 |
531 // Test migrating Chrome Frame from multi to single. | 534 // Test migrating Chrome Frame from multi to single. |
532 TEST_F(MigrateMultiToSingleTest, ChromeFrame) { | 535 TEST_F(MigrateMultiToSingleTest, ChromeFrame) { |
533 installer::ProductState chrome_frame; | 536 installer::ProductState chrome_frame; |
534 installer::ProductState binaries; | 537 installer::ProductState binaries; |
535 DWORD usagestats = 0; | 538 DWORD usagestats = 0; |
536 | 539 |
537 // Set up a config with dev-channel multi-install GCF. | 540 // Set up a config with dev-channel multi-install GCF. |
538 base::win::RegKey key; | 541 base::win::RegKey key; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 BrowserDistribution::CHROME_FRAME)); | 581 BrowserDistribution::CHROME_FRAME)); |
579 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats)); | 582 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats)); |
580 EXPECT_EQ(1U, usagestats); | 583 EXPECT_EQ(1U, usagestats); |
581 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value()); | 584 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value()); |
582 | 585 |
583 // Confirm that the binaries' channel no longer contains GCF. | 586 // Confirm that the binaries' channel no longer contains GCF. |
584 ASSERT_TRUE(binaries.Initialize(kSystemLevel, | 587 ASSERT_TRUE(binaries.Initialize(kSystemLevel, |
585 BrowserDistribution::CHROME_BINARIES)); | 588 BrowserDistribution::CHROME_BINARIES)); |
586 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value()); | 589 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value()); |
587 } | 590 } |
588 #endif | 591 #endif // GOOGLE_CHROME_BUILD |
589 | 592 |
590 TEST(SetupUtilTest, ContainsUnsupportedSwitch) { | 593 TEST(SetupUtilTest, ContainsUnsupportedSwitch) { |
591 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( | 594 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( |
592 base::CommandLine::FromString(L"foo.exe"))); | 595 base::CommandLine::FromString(L"foo.exe"))); |
593 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( | 596 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( |
594 base::CommandLine::FromString(L"foo.exe --multi-install --chrome"))); | 597 base::CommandLine::FromString(L"foo.exe --multi-install --chrome"))); |
595 EXPECT_TRUE(installer::ContainsUnsupportedSwitch( | 598 EXPECT_TRUE(installer::ContainsUnsupportedSwitch( |
596 base::CommandLine::FromString(L"foo.exe --chrome-frame"))); | 599 base::CommandLine::FromString(L"foo.exe --chrome-frame"))); |
597 } | 600 } |
598 | 601 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 714 } |
712 } | 715 } |
713 | 716 |
714 // Ensure that all values are absent. | 717 // Ensure that all values are absent. |
715 { | 718 { |
716 base::win::RegistryValueIterator it(root_, path_.c_str()); | 719 base::win::RegistryValueIterator it(root_, path_.c_str()); |
717 ASSERT_EQ(0u, it.ValueCount()); | 720 ASSERT_EQ(0u, it.ValueCount()); |
718 } | 721 } |
719 } | 722 } |
720 | 723 |
| 724 class LegacyCleanupsTest : public ::testing::Test { |
| 725 protected: |
| 726 LegacyCleanupsTest() = default; |
| 727 void SetUp() override { |
| 728 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 729 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
| 730 installer_state_ = |
| 731 base::MakeUnique<FakeInstallerState>(temp_dir_.GetPath()); |
| 732 // Create the state to be cleared. |
| 733 ASSERT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, |
| 734 KEY_WRITE | KEY_WOW64_32KEY) |
| 735 .Valid()); |
| 736 #if defined(GOOGLE_CHROME_BUILD) |
| 737 ASSERT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, |
| 738 KEY_WRITE | KEY_WOW64_32KEY) |
| 739 .Valid()); |
| 740 ASSERT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, |
| 741 KEY_WRITE | KEY_WOW64_32KEY) |
| 742 .Valid()); |
| 743 ASSERT_GT(base::WriteFile(GetAppHostExePath(), "cha", 3), 0); |
| 744 ASSERT_TRUE( |
| 745 base::win::RegKey(HKEY_CURRENT_USER, |
| 746 GetChromeAppCommandPath(L"install-extension").c_str(), |
| 747 KEY_WRITE | KEY_WOW64_32KEY) |
| 748 .Valid()); |
| 749 #endif // GOOGLE_CHROME_BUILD |
| 750 } |
| 751 |
| 752 const InstallerState& installer_state() const { return *installer_state_; } |
| 753 |
| 754 bool HasBinariesVersionKey() const { |
| 755 return base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, |
| 756 KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| 757 .Valid(); |
| 758 } |
| 759 |
| 760 #if defined(GOOGLE_CHROME_BUILD) |
| 761 bool HasMultiGCFVersionKey() const { |
| 762 return base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, |
| 763 KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| 764 .Valid(); |
| 765 } |
| 766 |
| 767 bool HasAppLauncherVersionKey() const { |
| 768 return base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, |
| 769 KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| 770 .Valid(); |
| 771 } |
| 772 |
| 773 bool HasAppHostExe() const { return base::PathExists(GetAppHostExePath()); } |
| 774 |
| 775 bool HasInstallExtensionCommand() const { |
| 776 return base::win::RegKey( |
| 777 HKEY_CURRENT_USER, |
| 778 GetChromeAppCommandPath(L"install-extension").c_str(), |
| 779 KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| 780 .Valid(); |
| 781 } |
| 782 #endif // GOOGLE_CHROME_BUILD |
| 783 |
| 784 private: |
| 785 // An InstallerState for a per-user install of Chrome in a given directory. |
| 786 class FakeInstallerState : public InstallerState { |
| 787 public: |
| 788 explicit FakeInstallerState(const base::FilePath& target_path) { |
| 789 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 790 operation_ = InstallerState::SINGLE_INSTALL_OR_UPDATE; |
| 791 target_path_ = target_path; |
| 792 state_key_ = dist->GetStateKey(); |
| 793 state_type_ = dist->GetType(); |
| 794 product_ = base::MakeUnique<Product>(dist); |
| 795 level_ = InstallerState::USER_LEVEL; |
| 796 root_key_ = HKEY_CURRENT_USER; |
| 797 } |
| 798 }; |
| 799 |
| 800 #if defined(GOOGLE_CHROME_BUILD) |
| 801 base::FilePath GetAppHostExePath() const { |
| 802 return installer_state_->target_path().AppendASCII("app_host.exe"); |
| 803 } |
| 804 |
| 805 base::string16 GetChromeAppCommandPath(const wchar_t* command) const { |
| 806 return base::string16( |
| 807 L"SOFTWARE\\Google\\Update\\Clients\\" |
| 808 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}\\Commands\\") + |
| 809 command; |
| 810 } |
| 811 #endif // GOOGLE_CHROME_BUILD |
| 812 |
| 813 static const wchar_t kBinariesClientsKeyPath[]; |
| 814 #if defined(GOOGLE_CHROME_BUILD) |
| 815 static const wchar_t kGCFClientsKeyPath[]; |
| 816 static const wchar_t kAppLauncherClientsKeyPath[]; |
| 817 #endif |
| 818 |
| 819 base::ScopedTempDir temp_dir_; |
| 820 registry_util::RegistryOverrideManager registry_override_manager_; |
| 821 std::unique_ptr<FakeInstallerState> installer_state_; |
| 822 DISALLOW_COPY_AND_ASSIGN(LegacyCleanupsTest); |
| 823 }; |
| 824 |
| 825 #if defined(GOOGLE_CHROME_BUILD) |
| 826 const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = |
| 827 L"SOFTWARE\\Google\\Update\\Clients\\" |
| 828 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| 829 const wchar_t LegacyCleanupsTest::kGCFClientsKeyPath[] = |
| 830 L"SOFTWARE\\Google\\Update\\Clients\\" |
| 831 L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; |
| 832 const wchar_t LegacyCleanupsTest::kAppLauncherClientsKeyPath[] = |
| 833 L"SOFTWARE\\Google\\Update\\Clients\\" |
| 834 L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}"; |
| 835 #else // GOOGLE_CHROME_BUILD |
| 836 const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = |
| 837 L"SOFTWARE\\Chromium Binaries"; |
| 838 #endif // !GOOGLE_CHROME_BUILD |
| 839 |
| 840 TEST_F(LegacyCleanupsTest, NoOpOnFailedUpdate) { |
| 841 DoLegacyCleanups(installer_state(), INSTALL_FAILED); |
| 842 EXPECT_TRUE(HasBinariesVersionKey()); |
| 843 #if defined(GOOGLE_CHROME_BUILD) |
| 844 EXPECT_TRUE(HasMultiGCFVersionKey()); |
| 845 EXPECT_TRUE(HasAppLauncherVersionKey()); |
| 846 EXPECT_TRUE(HasAppHostExe()); |
| 847 EXPECT_TRUE(HasInstallExtensionCommand()); |
| 848 #endif // GOOGLE_CHROME_BUILD |
| 849 } |
| 850 |
| 851 TEST_F(LegacyCleanupsTest, Do) { |
| 852 DoLegacyCleanups(installer_state(), NEW_VERSION_UPDATED); |
| 853 EXPECT_FALSE(HasBinariesVersionKey()); |
| 854 #if defined(GOOGLE_CHROME_BUILD) |
| 855 EXPECT_FALSE(HasMultiGCFVersionKey()); |
| 856 EXPECT_FALSE(HasAppLauncherVersionKey()); |
| 857 EXPECT_FALSE(HasAppHostExe()); |
| 858 EXPECT_FALSE(HasInstallExtensionCommand()); |
| 859 #endif // GOOGLE_CHROME_BUILD |
| 860 } |
| 861 |
721 } // namespace installer | 862 } // namespace installer |
OLD | NEW |