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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 } | 712 } |
712 } | 713 } |
713 | 714 |
714 // Ensure that all values are absent. | 715 // Ensure that all values are absent. |
715 { | 716 { |
716 base::win::RegistryValueIterator it(root_, path_.c_str()); | 717 base::win::RegistryValueIterator it(root_, path_.c_str()); |
717 ASSERT_EQ(0u, it.ValueCount()); | 718 ASSERT_EQ(0u, it.ValueCount()); |
718 } | 719 } |
719 } | 720 } |
720 | 721 |
722 class LegacyCleanupsTest : public ::testing::Test { | |
723 protected: | |
724 LegacyCleanupsTest() { | |
725 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
huangs
2017/01/06 17:57:18
NIT: Semantically, temp dir is part of test fixtur
grt (UTC plus 2)
2017/01/06 21:15:47
Done.
| |
726 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | |
727 installer_state_ = | |
728 base::MakeUnique<FakeInstallerState>(temp_dir_.GetPath()); | |
729 // Create the state to be cleared. | |
730 EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, | |
731 KEY_WRITE | KEY_WOW64_32KEY) | |
732 .Valid()); | |
733 #if defined(GOOGLE_CHROME_BUILD) | |
734 EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, | |
735 KEY_WRITE | KEY_WOW64_32KEY) | |
736 .Valid()); | |
737 EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, | |
738 KEY_WRITE | KEY_WOW64_32KEY) | |
739 .Valid()); | |
740 EXPECT_GT(base::WriteFile(GetAppHostExePath(), "cha", 3), 0); | |
huangs
2017/01/06 17:57:18
NIT: base::WriteFile() returns the number of bytes
grt (UTC plus 2)
2017/01/06 21:15:47
I chose GT 0 since the test only cares that the fi
| |
741 EXPECT_TRUE( | |
742 base::win::RegKey(HKEY_CURRENT_USER, | |
743 GetChromeAppCommandPath(L"install-extension").c_str(), | |
744 KEY_WRITE | KEY_WOW64_32KEY) | |
745 .Valid()); | |
746 | |
747 #endif | |
huangs
2017/01/06 17:57:18
#endif // GOOGLE_CHROME_BUILD
Same below.
grt (UTC plus 2)
2017/01/06 21:15:47
Done.
| |
748 } | |
749 | |
750 const InstallerState& installer_state() const { return *installer_state_; } | |
751 | |
752 bool HasBinariesVersionKey() const { | |
753 return base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, | |
754 KEY_QUERY_VALUE | KEY_WOW64_32KEY) | |
755 .Valid(); | |
756 } | |
757 | |
758 #if defined(GOOGLE_CHROME_BUILD) | |
759 bool HasMultiGCFVersionKey() const { | |
760 return base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, | |
761 KEY_QUERY_VALUE | KEY_WOW64_32KEY) | |
762 .Valid(); | |
763 } | |
764 | |
765 bool HasAppLauncherVersionKey() const { | |
766 return base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, | |
767 KEY_QUERY_VALUE | KEY_WOW64_32KEY) | |
768 .Valid(); | |
769 } | |
770 | |
771 bool HasAppHostExe() const { return base::PathExists(GetAppHostExePath()); } | |
772 | |
773 bool HasInstallExtensionCommand() const { | |
774 return base::win::RegKey( | |
775 HKEY_CURRENT_USER, | |
776 GetChromeAppCommandPath(L"install-extension").c_str(), | |
777 KEY_QUERY_VALUE | KEY_WOW64_32KEY) | |
778 .Valid(); | |
779 } | |
780 #endif | |
781 | |
782 private: | |
783 // An InstallerState for a per-user install of Chrome in a given directory. | |
784 class FakeInstallerState : public InstallerState { | |
785 public: | |
786 explicit FakeInstallerState(const base::FilePath& target_path) { | |
787 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
788 operation_ = InstallerState::SINGLE_INSTALL_OR_UPDATE; | |
789 target_path_ = target_path; | |
790 state_key_ = dist->GetStateKey(); | |
791 state_type_ = dist->GetType(); | |
792 product_ = base::MakeUnique<Product>(dist); | |
793 level_ = InstallerState::USER_LEVEL; | |
794 root_key_ = HKEY_CURRENT_USER; | |
795 } | |
796 }; | |
797 | |
798 #if defined(GOOGLE_CHROME_BUILD) | |
799 base::FilePath GetAppHostExePath() const { | |
800 return installer_state_->target_path().AppendASCII("app_host.exe"); | |
801 } | |
802 | |
803 base::string16 GetChromeAppCommandPath(const wchar_t* command) const { | |
804 return base::string16( | |
805 L"SOFTWARE\\Google\\Update\\Clients\\" | |
806 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}\\Commands\\") + | |
807 command; | |
808 } | |
809 #endif | |
810 | |
811 static const wchar_t kBinariesClientsKeyPath[]; | |
812 #if defined(GOOGLE_CHROME_BUILD) | |
813 static const wchar_t kGCFClientsKeyPath[]; | |
814 static const wchar_t kAppLauncherClientsKeyPath[]; | |
815 #endif | |
816 | |
817 base::ScopedTempDir temp_dir_; | |
818 registry_util::RegistryOverrideManager registry_override_manager_; | |
819 std::unique_ptr<FakeInstallerState> installer_state_; | |
820 DISALLOW_COPY_AND_ASSIGN(LegacyCleanupsTest); | |
821 }; | |
822 | |
823 #if defined(GOOGLE_CHROME_BUILD) | |
824 const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = | |
825 L"SOFTWARE\\Google\\Update\\Clients\\" | |
826 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
827 const wchar_t LegacyCleanupsTest::kGCFClientsKeyPath[] = | |
828 L"SOFTWARE\\Google\\Update\\Clients\\" | |
829 L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; | |
830 const wchar_t LegacyCleanupsTest::kAppLauncherClientsKeyPath[] = | |
831 L"SOFTWARE\\Google\\Update\\Clients\\" | |
832 L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}"; | |
833 #else | |
834 const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = | |
835 L"SOFTWARE\\Chromium Binaries"; | |
836 #endif | |
837 | |
838 TEST_F(LegacyCleanupsTest, NoOpOnFailedUpdate) { | |
839 DoLegacyCleanups(installer_state(), INSTALL_FAILED); | |
840 EXPECT_TRUE(HasBinariesVersionKey()); | |
841 #if defined(GOOGLE_CHROME_BUILD) | |
842 EXPECT_TRUE(HasMultiGCFVersionKey()); | |
843 EXPECT_TRUE(HasAppLauncherVersionKey()); | |
844 EXPECT_TRUE(HasAppHostExe()); | |
845 EXPECT_TRUE(HasInstallExtensionCommand()); | |
846 #endif | |
847 } | |
848 | |
849 TEST_F(LegacyCleanupsTest, Do) { | |
850 DoLegacyCleanups(installer_state(), NEW_VERSION_UPDATED); | |
851 EXPECT_FALSE(HasBinariesVersionKey()); | |
852 #if defined(GOOGLE_CHROME_BUILD) | |
853 EXPECT_FALSE(HasMultiGCFVersionKey()); | |
854 EXPECT_FALSE(HasAppLauncherVersionKey()); | |
855 EXPECT_FALSE(HasAppHostExe()); | |
856 EXPECT_FALSE(HasInstallExtensionCommand()); | |
857 #endif | |
858 } | |
859 | |
721 } // namespace installer | 860 } // namespace installer |
OLD | NEW |