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/install_worker.h" | 5 #include "chrome/installer/setup/install_worker.h" |
6 | 6 |
7 #include "base/test/test_reg_util_win.h" | |
8 #include "base/version.h" | |
7 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
8 #include "base/version.h" | |
9 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
10 #include "chrome/installer/setup/setup_util.h" | 11 #include "chrome/installer/setup/setup_util.h" |
12 #include "chrome/installer/util/create_reg_key_work_item.h" | |
11 #include "chrome/installer/util/delete_reg_key_work_item.h" | 13 #include "chrome/installer/util/delete_reg_key_work_item.h" |
12 #include "chrome/installer/util/create_reg_key_work_item.h" | 14 #include "chrome/installer/util/google_update_constants.h" |
13 #include "chrome/installer/util/helper.h" | 15 #include "chrome/installer/util/helper.h" |
14 #include "chrome/installer/util/google_update_constants.h" | 16 #include "chrome/installer/util/install_util.h" |
15 #include "chrome/installer/util/installation_state.h" | 17 #include "chrome/installer/util/installation_state.h" |
16 #include "chrome/installer/util/installer_state.h" | 18 #include "chrome/installer/util/installer_state.h" |
17 #include "chrome/installer/util/set_reg_value_work_item.h" | 19 #include "chrome/installer/util/set_reg_value_work_item.h" |
18 #include "chrome/installer/util/util_constants.h" | 20 #include "chrome/installer/util/util_constants.h" |
21 #include "chrome/installer/util/work_item.h" | |
19 #include "chrome/installer/util/work_item_list.h" | 22 #include "chrome/installer/util/work_item_list.h" |
20 | 23 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | |
23 | 25 |
24 using base::win::RegKey; | 26 using base::win::RegKey; |
25 using installer::InstallationState; | 27 using installer::InstallationState; |
26 using installer::InstallerState; | 28 using installer::InstallerState; |
27 using installer::Product; | 29 using installer::Product; |
28 using installer::ProductState; | 30 using installer::ProductState; |
29 | 31 |
30 using ::testing::_; | 32 using ::testing::_; |
31 using ::testing::AtLeast; | 33 using ::testing::AtLeast; |
32 using ::testing::AtMost; | 34 using ::testing::AtMost; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 void set_package_type(PackageType type) { | 161 void set_package_type(PackageType type) { |
160 InstallerState::set_package_type(type); | 162 InstallerState::set_package_type(type); |
161 } | 163 } |
162 }; | 164 }; |
163 | 165 |
164 // The test fixture | 166 // The test fixture |
165 //------------------------------------------------------------------------------ | 167 //------------------------------------------------------------------------------ |
166 | 168 |
167 class InstallWorkerTest : public testing::Test { | 169 class InstallWorkerTest : public testing::Test { |
168 public: | 170 public: |
171 InstallWorkerTest() {} | |
172 | |
169 void SetUp() override { | 173 void SetUp() override { |
174 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | |
175 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); | |
176 | |
170 current_version_.reset(new Version("1.0.0.0")); | 177 current_version_.reset(new Version("1.0.0.0")); |
171 new_version_.reset(new Version("42.0.0.0")); | 178 new_version_.reset(new Version("42.0.0.0")); |
172 | 179 |
173 // Don't bother ensuring that these paths exist. Since we're just | 180 // Don't bother ensuring that these paths exist. Since we're just |
174 // building the work item lists and not running them, they shouldn't | 181 // building the work item lists and not running them, they shouldn't |
175 // actually be touched. | 182 // actually be touched. |
176 archive_path_ = | 183 archive_path_ = |
177 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); | 184 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); |
178 // TODO(robertshield): Take this from the BrowserDistribution once that | 185 // TODO(robertshield): Take this from the BrowserDistribution once that |
179 // no longer depends on MasterPreferences. | 186 // no longer depends on MasterPreferences. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 } | 424 } |
418 | 425 |
419 protected: | 426 protected: |
420 scoped_ptr<Version> current_version_; | 427 scoped_ptr<Version> current_version_; |
421 scoped_ptr<Version> new_version_; | 428 scoped_ptr<Version> new_version_; |
422 base::FilePath archive_path_; | 429 base::FilePath archive_path_; |
423 base::FilePath installation_path_; | 430 base::FilePath installation_path_; |
424 base::FilePath setup_path_; | 431 base::FilePath setup_path_; |
425 base::FilePath src_path_; | 432 base::FilePath src_path_; |
426 base::FilePath temp_dir_; | 433 base::FilePath temp_dir_; |
434 | |
435 private: | |
436 registry_util::RegistryOverrideManager registry_override_manager_; | |
437 | |
438 DISALLOW_COPY_AND_ASSIGN(InstallWorkerTest); | |
427 }; | 439 }; |
428 | 440 |
429 // Tests | 441 // Tests |
430 //------------------------------------------------------------------------------ | 442 //------------------------------------------------------------------------------ |
431 | 443 |
432 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) { | 444 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) { |
433 const bool system_level = true; | 445 const bool system_level = true; |
434 const bool multi_install = false; | 446 const bool multi_install = false; |
435 MockWorkItemList work_item_list; | 447 MockWorkItemList work_item_list; |
436 | 448 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 AddDeleteRegValueWorkItem( | 676 AddDeleteRegValueWorkItem( |
665 Eq(installer_state->root_key()), | 677 Eq(installer_state->root_key()), |
666 StrEq(chrome_dist->GetStateKey()), | 678 StrEq(chrome_dist->GetStateKey()), |
667 StrEq(google_update::kRegUsageStatsField))).Times(1); | 679 StrEq(google_update::kRegUsageStatsField))).Times(1); |
668 | 680 |
669 AddUsageStatsWorkItems(*installation_state.get(), | 681 AddUsageStatsWorkItems(*installation_state.get(), |
670 *installer_state.get(), | 682 *installer_state.get(), |
671 &work_item_list); | 683 &work_item_list); |
672 } | 684 } |
673 | 685 |
686 // Test that active setup version installing/updating is handled property. | |
687 TEST_F(InstallWorkerTest, AddAndRunActiveSetupWorkItems) { | |
688 // Active Setup only makes sense at system-level. | |
689 const bool system_level = true; | |
690 const bool multi_install = false; | |
691 | |
692 scoped_ptr<MockInstallationState> installation_state( | |
693 BuildChromeInstallationState(system_level, multi_install)); | |
694 | |
695 MockProductState chrome_state; | |
696 chrome_state.set_version(new Version(*current_version_)); | |
697 chrome_state.set_multi_install(multi_install); | |
698 | |
699 installation_state->SetProductState( | |
700 system_level, BrowserDistribution::CHROME_BROWSER, chrome_state); | |
701 | |
702 scoped_ptr<MockInstallerState> installer_state( | |
703 BuildChromeInstallerState(system_level, multi_install, | |
704 *installation_state, | |
705 InstallerState::MULTI_INSTALL)); | |
706 | |
707 enum class TestCaseStep { | |
grt (UTC plus 2)
2015/06/30 18:54:49
this all seems pretty complicated. does it all boi
gab
2015/07/02 03:12:33
Good point, at first I didn't like having to go th
| |
708 // Executes the Active Setup work items. | |
709 EXECUTE, | |
710 // Expect a given value for the Active Setup version in the registry. | |
711 EXPECT_VERSION, | |
712 // Set a specific value for the Active Setup version in the registry. | |
713 SET_VERSION, | |
714 }; | |
715 | |
716 struct TestCaseSteps { | |
717 TestCaseStep step; | |
718 const wchar_t* step_value; | |
719 } static const kTestCaseSteps[] = { | |
720 // Execute the work items twice, once to confirm it works initially when | |
721 // nothing is there and a second time to confirm the no-op update works as | |
722 // intended. | |
723 {TestCaseStep::EXECUTE}, | |
724 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
725 | |
726 {TestCaseStep::EXECUTE}, | |
727 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
728 | |
729 // Write a different version and expect that only the major component of | |
730 // the version gets updated. | |
731 {TestCaseStep::SET_VERSION, L"24,1,2,3"}, | |
732 {TestCaseStep::EXECUTE}, | |
733 {TestCaseStep::EXPECT_VERSION, L"43,1,2,3"}, | |
734 | |
735 // Try a few invalid Version entries, expect them all to be reset to the | |
736 // default version. | |
737 {TestCaseStep::SET_VERSION, L"zzz"}, | |
738 {TestCaseStep::EXECUTE}, | |
739 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
740 | |
741 {TestCaseStep::SET_VERSION, L"1,2"}, | |
742 {TestCaseStep::EXECUTE}, | |
743 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
744 | |
745 {TestCaseStep::SET_VERSION, L"43,1,2,3,10"}, | |
746 {TestCaseStep::EXECUTE}, | |
747 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
748 | |
749 {TestCaseStep::SET_VERSION, L""}, | |
750 {TestCaseStep::EXECUTE}, | |
751 {TestCaseStep::EXPECT_VERSION, L"43,0,0,0"}, | |
752 }; | |
753 | |
754 const HKEY kRoot = HKEY_LOCAL_MACHINE; | |
755 const std::wstring active_setup_path(InstallUtil::GetActiveSetupPath( | |
756 BrowserDistribution::GetSpecificDistribution( | |
757 BrowserDistribution::CHROME_BROWSER))); | |
758 RegKey test_key; | |
759 | |
760 EXPECT_NE(ERROR_SUCCESS, | |
761 test_key.Open(kRoot, active_setup_path.c_str(), KEY_READ)); | |
762 | |
763 for (size_t i = 0; i < arraysize(kTestCaseSteps); ++i) { | |
764 SCOPED_TRACE(i); | |
grt (UTC plus 2)
2015/06/30 18:54:49
kewl
gab
2015/07/02 03:12:33
Yep :-)
| |
765 | |
766 switch (kTestCaseSteps[i].step) { | |
767 case TestCaseStep::EXECUTE: { | |
768 // Note: This performs real operations, it's *not* a MockWorkItemList | |
769 // like in the other tests (the registry itself is mocked in the fixture | |
770 // however so this is okay). | |
771 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | |
772 AddActiveSetupWorkItems( | |
773 *installer_state, *current_version_, | |
774 *installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER), | |
775 work_item_list.get()); | |
776 work_item_list->Do(); | |
777 break; | |
778 } | |
779 | |
780 case TestCaseStep::EXPECT_VERSION: { | |
781 std::wstring version_out; | |
782 EXPECT_EQ(ERROR_SUCCESS, | |
783 test_key.Open(kRoot, active_setup_path.c_str(), KEY_READ)); | |
784 EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &version_out)); | |
785 EXPECT_EQ(kTestCaseSteps[i].step_value, version_out); | |
786 break; | |
787 } | |
788 | |
789 case TestCaseStep::SET_VERSION: { | |
790 EXPECT_EQ(ERROR_SUCCESS, test_key.Open(kRoot, active_setup_path.c_str(), | |
791 KEY_READ | KEY_SET_VALUE)); | |
792 EXPECT_EQ(ERROR_SUCCESS, test_key.WriteValue( | |
793 L"Version", kTestCaseSteps[i].step_value)); | |
794 break; | |
795 } | |
796 } | |
797 } | |
798 } | |
799 | |
674 // The Quick Enable tests only make sense for the Google Chrome build as it | 800 // The Quick Enable tests only make sense for the Google Chrome build as it |
675 // interacts with registry values that are specific to Google Update. | 801 // interacts with registry values that are specific to Google Update. |
676 #if defined(GOOGLE_CHROME_BUILD) | 802 #if defined(GOOGLE_CHROME_BUILD) |
677 | 803 |
678 // Test scenarios under which the quick-enable-cf command should not exist after | 804 // Test scenarios under which the quick-enable-cf command should not exist after |
679 // the run. We're permissive in that we allow the DeleteRegKeyWorkItem even if | 805 // the run. We're permissive in that we allow the DeleteRegKeyWorkItem even if |
680 // it isn't strictly needed. | 806 // it isn't strictly needed. |
681 class QuickEnableAbsentTest : public InstallWorkerTest { | 807 class QuickEnableAbsentTest : public InstallWorkerTest { |
682 public: | 808 public: |
683 virtual void SetUp() { | 809 virtual void SetUp() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 prod_type_list[i_type_check]); | 923 prod_type_list[i_type_check]); |
798 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; | 924 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; |
799 EXPECT_EQ(prod_expect, prod_res); | 925 EXPECT_EQ(prod_expect, prod_res); |
800 } | 926 } |
801 } | 927 } |
802 } | 928 } |
803 } | 929 } |
804 } | 930 } |
805 | 931 |
806 #endif // defined(GOOGLE_CHROME_BUILD) | 932 #endif // defined(GOOGLE_CHROME_BUILD) |
OLD | NEW |