| 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> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 // Test that we are parsing Chrome version correctly. | 91 // Test that we are parsing Chrome version correctly. |
| 92 TEST(SetupUtilTest, GetMaxVersionFromArchiveDirTest) { | 92 TEST(SetupUtilTest, GetMaxVersionFromArchiveDirTest) { |
| 93 // Create a version dir | 93 // Create a version dir |
| 94 base::ScopedTempDir test_dir; | 94 base::ScopedTempDir test_dir; |
| 95 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | 95 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| 96 base::FilePath chrome_dir = test_dir.path().AppendASCII("1.0.0.0"); | 96 base::FilePath chrome_dir = test_dir.path().AppendASCII("1.0.0.0"); |
| 97 base::CreateDirectory(chrome_dir); | 97 base::CreateDirectory(chrome_dir); |
| 98 ASSERT_TRUE(base::PathExists(chrome_dir)); | 98 ASSERT_TRUE(base::PathExists(chrome_dir)); |
| 99 std::unique_ptr<Version> version( | 99 std::unique_ptr<base::Version> version( |
| 100 installer::GetMaxVersionFromArchiveDir(test_dir.path())); | 100 installer::GetMaxVersionFromArchiveDir(test_dir.path())); |
| 101 ASSERT_EQ(version->GetString(), "1.0.0.0"); | 101 ASSERT_EQ(version->GetString(), "1.0.0.0"); |
| 102 | 102 |
| 103 base::DeleteFile(chrome_dir, true); | 103 base::DeleteFile(chrome_dir, true); |
| 104 ASSERT_FALSE(base::PathExists(chrome_dir)) << chrome_dir.value(); | 104 ASSERT_FALSE(base::PathExists(chrome_dir)) << chrome_dir.value(); |
| 105 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir.path()) == NULL); | 105 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir.path()) == NULL); |
| 106 | 106 |
| 107 chrome_dir = test_dir.path().AppendASCII("ABC"); | 107 chrome_dir = test_dir.path().AppendASCII("ABC"); |
| 108 base::CreateDirectory(chrome_dir); | 108 base::CreateDirectory(chrome_dir); |
| 109 ASSERT_TRUE(base::PathExists(chrome_dir)); | 109 ASSERT_TRUE(base::PathExists(chrome_dir)); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 protected: | 281 protected: |
| 282 class FakeInstallationState : public installer::InstallationState { | 282 class FakeInstallationState : public installer::InstallationState { |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 class FakeProductState : public installer::ProductState { | 285 class FakeProductState : public installer::ProductState { |
| 286 public: | 286 public: |
| 287 static FakeProductState* FromProductState(const ProductState* product) { | 287 static FakeProductState* FromProductState(const ProductState* product) { |
| 288 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); | 288 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void set_version(const Version& version) { | 291 void set_version(const base::Version& version) { |
| 292 if (version.IsValid()) | 292 if (version.IsValid()) |
| 293 version_.reset(new Version(version)); | 293 version_.reset(new base::Version(version)); |
| 294 else | 294 else |
| 295 version_.reset(); | 295 version_.reset(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void set_uninstall_command(const base::CommandLine& uninstall_command) { | 298 void set_uninstall_command(const base::CommandLine& uninstall_command) { |
| 299 uninstall_command_ = uninstall_command; | 299 uninstall_command_ = uninstall_command; |
| 300 } | 300 } |
| 301 }; | 301 }; |
| 302 | 302 |
| 303 FindArchiveToPatchTest() {} | 303 FindArchiveToPatchTest() {} |
| 304 | 304 |
| 305 void SetUp() override { | 305 void SetUp() override { |
| 306 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 306 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 307 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 307 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
| 308 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); | 308 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); |
| 309 product_version_ = Version("30.0.1559.0"); | 309 product_version_ = base::Version("30.0.1559.0"); |
| 310 max_version_ = Version("47.0.1559.0"); | 310 max_version_ = base::Version("47.0.1559.0"); |
| 311 | 311 |
| 312 // Install the product according to the version. | 312 // Install the product according to the version. |
| 313 original_state_.reset(new FakeInstallationState()); | 313 original_state_.reset(new FakeInstallationState()); |
| 314 InstallProduct(); | 314 InstallProduct(); |
| 315 | 315 |
| 316 // Prepare to update the product in the temp dir. | 316 // Prepare to update the product in the temp dir. |
| 317 installer_state_.reset(new installer::InstallerState( | 317 installer_state_.reset(new installer::InstallerState( |
| 318 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : | 318 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : |
| 319 installer::InstallerState::USER_LEVEL)); | 319 installer::InstallerState::USER_LEVEL)); |
| 320 installer_state_->AddProductFromState( | 320 installer_state_->AddProductFromState( |
| 321 kProductType_, | 321 kProductType_, |
| 322 *original_state_->GetProductState(kSystemInstall_, kProductType_)); | 322 *original_state_->GetProductState(kSystemInstall_, kProductType_)); |
| 323 | 323 |
| 324 // Create archives in the two version dirs. | 324 // Create archives in the two version dirs. |
| 325 ASSERT_TRUE( | 325 ASSERT_TRUE( |
| 326 base::CreateDirectory(GetProductVersionArchivePath().DirName())); | 326 base::CreateDirectory(GetProductVersionArchivePath().DirName())); |
| 327 ASSERT_EQ(1, base::WriteFile(GetProductVersionArchivePath(), "a", 1)); | 327 ASSERT_EQ(1, base::WriteFile(GetProductVersionArchivePath(), "a", 1)); |
| 328 ASSERT_TRUE( | 328 ASSERT_TRUE( |
| 329 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); | 329 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); |
| 330 ASSERT_EQ(1, base::WriteFile(GetMaxVersionArchivePath(), "b", 1)); | 330 ASSERT_EQ(1, base::WriteFile(GetMaxVersionArchivePath(), "b", 1)); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void TearDown() override { | 333 void TearDown() override { |
| 334 original_state_.reset(); | 334 original_state_.reset(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 base::FilePath GetArchivePath(const Version& version) const { | 337 base::FilePath GetArchivePath(const base::Version& version) const { |
| 338 return test_dir_.path() | 338 return test_dir_.path() |
| 339 .AppendASCII(version.GetString()) | 339 .AppendASCII(version.GetString()) |
| 340 .Append(installer::kInstallerDir) | 340 .Append(installer::kInstallerDir) |
| 341 .Append(installer::kChromeArchive); | 341 .Append(installer::kChromeArchive); |
| 342 } | 342 } |
| 343 | 343 |
| 344 base::FilePath GetMaxVersionArchivePath() const { | 344 base::FilePath GetMaxVersionArchivePath() const { |
| 345 return GetArchivePath(max_version_); | 345 return GetArchivePath(max_version_); |
| 346 } | 346 } |
| 347 | 347 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 361 .Append(installer::kInstallerDir) | 361 .Append(installer::kInstallerDir) |
| 362 .Append(installer::kSetupExe)); | 362 .Append(installer::kSetupExe)); |
| 363 uninstall_command.AppendSwitch(installer::switches::kUninstall); | 363 uninstall_command.AppendSwitch(installer::switches::kUninstall); |
| 364 product->set_uninstall_command(uninstall_command); | 364 product->set_uninstall_command(uninstall_command); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void UninstallProduct() { | 367 void UninstallProduct() { |
| 368 FakeProductState::FromProductState( | 368 FakeProductState::FromProductState( |
| 369 original_state_->GetNonVersionedProductState(kSystemInstall_, | 369 original_state_->GetNonVersionedProductState(kSystemInstall_, |
| 370 kProductType_)) | 370 kProductType_)) |
| 371 ->set_version(Version()); | 371 ->set_version(base::Version()); |
| 372 } | 372 } |
| 373 | 373 |
| 374 static const bool kSystemInstall_; | 374 static const bool kSystemInstall_; |
| 375 static const BrowserDistribution::Type kProductType_; | 375 static const BrowserDistribution::Type kProductType_; |
| 376 base::ScopedTempDir test_dir_; | 376 base::ScopedTempDir test_dir_; |
| 377 Version product_version_; | 377 base::Version product_version_; |
| 378 Version max_version_; | 378 base::Version max_version_; |
| 379 std::unique_ptr<FakeInstallationState> original_state_; | 379 std::unique_ptr<FakeInstallationState> original_state_; |
| 380 std::unique_ptr<installer::InstallerState> installer_state_; | 380 std::unique_ptr<installer::InstallerState> installer_state_; |
| 381 | 381 |
| 382 private: | 382 private: |
| 383 registry_util::RegistryOverrideManager registry_override_manager_; | 383 registry_util::RegistryOverrideManager registry_override_manager_; |
| 384 | 384 |
| 385 DISALLOW_COPY_AND_ASSIGN(FindArchiveToPatchTest); | 385 DISALLOW_COPY_AND_ASSIGN(FindArchiveToPatchTest); |
| 386 }; | 386 }; |
| 387 | 387 |
| 388 const bool FindArchiveToPatchTest::kSystemInstall_ = false; | 388 const bool FindArchiveToPatchTest::kSystemInstall_ = false; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 } | 643 } |
| 644 | 644 |
| 645 // Ensure that all values are absent. | 645 // Ensure that all values are absent. |
| 646 { | 646 { |
| 647 base::win::RegistryValueIterator it(root_, path_.c_str()); | 647 base::win::RegistryValueIterator it(root_, path_.c_str()); |
| 648 ASSERT_EQ(0u, it.ValueCount()); | 648 ASSERT_EQ(0u, it.ValueCount()); |
| 649 } | 649 } |
| 650 } | 650 } |
| 651 | 651 |
| 652 } // namespace installer | 652 } // namespace installer |
| OLD | NEW |