summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 20:02:42 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 20:02:42 +0000
commita8f8588a7a24c9a0603e28fd67ea463b542a72ac (patch)
tree5130701e6d083f1f2b742fd155522ebd970ee331 /chrome/installer
parent96de7910f611a4640bc9ade33abf981b6661680d (diff)
downloadchromium_src-a8f8588a7a24c9a0603e28fd67ea463b542a72ac.zip
chromium_src-a8f8588a7a24c9a0603e28fd67ea463b542a72ac.tar.gz
chromium_src-a8f8588a7a24c9a0603e28fd67ea463b542a72ac.tar.bz2
Tommi: I need an owner review for the chrome frame changes.
Moving the test helper class TempRegKeyOverride since I need to do something similar in some new RLZ tests, and I don't want to duplicate the code. Please suggest a better namespace name if needed, I was just following the same pattern found in test_file_util in the same directory. BUG=None TEST=No new tests, just refactoring test helpers Review URL: http://codereview.chromium.org/7669061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/util/install_util_unittest.cc38
-rw-r--r--chrome/installer/util/installer_state_unittest.cc14
-rw-r--r--chrome/installer/util/product_state_unittest.cc8
-rw-r--r--chrome/installer/util/product_unittest.cc35
-rw-r--r--chrome/installer/util/product_unittest.h18
5 files changed, 38 insertions, 75 deletions
diff --git a/chrome/installer/util/install_util_unittest.cc b/chrome/installer/util/install_util_unittest.cc
index 9b12075d..57f61b6 100644
--- a/chrome/installer/util/install_util_unittest.cc
+++ b/chrome/installer/util/install_util_unittest.cc
@@ -6,6 +6,7 @@
#include <utility>
#include "base/command_line.h"
+#include "base/test/test_reg_util_win.h"
#include "base/win/registry.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/install_util.h"
@@ -13,6 +14,7 @@
#include "testing/gmock/include/gmock/gmock.h"
using base::win::RegKey;
+using registry_util::RegistryOverrideManager;
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
@@ -76,7 +78,8 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
// Update the stage when there's no "ap" value.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE);
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
installer::BUILDING);
@@ -86,11 +89,11 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
.ReadValue(google_update::kRegApField, &value));
EXPECT_EQ(L"-stage:building", value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
// Update the stage when there is an "ap" value.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(google_update::kRegApField, L"2.0-dev");
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -101,11 +104,11 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
.ReadValue(google_update::kRegApField, &value));
EXPECT_EQ(L"2.0-dev-stage:building", value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
// Clear the stage.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(google_update::kRegApField, L"2.0-dev-stage:building");
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -116,7 +119,6 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
.ReadValue(google_update::kRegApField, &value));
EXPECT_EQ(L"2.0-dev", value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
}
TEST_F(InstallUtilTest, UpdateInstallerStage) {
@@ -126,7 +128,8 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
// Update the stage when there's no "InstallerExtraCode1" value.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.DeleteValue(installer::kInstallerExtraCode1);
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -137,11 +140,11 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
.ReadValueDW(installer::kInstallerExtraCode1, &value));
EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
// Update the stage when there is an "InstallerExtraCode1" value.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(installer::kInstallerExtraCode1,
static_cast<DWORD>(installer::UNPACKING));
@@ -153,11 +156,11 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
.ReadValueDW(installer::kInstallerExtraCode1, &value));
EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
// Clear the stage.
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5));
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -167,7 +170,6 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
.ReadValueDW(installer::kInstallerExtraCode1, &value));
}
- TempRegKeyOverride::DeleteAllTempKeys();
}
TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
@@ -179,7 +181,8 @@ TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
const wchar_t value[] = L"hi mom";
{
- TempRegKeyOverride override(root, L"root_key");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_key");
// Nothing to delete if the keys aren't even there.
{
MockRegistryValuePredicate pred;
@@ -245,7 +248,6 @@ TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
KEY_QUERY_VALUE).Valid());
}
}
- TempRegKeyOverride::DeleteAllTempKeys();
}
TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
@@ -255,7 +257,8 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
const wchar_t value[] = L"hi mom";
{
- TempRegKeyOverride override(root, L"root_key");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_key");
// Nothing to delete if the key isn't even there.
{
MockRegistryValuePredicate pred;
@@ -308,10 +311,10 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
KEY_QUERY_VALUE).ValueExists(value_name));
}
}
- TempRegKeyOverride::DeleteAllTempKeys();
{
- TempRegKeyOverride override(root, L"root_key");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_key");
// Default value matches: delete.
{
MockRegistryValuePredicate pred;
@@ -327,7 +330,6 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
KEY_QUERY_VALUE).ValueExists(L""));
}
}
- TempRegKeyOverride::DeleteAllTempKeys();
}
TEST_F(InstallUtilTest, ValueEquals) {
diff --git a/chrome/installer/util/installer_state_unittest.cc b/chrome/installer/util/installer_state_unittest.cc
index f7d1568..14dec6d 100644
--- a/chrome/installer/util/installer_state_unittest.cc
+++ b/chrome/installer/util/installer_state_unittest.cc
@@ -13,6 +13,7 @@
#include "base/process_util.h"
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
+#include "base/test/test_reg_util_win.h"
#include "base/utf_string_conversions.h"
#include "base/version.h"
#include "base/win/registry.h"
@@ -35,6 +36,7 @@ using base::win::RegKey;
using installer::InstallationState;
using installer::InstallerState;
using installer::MasterPreferences;
+using registry_util::RegistryOverrideManager;
class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys {
protected:
@@ -343,8 +345,10 @@ TEST_F(InstallerStateTest, WithProduct) {
HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
EXPECT_EQ(root, installer_state.root_key());
+
{
- TempRegKeyOverride override(root, L"root_pit");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_pit");
BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
BrowserDistribution::CHROME_BROWSER);
RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS);
@@ -376,7 +380,8 @@ TEST_F(InstallerStateTest, InstallerResult) {
// check results for a fresh install of single Chrome
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level");
const MasterPreferences prefs(cmd_line);
InstallationState machine_state;
@@ -403,11 +408,11 @@ TEST_F(InstallerStateTest, InstallerResult) {
key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
EXPECT_EQ(launch_cmd, value);
}
- TempRegKeyOverride::DeleteAllTempKeys();
// check results for a fresh install of multi Chrome
{
- TempRegKeyOverride override(root, L"root_inst_res");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_inst_res");
CommandLine cmd_line = CommandLine::FromString(
L"setup.exe --system-level --multi-install --chrome");
const MasterPreferences prefs(cmd_line);
@@ -435,7 +440,6 @@ TEST_F(InstallerStateTest, InstallerResult) {
EXPECT_EQ(launch_cmd, value);
key.Close();
}
- TempRegKeyOverride::DeleteAllTempKeys();
}
// Test GetCurrentVersion when migrating single Chrome to multi
diff --git a/chrome/installer/util/product_state_unittest.cc b/chrome/installer/util/product_state_unittest.cc
index 1c8400d..a180bd5 100644
--- a/chrome/installer/util/product_state_unittest.cc
+++ b/chrome/installer/util/product_state_unittest.cc
@@ -5,6 +5,7 @@
#include <windows.h>
#include "base/utf_string_conversions.h"
+#include "base/test/test_reg_util_win.h"
#include "base/version.h"
#include "base/win/registry.h"
#include "chrome/installer/util/browser_distribution.h"
@@ -16,6 +17,7 @@
using base::win::RegKey;
using installer::ProductState;
+using registry_util::RegistryOverrideManager;
class ProductStateTest : public testing::Test {
protected:
@@ -48,7 +50,7 @@ void ProductStateTest::SetUpTestCase() {
BrowserDistribution::CHROME_BROWSER);
// And we'll play in HKCU here:
- temp_key_path_.assign(TempRegKeyOverride::kTempTestKeyPath)
+ temp_key_path_.assign(RegistryOverrideManager::kTempTestKeyPath)
.append(1, L'\\')
.append(L"ProductStateTest");
}
@@ -68,7 +70,7 @@ void ProductStateTest::SetUp() {
system_install_ = true;
overridden_ = (system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER);
- // Override for test purposes. We don't use TempRegKeyOverride
+ // Override for test purposes. We don't use ScopedRegistryKeyOverride
// directly because it doesn't suit itself to our use here.
RegKey temp_key;
EXPECT_EQ(ERROR_SUCCESS,
@@ -94,7 +96,7 @@ void ProductStateTest::TearDown() {
system_install_ = false;
// Shotgun approach to clearing out data we may have written.
- TempRegKeyOverride::DeleteAllTempKeys();
+ RegistryOverrideManager::DeleteAllTempKeys();
testing::Test::TearDown();
}
diff --git a/chrome/installer/util/product_unittest.cc b/chrome/installer/util/product_unittest.cc
index 913a6ff..f548bf40 100644
--- a/chrome/installer/util/product_unittest.cc
+++ b/chrome/installer/util/product_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/installer/util/product_unittest.h"
#include "base/logging.h"
+#include "base/test/test_reg_util_win.h"
#include "base/utf_string_conversions.h"
#include "chrome/installer/util/chrome_frame_distribution.h"
#include "chrome/installer/util/google_update_constants.h"
@@ -16,6 +17,7 @@
using base::win::RegKey;
using installer::Product;
using installer::MasterPreferences;
+using registry_util::RegistryOverrideManager;
void TestWithTempDir::SetUp() {
// Name a subdirectory of the user temp directory.
@@ -30,41 +32,11 @@ void TestWithTempDir::TearDown() {
////////////////////////////////////////////////////////////////////////////////
void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() {
- TempRegKeyOverride::DeleteAllTempKeys();
TestWithTempDir::SetUp();
}
void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() {
TestWithTempDir::TearDown();
- TempRegKeyOverride::DeleteAllTempKeys();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-const wchar_t TempRegKeyOverride::kTempTestKeyPath[] =
- L"Software\\Chromium\\TempTestKeys";
-
-TempRegKeyOverride::TempRegKeyOverride(HKEY override, const wchar_t* temp_name)
- : override_(override), temp_name_(temp_name) {
- DCHECK(temp_name && lstrlenW(temp_name));
- std::wstring key_path(kTempTestKeyPath);
- key_path += L"\\" + temp_name_;
- EXPECT_EQ(ERROR_SUCCESS,
- temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
- EXPECT_EQ(ERROR_SUCCESS,
- ::RegOverridePredefKey(override_, temp_key_.Handle()));
-}
-
-TempRegKeyOverride::~TempRegKeyOverride() {
- ::RegOverridePredefKey(override_, NULL);
- // The temp key will be deleted via a call to DeleteAllTempKeys().
-}
-
-// static
-void TempRegKeyOverride::DeleteAllTempKeys() {
- RegKey key;
- if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) {
- key.DeleteKey(kTempTestKeyPath);
- }
}
////////////////////////////////////////////////////////////////////////////////
@@ -110,7 +82,8 @@ TEST_F(ProductTest, ProductInstallBasic) {
HKEY root = installer_state.root_key();
{
- TempRegKeyOverride override(root, L"root_pit");
+ RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(root, L"root_pit");
// Let's pretend chrome is installed.
RegKey version_key(root, distribution->GetVersionKey().c_str(),
diff --git a/chrome/installer/util/product_unittest.h b/chrome/installer/util/product_unittest.h
index 8635fc8..a48c9b7 100644
--- a/chrome/installer/util/product_unittest.h
+++ b/chrome/installer/util/product_unittest.h
@@ -12,7 +12,6 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
-#include "base/win/registry.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestWithTempDir : public testing::Test {
@@ -29,21 +28,4 @@ class TestWithTempDirAndDeleteTempOverrideKeys : public TestWithTempDir {
virtual void TearDown();
};
-// TODO(tommi): This is "borrowed" from Chrome Frame test code. It should be
-// moved to some common test utility file.
-class TempRegKeyOverride {
- public:
- static const wchar_t kTempTestKeyPath[];
-
- TempRegKeyOverride(HKEY override, const wchar_t* temp_name);
- ~TempRegKeyOverride();
-
- static void DeleteAllTempKeys();
-
- protected:
- HKEY override_;
- base::win::RegKey temp_key_;
- std::wstring temp_name_;
-};
-
#endif // CHROME_INSTALLER_UTIL_PRODUCT_UNITTEST_H_