Chromium Code Reviews| Index: chrome/installer/setup/setup_util_unittest.cc |
| diff --git a/chrome/installer/setup/setup_util_unittest.cc b/chrome/installer/setup/setup_util_unittest.cc |
| index a2d88cc4425581d8a8713404ea381ac6e284333a..9b9ea3b154a1fac9bce8c1fe50aab3d74803ee58 100644 |
| --- a/chrome/installer/setup/setup_util_unittest.cc |
| +++ b/chrome/installer/setup/setup_util_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/process/kill.h" |
| #include "base/process/launch.h" |
| #include "base/process/process_handle.h" |
| @@ -718,4 +719,142 @@ TEST_F(DeleteRegistryKeyPartialTest, NonEmptyKeyWithPreserve) { |
| } |
| } |
| +class LegacyCleanupsTest : public ::testing::Test { |
| + protected: |
| + LegacyCleanupsTest() { |
| + 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.
|
| + registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
| + installer_state_ = |
| + base::MakeUnique<FakeInstallerState>(temp_dir_.GetPath()); |
| + // Create the state to be cleared. |
| + EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, |
| + KEY_WRITE | KEY_WOW64_32KEY) |
| + .Valid()); |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, |
| + KEY_WRITE | KEY_WOW64_32KEY) |
| + .Valid()); |
| + EXPECT_TRUE(base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, |
| + KEY_WRITE | KEY_WOW64_32KEY) |
| + .Valid()); |
| + 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
|
| + EXPECT_TRUE( |
| + base::win::RegKey(HKEY_CURRENT_USER, |
| + GetChromeAppCommandPath(L"install-extension").c_str(), |
| + KEY_WRITE | KEY_WOW64_32KEY) |
| + .Valid()); |
| + |
| +#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.
|
| + } |
| + |
| + const InstallerState& installer_state() const { return *installer_state_; } |
| + |
| + bool HasBinariesVersionKey() const { |
| + return base::win::RegKey(HKEY_CURRENT_USER, kBinariesClientsKeyPath, |
| + KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| + .Valid(); |
| + } |
| + |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + bool HasMultiGCFVersionKey() const { |
| + return base::win::RegKey(HKEY_CURRENT_USER, kGCFClientsKeyPath, |
| + KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| + .Valid(); |
| + } |
| + |
| + bool HasAppLauncherVersionKey() const { |
| + return base::win::RegKey(HKEY_CURRENT_USER, kAppLauncherClientsKeyPath, |
| + KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| + .Valid(); |
| + } |
| + |
| + bool HasAppHostExe() const { return base::PathExists(GetAppHostExePath()); } |
| + |
| + bool HasInstallExtensionCommand() const { |
| + return base::win::RegKey( |
| + HKEY_CURRENT_USER, |
| + GetChromeAppCommandPath(L"install-extension").c_str(), |
| + KEY_QUERY_VALUE | KEY_WOW64_32KEY) |
| + .Valid(); |
| + } |
| +#endif |
| + |
| + private: |
| + // An InstallerState for a per-user install of Chrome in a given directory. |
| + class FakeInstallerState : public InstallerState { |
| + public: |
| + explicit FakeInstallerState(const base::FilePath& target_path) { |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + operation_ = InstallerState::SINGLE_INSTALL_OR_UPDATE; |
| + target_path_ = target_path; |
| + state_key_ = dist->GetStateKey(); |
| + state_type_ = dist->GetType(); |
| + product_ = base::MakeUnique<Product>(dist); |
| + level_ = InstallerState::USER_LEVEL; |
| + root_key_ = HKEY_CURRENT_USER; |
| + } |
| + }; |
| + |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + base::FilePath GetAppHostExePath() const { |
| + return installer_state_->target_path().AppendASCII("app_host.exe"); |
| + } |
| + |
| + base::string16 GetChromeAppCommandPath(const wchar_t* command) const { |
| + return base::string16( |
| + L"SOFTWARE\\Google\\Update\\Clients\\" |
| + L"{8A69D345-D564-463c-AFF1-A69D9E530F96}\\Commands\\") + |
| + command; |
| + } |
| +#endif |
| + |
| + static const wchar_t kBinariesClientsKeyPath[]; |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + static const wchar_t kGCFClientsKeyPath[]; |
| + static const wchar_t kAppLauncherClientsKeyPath[]; |
| +#endif |
| + |
| + base::ScopedTempDir temp_dir_; |
| + registry_util::RegistryOverrideManager registry_override_manager_; |
| + std::unique_ptr<FakeInstallerState> installer_state_; |
| + DISALLOW_COPY_AND_ASSIGN(LegacyCleanupsTest); |
| +}; |
| + |
| +#if defined(GOOGLE_CHROME_BUILD) |
| +const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = |
| + L"SOFTWARE\\Google\\Update\\Clients\\" |
| + L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| +const wchar_t LegacyCleanupsTest::kGCFClientsKeyPath[] = |
| + L"SOFTWARE\\Google\\Update\\Clients\\" |
| + L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; |
| +const wchar_t LegacyCleanupsTest::kAppLauncherClientsKeyPath[] = |
| + L"SOFTWARE\\Google\\Update\\Clients\\" |
| + L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}"; |
| +#else |
| +const wchar_t LegacyCleanupsTest::kBinariesClientsKeyPath[] = |
| + L"SOFTWARE\\Chromium Binaries"; |
| +#endif |
| + |
| +TEST_F(LegacyCleanupsTest, NoOpOnFailedUpdate) { |
| + DoLegacyCleanups(installer_state(), INSTALL_FAILED); |
| + EXPECT_TRUE(HasBinariesVersionKey()); |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_TRUE(HasMultiGCFVersionKey()); |
| + EXPECT_TRUE(HasAppLauncherVersionKey()); |
| + EXPECT_TRUE(HasAppHostExe()); |
| + EXPECT_TRUE(HasInstallExtensionCommand()); |
| +#endif |
| +} |
| + |
| +TEST_F(LegacyCleanupsTest, Do) { |
| + DoLegacyCleanups(installer_state(), NEW_VERSION_UPDATED); |
| + EXPECT_FALSE(HasBinariesVersionKey()); |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_FALSE(HasMultiGCFVersionKey()); |
| + EXPECT_FALSE(HasAppLauncherVersionKey()); |
| + EXPECT_FALSE(HasAppHostExe()); |
| + EXPECT_FALSE(HasInstallExtensionCommand()); |
| +#endif |
| +} |
| + |
| } // namespace installer |