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 "chrome/installer/util/install_util.h" | 5 #include "chrome/installer/util/install_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/test/scoped_path_override.h" | 18 #include "base/test/scoped_path_override.h" |
| 19 #include "base/test/test_reg_util_win.h" | 19 #include "base/test/test_reg_util_win.h" |
| 20 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
| 21 #include "chrome/installer/util/google_update_constants.h" | 21 #include "chrome/installer/util/google_update_constants.h" |
| 22 #include "chrome/installer/util/test_app_registration_data.h" | |
| 22 #include "chrome/installer/util/work_item.h" | 23 #include "chrome/installer/util/work_item.h" |
| 24 #include "chrome/installer/util/work_item_list.h" | |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| 26 using base::win::RegKey; | 28 using base::win::RegKey; |
| 27 using ::testing::_; | 29 using ::testing::_; |
| 28 using ::testing::Return; | 30 using ::testing::Return; |
| 29 using ::testing::StrEq; | 31 using ::testing::StrEq; |
| 30 | 32 |
| 31 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { | 33 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { |
| 32 public: | 34 public: |
| 33 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); | 35 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); |
| 34 }; | 36 }; |
| 35 | 37 |
| 38 class TestBrowserDistribution : public BrowserDistribution { | |
| 39 public: | |
| 40 TestBrowserDistribution() | |
| 41 : BrowserDistribution(CHROME_BROWSER, | |
| 42 std::unique_ptr<AppRegistrationData>( | |
| 43 new TestAppRegistrationData())) {} | |
| 44 }; | |
| 45 | |
| 36 class InstallUtilTest : public testing::Test { | 46 class InstallUtilTest : public testing::Test { |
| 37 protected: | 47 protected: |
| 38 InstallUtilTest() {} | 48 InstallUtilTest() {} |
| 39 | 49 |
| 40 void SetUp() override { | 50 void SetUp() override { |
| 41 ResetRegistryOverrides(); | 51 ResetRegistryOverrides(); |
| 42 } | 52 } |
| 43 | 53 |
| 44 void ResetRegistryOverrides() { | 54 void ResetRegistryOverrides() { |
| 45 registry_override_manager_.reset( | 55 registry_override_manager_.reset( |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 #if defined(_WIN64) | 523 #if defined(_WIN64) |
| 514 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; | 524 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; |
| 515 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); | 525 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); |
| 516 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); | 526 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); |
| 517 some_exe = some_exe.AppendASCII("Company") | 527 some_exe = some_exe.AppendASCII("Company") |
| 518 .AppendASCII("Product") | 528 .AppendASCII("Product") |
| 519 .AppendASCII("product.exe"); | 529 .AppendASCII("product.exe"); |
| 520 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); | 530 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); |
| 521 #endif // defined(_WIN64) | 531 #endif // defined(_WIN64) |
| 522 } | 532 } |
| 533 | |
| 534 TEST_F(InstallUtilTest, AddDowngradeVersion) { | |
| 535 TestBrowserDistribution dist; | |
| 536 bool system_install = true; | |
| 537 RegKey(HKEY_LOCAL_MACHINE, dist.GetStateKey().c_str(), | |
| 538 KEY_SET_VALUE | KEY_WOW64_32KEY); | |
| 539 std::unique_ptr<WorkItemList> list; | |
| 540 | |
| 541 base::Version current_version("1.1.1.1"); | |
| 542 base::Version higer_new_version("1.1.1.2"); | |
| 543 base::Version lower_new_version_1("1.1.1.0"); | |
| 544 base::Version lower_new_version_2("1.1.0.0"); | |
| 545 | |
| 546 ASSERT_FALSE( | |
| 547 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | |
| 548 | |
| 549 // Upgrade should not create the value. | |
| 550 list.reset((WorkItem::CreateWorkItemList())); | |
|
grt (UTC plus 2)
2016/05/20 18:17:05
nit: remove spurious parens
zmin
2016/05/20 19:11:22
Done.
| |
| 551 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 552 system_install, ¤t_version, higer_new_version, &dist, list.get()); | |
| 553 ASSERT_TRUE(list->Do()); | |
| 554 ASSERT_FALSE( | |
| 555 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | |
| 556 | |
| 557 // Downgrade should create the value. | |
| 558 list.reset(WorkItem::CreateWorkItemList()); | |
| 559 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 560 system_install, ¤t_version, lower_new_version_1, &dist, list.get()); | |
| 561 ASSERT_TRUE(list->Do()); | |
| 562 EXPECT_EQ(current_version, | |
| 563 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 564 | |
| 565 // Multiple downgrads should not change the value. | |
|
grt (UTC plus 2)
2016/05/20 18:17:05
downgrades
zmin
2016/05/20 19:11:21
Done.
| |
| 566 list.reset(WorkItem::CreateWorkItemList()); | |
| 567 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 568 system_install, &lower_new_version_1, lower_new_version_2, &dist, | |
| 569 list.get()); | |
| 570 ASSERT_TRUE(list->Do()); | |
| 571 EXPECT_EQ(current_version, | |
| 572 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 573 } | |
| 574 | |
| 575 TEST_F(InstallUtilTest, DeleteDowngradeVersion) { | |
| 576 TestBrowserDistribution dist; | |
| 577 bool system_install = true; | |
| 578 RegKey(HKEY_LOCAL_MACHINE, dist.GetStateKey().c_str(), | |
| 579 KEY_SET_VALUE | KEY_WOW64_32KEY); | |
| 580 std::unique_ptr<WorkItemList> list; | |
| 581 | |
| 582 base::Version current_version("1.1.1.1"); | |
| 583 base::Version higer_new_version("1.1.1.2"); | |
| 584 base::Version lower_new_version_1("1.1.1.0"); | |
| 585 base::Version lower_new_version_2("1.1.0.0"); | |
| 586 | |
| 587 list.reset(WorkItem::CreateWorkItemList()); | |
| 588 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 589 system_install, ¤t_version, lower_new_version_2, &dist, list.get()); | |
| 590 ASSERT_TRUE(list->Do()); | |
| 591 EXPECT_EQ(current_version, | |
| 592 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 593 | |
| 594 // Upgrade should not delete the value if it still lower than the version that | |
| 595 // downgrade from. | |
| 596 list.reset(WorkItem::CreateWorkItemList()); | |
| 597 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 598 system_install, &lower_new_version_2, lower_new_version_1, &dist, | |
| 599 list.get()); | |
| 600 ASSERT_TRUE(list->Do()); | |
| 601 EXPECT_EQ(current_version, | |
| 602 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 603 | |
| 604 // Repair should not delete the value. | |
| 605 list.reset(WorkItem::CreateWorkItemList()); | |
| 606 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 607 system_install, &lower_new_version_1, lower_new_version_1, &dist, | |
| 608 list.get()); | |
| 609 ASSERT_TRUE(list->Do()); | |
| 610 EXPECT_EQ(current_version, | |
| 611 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 612 | |
| 613 // Fully upgrade should delete the value. | |
| 614 list.reset(WorkItem::CreateWorkItemList()); | |
| 615 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 616 system_install, &lower_new_version_1, higer_new_version, &dist, | |
| 617 list.get()); | |
| 618 ASSERT_TRUE(list->Do()); | |
| 619 ASSERT_FALSE( | |
| 620 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | |
| 621 | |
| 622 // Fresh install should delete the value if exist | |
|
grt (UTC plus 2)
2016/05/20 18:17:05
nit: "it exists."
zmin
2016/05/20 19:11:21
Done.
| |
| 623 list.reset(WorkItem::CreateWorkItemList()); | |
| 624 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 625 system_install, ¤t_version, lower_new_version_2, &dist, list.get()); | |
| 626 ASSERT_TRUE(list->Do()); | |
| 627 EXPECT_EQ(current_version, | |
| 628 InstallUtil::GetDowngradeVersion(system_install, &dist)); | |
| 629 list.reset(WorkItem::CreateWorkItemList()); | |
| 630 InstallUtil::AddUpdateDowngradeVersionItem( | |
| 631 system_install, nullptr, lower_new_version_1, &dist, list.get()); | |
| 632 ASSERT_TRUE(list->Do()); | |
| 633 ASSERT_FALSE( | |
| 634 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | |
| 635 } | |
| OLD | NEW |