diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 20:02:42 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 20:02:42 +0000 |
commit | a8f8588a7a24c9a0603e28fd67ea463b542a72ac (patch) | |
tree | 5130701e6d083f1f2b742fd155522ebd970ee331 /chrome_frame | |
parent | 96de7910f611a4640bc9ade33abf981b6661680d (diff) | |
download | chromium_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_frame')
-rw-r--r-- | chrome_frame/test/chrome_frame_test_utils.cc | 39 | ||||
-rw-r--r-- | chrome_frame/test/chrome_frame_test_utils.h | 23 | ||||
-rw-r--r-- | chrome_frame/test/policy_settings_unittest.cc | 1 | ||||
-rw-r--r-- | chrome_frame/test/util_unittests.cc | 14 |
4 files changed, 15 insertions, 62 deletions
diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc index 240cec2..7b54724 100644 --- a/chrome_frame/test/chrome_frame_test_utils.cc +++ b/chrome_frame/test/chrome_frame_test_utils.cc @@ -51,9 +51,6 @@ const wchar_t kChromeLauncher[] = L"chrome_launcher.exe"; const int kChromeFrameLongNavigationTimeoutInSeconds = 10; const int kChromeFrameVeryLongNavigationTimeoutInSeconds = 30; -const wchar_t TempRegKeyOverride::kTempTestKeyPath[] = - L"Software\\Chromium\\TempTestKeys"; - // Callback function for EnumThreadWindows. BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { int& count = *reinterpret_cast<int*>(param); @@ -616,40 +613,16 @@ base::ProcessHandle StartCrashService() { } } -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() { - base::win::RegKey key; - if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) { - key.DeleteKey(kTempTestKeyPath); - } -} - ScopedVirtualizeHklmAndHkcu::ScopedVirtualizeHklmAndHkcu() { - TempRegKeyOverride::DeleteAllTempKeys(); - hklm_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_fake")); - hkcu_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_fake")); + override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, L"hklm_fake"); + override_manager_.OverrideRegistry(HKEY_CURRENT_USER, L"hkcu_fake"); } ScopedVirtualizeHklmAndHkcu::~ScopedVirtualizeHklmAndHkcu() { - hkcu_.reset(NULL); - hklm_.reset(NULL); - TempRegKeyOverride::DeleteAllTempKeys(); +} + +void ScopedVirtualizeHklmAndHkcu::RemoveAllOverrides() { + override_manager_.RemoveAllOverrides(); } bool KillProcesses(const std::wstring& executable_name, int exit_code, diff --git a/chrome_frame/test/chrome_frame_test_utils.h b/chrome_frame/test/chrome_frame_test_utils.h index a93af2f..329adba 100644 --- a/chrome_frame/test/chrome_frame_test_utils.h +++ b/chrome_frame/test/chrome_frame_test_utils.h @@ -17,6 +17,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/process_util.h" +#include "base/test/test_reg_util_win.h" #include "base/win/registry.h" #include "base/win/scoped_comptr.h" @@ -285,21 +286,6 @@ class CloseIeAtEndOfScope { // during test runs. base::ProcessHandle StartCrashService(); -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_; -}; - // Used in tests where we reference the registry and don't want to run into // problems where existing registry settings might conflict with the // expectations of the test. @@ -308,9 +294,12 @@ class ScopedVirtualizeHklmAndHkcu { ScopedVirtualizeHklmAndHkcu(); ~ScopedVirtualizeHklmAndHkcu(); + // Removes all overrides and deletes all temporary test keys used by the + // overrides. + void RemoveAllOverrides(); + protected: - scoped_ptr<TempRegKeyOverride> hklm_; - scoped_ptr<TempRegKeyOverride> hkcu_; + registry_util::RegistryOverrideManager override_manager_; }; // Attempts to kill all the processes on the current machine that were launched diff --git a/chrome_frame/test/policy_settings_unittest.cc b/chrome_frame/test/policy_settings_unittest.cc index 15fa443..99d970f 100644 --- a/chrome_frame/test/policy_settings_unittest.cc +++ b/chrome_frame/test/policy_settings_unittest.cc @@ -16,7 +16,6 @@ using base::win::RegKey; using chrome_frame_test::ScopedVirtualizeHklmAndHkcu; -using chrome_frame_test::TempRegKeyOverride; namespace { diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc index 9cdf9f6..bb52451 100644 --- a/chrome_frame/test/util_unittests.cc +++ b/chrome_frame/test/util_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,7 +16,6 @@ #include "testing/gmock/include/gmock/gmock.h" using base::win::RegKey; -using chrome_frame_test::TempRegKeyOverride; const wchar_t kChannelName[] = L"-dev"; const wchar_t kSuffix[] = L"-fix"; @@ -31,23 +30,16 @@ TEST(SimpleUtilTests, GetTempInternetFiles) { class UtilTests : public testing::Test { protected: void SetUp() { - TempRegKeyOverride::DeleteAllTempKeys(); DeleteAllSingletons(); - - hklm_pol_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_fake")); - hkcu_pol_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_fake")); } void TearDown() { - hkcu_pol_.reset(NULL); - hklm_pol_.reset(NULL); - TempRegKeyOverride::DeleteAllTempKeys(); + registry_virtualization_.RemoveAllOverrides(); } // This is used to manage life cycle of PolicySettings singleton. // base::ShadowingAtExitManager at_exit_manager_; - scoped_ptr<TempRegKeyOverride> hklm_pol_; - scoped_ptr<TempRegKeyOverride> hkcu_pol_; + chrome_frame_test::ScopedVirtualizeHklmAndHkcu registry_virtualization_; }; TEST_F(UtilTests, GetModuleVersionTest) { |