| Index: chrome/installer/setup/install_worker_unittest.cc
|
| diff --git a/chrome/installer/setup/install_worker_unittest.cc b/chrome/installer/setup/install_worker_unittest.cc
|
| index 67ef806c18e159708b0cb8329a97560b66fa5c48..1bd371563aca7f6e3de2052f6a12a9aa25e66500 100644
|
| --- a/chrome/installer/setup/install_worker_unittest.cc
|
| +++ b/chrome/installer/setup/install_worker_unittest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/installer/setup/install_worker.h"
|
|
|
| +#include "base/test/test_reg_util_win.h"
|
| #include "base/win/registry.h"
|
| #include "base/version.h"
|
| #include "chrome/common/chrome_constants.h"
|
| @@ -12,6 +13,7 @@
|
| #include "chrome/installer/util/helper.h"
|
| #include "chrome/installer/util/google_update_constants.h"
|
| #include "chrome/installer/util/installation_state.h"
|
| +#include "chrome/installer/util/installation_validation_helper.h"
|
| #include "chrome/installer/util/installer_state.h"
|
| #include "chrome/installer/util/set_reg_value_work_item.h"
|
| #include "chrome/installer/util/util_constants.h"
|
| @@ -20,6 +22,7 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
|
|
| +using base::win::RegKey;
|
| using installer::InstallationState;
|
| using installer::InstallerState;
|
| using installer::Product;
|
| @@ -27,13 +30,16 @@ using installer::ProductState;
|
|
|
| using ::testing::_;
|
| using ::testing::AtLeast;
|
| -using ::testing::HasSubstr;
|
| using ::testing::AtMost;
|
| +using ::testing::Bool;
|
| +using ::testing::Combine;
|
| +using ::testing::HasSubstr;
|
| using ::testing::Eq;
|
| using ::testing::Return;
|
| using ::testing::StrCaseEq;
|
| using ::testing::StrEq;
|
| using ::testing::StrictMock;
|
| +using ::testing::Values;
|
|
|
| // Mock classes to help with testing
|
| //------------------------------------------------------------------------------
|
| @@ -42,6 +48,9 @@ class MockWorkItemList : public WorkItemList {
|
| public:
|
| MockWorkItemList() {}
|
|
|
| + MOCK_METHOD3(AddCopyRegKeyWorkItem, WorkItem* (HKEY,
|
| + const std::wstring&,
|
| + const std::wstring&));
|
| MOCK_METHOD5(AddCopyTreeWorkItem, WorkItem*(const std::wstring&,
|
| const std::wstring&,
|
| const std::wstring&,
|
| @@ -176,11 +185,26 @@ class InstallWorkerTest : public testing::Test {
|
| virtual void TearDown() {
|
| }
|
|
|
| + void MaybeAddBinariesToInstallationState(
|
| + bool system_level,
|
| + MockInstallationState* installation_state) {
|
| + if (installation_state->GetProductState(
|
| + system_level, BrowserDistribution::CHROME_BINARIES) == NULL) {
|
| + MockProductState product_state;
|
| + product_state.set_version(current_version_->Clone());
|
| + installation_state->SetProductState(system_level,
|
| + BrowserDistribution::CHROME_BINARIES,
|
| + product_state);
|
| + }
|
| + }
|
| +
|
| void AddChromeToInstallationState(
|
| bool system_level,
|
| bool multi_install,
|
| bool with_chrome_frame_ready_mode,
|
| MockInstallationState* installation_state) {
|
| + if (multi_install)
|
| + MaybeAddBinariesToInstallationState(system_level, installation_state);
|
| MockProductState product_state;
|
| product_state.set_version(current_version_->Clone());
|
| product_state.set_multi_install(multi_install);
|
| @@ -192,7 +216,9 @@ class InstallWorkerTest : public testing::Test {
|
| FilePath install_path =
|
| installer::GetChromeInstallPath(system_level, dist);
|
| product_state.SetUninstallProgram(
|
| - install_path.Append(installer::kSetupExe));
|
| + install_path.AppendASCII(current_version_->GetString())
|
| + .Append(installer::kInstallerDir)
|
| + .Append(installer::kSetupExe));
|
| product_state.AddUninstallSwitch(installer::switches::kUninstall);
|
| if (system_level)
|
| product_state.AddUninstallSwitch(installer::switches::kSystemLevel);
|
| @@ -216,6 +242,8 @@ class InstallWorkerTest : public testing::Test {
|
| bool multi_install,
|
| bool ready_mode,
|
| MockInstallationState* installation_state) {
|
| + if (multi_install)
|
| + MaybeAddBinariesToInstallationState(system_level, installation_state);
|
| MockProductState product_state;
|
| product_state.set_version(current_version_->Clone());
|
| product_state.set_multi_install(multi_install);
|
| @@ -226,7 +254,9 @@ class InstallWorkerTest : public testing::Test {
|
| FilePath install_path =
|
| installer::GetChromeInstallPath(system_level, dist);
|
| product_state.SetUninstallProgram(
|
| - install_path.Append(installer::kSetupExe));
|
| + install_path.AppendASCII(current_version_->GetString())
|
| + .Append(installer::kInstallerDir)
|
| + .Append(installer::kSetupExe));
|
| product_state.AddUninstallSwitch(installer::switches::kUninstall);
|
| product_state.AddUninstallSwitch(installer::switches::kChromeFrame);
|
| if (system_level)
|
| @@ -393,141 +423,139 @@ namespace {
|
| const wchar_t elevation_key[] =
|
| L"SOFTWARE\\Microsoft\\Internet Explorer\\Low Rights\\ElevationPolicy\\"
|
| L"{E0A900DF-9611-4446-86BD-4B1D47E7DB2A}";
|
| -const wchar_t dragdrop_key[] =
|
| - L"SOFTWARE\\Microsoft\\Internet Explorer\\Low Rights\\DragDrop\\"
|
| - L"{E0A900DF-9611-4446-86BD-4B1D47E7DB2A}";
|
| -
|
| -} // namespace
|
| -
|
| -TEST_F(InstallWorkerTest, ElevationPolicyWorkItems) {
|
| - const bool system_level = true;
|
| - const HKEY root = HKEY_LOCAL_MACHINE;
|
| - const bool multi_install = true;
|
| - MockWorkItemList work_item_list;
|
| -
|
| - scoped_ptr<MockInstallationState> installation_state(
|
| - BuildChromeInstallationState(system_level, multi_install));
|
| -
|
| - scoped_ptr<MockInstallerState> installer_state(
|
| - BuildChromeInstallerState(system_level, multi_install,
|
| - *installation_state,
|
| - InstallerState::MULTI_INSTALL));
|
| -
|
| - EXPECT_CALL(work_item_list, AddCreateRegKeyWorkItem(root,
|
| - StrEq(elevation_key))).Times(1);
|
| -
|
| - EXPECT_CALL(work_item_list, AddCreateRegKeyWorkItem(root,
|
| - StrEq(dragdrop_key))).Times(1);
|
| -
|
| - EXPECT_CALL(work_item_list, AddSetRegDwordValueWorkItem(root,
|
| - StrEq(elevation_key), StrEq(L"Policy"), 3, _)).Times(1);
|
| -
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(root,
|
| - StrEq(elevation_key), StrEq(L"AppName"),
|
| - StrEq(installer::kChromeLauncherExe), _)).Times(1);
|
| +const wchar_t old_elevation_key[] =
|
| + L"SOFTWARE\\Microsoft\\Internet Explorer\\Low Rights\\ElevationPolicy\\"
|
| + L"{6C288DD7-76FB-4721-B628-56FAC252E199}";
|
|
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(root,
|
| - StrEq(elevation_key), StrEq(L"AppPath"), _, _)).Times(1);
|
| +enum ProductBits {
|
| + CHROME_PB = 1 << 0,
|
| + CHROME_FRAME_PB = 1 << 1,
|
| + CHROME_AND_CHROME_FRAME_PB = CHROME_PB | CHROME_FRAME_PB,
|
| +};
|
|
|
| - EXPECT_CALL(work_item_list, AddSetRegDwordValueWorkItem(root,
|
| - StrEq(dragdrop_key), StrEq(L"Policy"), 3, _)).Times(1);
|
| +} // namespace
|
|
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(root,
|
| - StrEq(dragdrop_key), StrEq(L"AppName"),
|
| - StrEq(chrome::kBrowserProcessExecutableName), _)).Times(1);
|
| +// A test class for worker functions that manipulate the old IE low rights
|
| +// policies.
|
| +// Parameters:
|
| +// bool : system_level_
|
| +// bool : multi_install_
|
| +// ProductBits : installed_products_
|
| +// bool : old_value_exists_
|
| +class OldIELowRightsTests : public InstallWorkerTest,
|
| + public ::testing::WithParamInterface<
|
| + std::tr1::tuple<bool, bool, ProductBits, bool> > {
|
| + protected:
|
| + virtual void SetUp() OVERRIDE {
|
| + InstallWorkerTest::SetUp();
|
|
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(root,
|
| - StrEq(dragdrop_key), StrEq(L"AppPath"), _, _)).Times(1);
|
| + const ParamType& param = GetParam();
|
| + system_level_ = std::tr1::get<0>(param);
|
| + multi_install_ = std::tr1::get<1>(param);
|
| + installed_products_ = std::tr1::get<2>(param);
|
| + old_value_exists_ = std::tr1::get<3>(param);
|
| + root_key_ = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
|
|
|
| - AddElevationPolicyWorkItems(*installation_state.get(),
|
| - *installer_state.get(),
|
| - *new_version_.get(),
|
| - &work_item_list);
|
| -}
|
| + registry_overrides_.OverrideRegistry(root_key_, L"OldIELowRightsTests");
|
| + if (old_value_exists_) {
|
| + // Write an "old" low rights elevation policy.
|
| + RegKey key(root_key_, old_elevation_key, KEY_WRITE);
|
| + }
|
| + // For simplicity's sake, pretend that both products in single install is
|
| + // only Chrome. We'll test that codepath twice, but who cares.
|
| + if (!multi_install_ && installed_products_ == CHROME_AND_CHROME_FRAME_PB)
|
| + installed_products_ = CHROME_PB;
|
| +
|
| + installation_state_.reset(new MockInstallationState());
|
| + if (installed_products_ & CHROME_PB) {
|
| + AddChromeToInstallationState(system_level_, multi_install_, false,
|
| + installation_state_.get());
|
| + }
|
| + if (installed_products_ & CHROME_FRAME_PB) {
|
| + AddChromeFrameToInstallationState(system_level_, multi_install_, false,
|
| + installation_state_.get());
|
| + }
|
| +#if 0
|
| + // TODO(grt): beef up the state building in this test so we can validate it.
|
| + installer::ExpectInstallationOfTypeForState(
|
| + *installation_state_, system_level_, GetInstallationType());
|
| +#endif
|
| + installer_state_.reset(BuildBasicInstallerState(
|
| + system_level_, multi_install_, *installation_state_,
|
| + multi_install_ ? InstallerState::MULTI_UPDATE :
|
| + InstallerState::SINGLE_INSTALL_OR_UPDATE));
|
| + if (installed_products_ & CHROME_PB)
|
| + AddChromeToInstallerState(*installation_state_, installer_state_.get());
|
| + if (installed_products_ & CHROME_FRAME_PB) {
|
| + AddChromeFrameToInstallerState(*installation_state_, false,
|
| + installer_state_.get());
|
| + }
|
| + }
|
|
|
| -TEST_F(InstallWorkerTest, ElevationPolicyUninstall) {
|
| - const bool system_level = true;
|
| - const HKEY root = HKEY_LOCAL_MACHINE;
|
| - const bool multi_install = true;
|
| - MockWorkItemList work_item_list;
|
| + installer::InstallationValidator::InstallationType GetInstallationType()
|
| + const {
|
| + using installer::InstallationValidator;
|
| + uint32 bits = 0;
|
| + if (installed_products_ & CHROME_PB) {
|
| + bits |= (multi_install_
|
| + ? InstallationValidator::ProductBits::CHROME_MULTI
|
| + : InstallationValidator::ProductBits::CHROME_SINGLE);
|
| + }
|
| + if (installed_products_ & CHROME_FRAME_PB) {
|
| + bits |= (multi_install_
|
| + ? InstallationValidator::ProductBits::CHROME_FRAME_MULTI
|
| + : InstallationValidator::ProductBits::CHROME_FRAME_SINGLE);
|
| + }
|
| + return static_cast<InstallationValidator::InstallationType>(bits);
|
| + }
|
|
|
| - scoped_ptr<MockInstallationState> installation_state(
|
| - BuildChromeInstallationState(system_level, multi_install));
|
| + registry_util::RegistryOverrideManager registry_overrides_;
|
| + scoped_ptr<MockInstallationState> installation_state_;
|
| + scoped_ptr<MockInstallerState> installer_state_;
|
| + bool system_level_;
|
| + bool multi_install_;
|
| + bool old_value_exists_;
|
| + ProductBits installed_products_;
|
| + HKEY root_key_;
|
| +};
|
|
|
| - scoped_ptr<MockInstallerState> installer_state(
|
| - BuildChromeInstallerState(system_level, multi_install,
|
| - *installation_state,
|
| - InstallerState::UNINSTALL));
|
| +TEST_P(OldIELowRightsTests, MaybeAddDeleteOldIELowRightsPolicyWorkItems) {
|
| + StrictMock<MockWorkItemList> work_item_list;
|
|
|
| - EXPECT_CALL(work_item_list, AddDeleteRegKeyWorkItem(root,
|
| - StrEq(elevation_key))).Times(1);
|
| - EXPECT_CALL(work_item_list, AddDeleteRegKeyWorkItem(root,
|
| - StrEq(dragdrop_key))).Times(1);
|
| + // The old elevation policy key should only be deleted when Chrome Frame is
|
| + // being operated on.
|
| + if (installed_products_ & CHROME_FRAME_PB) {
|
| + EXPECT_CALL(work_item_list,
|
| + AddDeleteRegKeyWorkItem(root_key_, StrEq(old_elevation_key)))
|
| + .Times(1);
|
| + }
|
|
|
| - AddElevationPolicyWorkItems(*installation_state.get(),
|
| - *installer_state.get(),
|
| - *new_version_.get(),
|
| - &work_item_list);
|
| + MaybeAddDeleteOldIELowRightsPolicyWorkItems(*installer_state_.get(),
|
| + &work_item_list);
|
| }
|
|
|
| -TEST_F(InstallWorkerTest, ElevationPolicySingleNoop) {
|
| - const bool system_level = true;
|
| - const bool multi_install = false; // nothing should be done for single.
|
| - MockWorkItemList work_item_list;
|
| +TEST_P(OldIELowRightsTests, MaybeAddCopyIELowRightsPolicyWorkItems) {
|
| + StrictMock<MockWorkItemList> work_item_list;
|
|
|
| - scoped_ptr<MockInstallationState> installation_state(
|
| - BuildChromeInstallationState(system_level, multi_install));
|
| + // The old elevation policy key should only be copied when Chrome Frame is
|
| + // being operated on and when there's no old value.
|
| + if ((installed_products_ & CHROME_FRAME_PB) && !old_value_exists_) {
|
| + EXPECT_CALL(work_item_list,
|
| + AddCopyRegKeyWorkItem(root_key_, StrEq(elevation_key),
|
| + StrEq(old_elevation_key)))
|
| + .Times(1);
|
| + }
|
|
|
| - scoped_ptr<MockInstallerState> installer_state(
|
| - BuildChromeInstallerState(system_level, multi_install,
|
| - *installation_state,
|
| - InstallerState::UNINSTALL));
|
| -
|
| - EXPECT_CALL(work_item_list, AddDeleteRegKeyWorkItem(_, _)).Times(0);
|
| - EXPECT_CALL(work_item_list, AddCreateRegKeyWorkItem(_, _)).Times(0);
|
| - EXPECT_CALL(work_item_list, AddSetRegDwordValueWorkItem(_, _, _, _, _))
|
| - .Times(0);
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(_, _, _, _, _))
|
| - .Times(0);
|
| -
|
| - AddElevationPolicyWorkItems(*installation_state.get(),
|
| - *installer_state.get(),
|
| - *new_version_.get(),
|
| - &work_item_list);
|
| + MaybeAddCopyIELowRightsPolicyWorkItems(*installer_state_.get(),
|
| + &work_item_list);
|
| }
|
|
|
| -TEST_F(InstallWorkerTest, ElevationPolicyExistingSingleCFNoop) {
|
| - const bool system_level = true;
|
| - const bool multi_install = true;
|
| - MockWorkItemList work_item_list;
|
| -
|
| - scoped_ptr<MockInstallationState> installation_state(
|
| - BuildChromeInstallationState(system_level, multi_install));
|
| -
|
| - MockProductState cf_state;
|
| - cf_state.set_version(current_version_->Clone());
|
| - cf_state.set_multi_install(false);
|
| -
|
| - installation_state->SetProductState(system_level,
|
| - BrowserDistribution::CHROME_FRAME, cf_state);
|
| -
|
| - scoped_ptr<MockInstallerState> installer_state(
|
| - BuildChromeInstallerState(system_level, multi_install,
|
| - *installation_state,
|
| - InstallerState::MULTI_INSTALL));
|
| -
|
| - EXPECT_CALL(work_item_list, AddDeleteRegKeyWorkItem(_, _)).Times(0);
|
| - EXPECT_CALL(work_item_list, AddCreateRegKeyWorkItem(_, _)).Times(0);
|
| - EXPECT_CALL(work_item_list, AddSetRegDwordValueWorkItem(_, _, _, _, _))
|
| - .Times(0);
|
| - EXPECT_CALL(work_item_list, AddSetRegStringValueWorkItem(_, _, _, _, _))
|
| - .Times(0);
|
| -
|
| - AddElevationPolicyWorkItems(*installation_state.get(),
|
| - *installer_state.get(),
|
| - *new_version_.get(),
|
| - &work_item_list);
|
| -}
|
| +INSTANTIATE_TEST_CASE_P(
|
| + Variations,
|
| + OldIELowRightsTests,
|
| + Combine(Bool(), Bool(),
|
| + Values(CHROME_PB, CHROME_FRAME_PB, CHROME_AND_CHROME_FRAME_PB),
|
| + Bool()));
|
|
|
| TEST_F(InstallWorkerTest, GoogleUpdateWorkItemsTest) {
|
| const bool system_level = true;
|
|
|