summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/policy_settings_unittest.cc
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-09 02:56:24 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-09 02:56:24 +0000
commit7dd06a0131c05212100c81ae88ae07f0757ff4db (patch)
tree8b42ff631ecaa927da86b40d47fe6298f972a8a7 /chrome_frame/test/policy_settings_unittest.cc
parentd077249e28b8163aabf452604716dba216303207 (diff)
downloadchromium_src-7dd06a0131c05212100c81ae88ae07f0757ff4db.zip
chromium_src-7dd06a0131c05212100c81ae88ae07f0757ff4db.tar.gz
chromium_src-7dd06a0131c05212100c81ae88ae07f0757ff4db.tar.bz2
Temporary workaround to get tests that reference singletons either directly or indirectly to pass.
With the recent Singleton refactoring, these tests started exposing some inherent problems with singletons, namely that one test can reference a state set by a different test, which can cause all sorts of flakiness. Furthermore, some of these tests could reference the registry which may have some user specific settings that could cause the tests to fail To work around these issues, I'm adding a few utility classes for tests (registry virtualization) and exposing a method to reset singletons before a test is run. TEST=Fixes flakiness and a few tests that could fail on the waterfall. BUG=none Review URL: http://codereview.chromium.org/5564009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68701 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/policy_settings_unittest.cc')
-rw-r--r--chrome_frame/test/policy_settings_unittest.cc56
1 files changed, 8 insertions, 48 deletions
diff --git a/chrome_frame/test/policy_settings_unittest.cc b/chrome_frame/test/policy_settings_unittest.cc
index 53c4df0..771762f 100644
--- a/chrome_frame/test/policy_settings_unittest.cc
+++ b/chrome_frame/test/policy_settings_unittest.cc
@@ -11,9 +11,12 @@
#include "base/win/registry.h"
#include "chrome/common/policy_constants.h"
#include "chrome_frame/policy_settings.h"
+#include "chrome_frame/test/chrome_frame_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
+using chrome_frame_test::ScopedVirtualizeHklmAndHkcu;
+using chrome_frame_test::TempRegKeyOverride;
namespace {
@@ -30,42 +33,6 @@ void DeleteChromeFramePolicyEntries(HKEY root) {
}
}
-class TempRegKeyOverride {
- public:
- static const wchar_t kTempTestKeyPath[];
-
- 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_TRUE(temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(),
- KEY_ALL_ACCESS));
- EXPECT_EQ(ERROR_SUCCESS,
- ::RegOverridePredefKey(override_, temp_key_.Handle()));
- }
-
- ~TempRegKeyOverride() {
- ::RegOverridePredefKey(override_, NULL);
- // The temp key will be deleted via a call to DeleteAllTempKeys().
- }
-
- static void DeleteAllTempKeys() {
- RegKey key;
- if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS)) {
- key.DeleteKey(kTempTestKeyPath);
- }
- }
-
- protected:
- HKEY override_;
- RegKey temp_key_;
- std::wstring temp_name_;
-};
-
-const wchar_t TempRegKeyOverride::kTempTestKeyPath[] =
- L"Software\\Chromium\\TempTestKeys";
-
bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) {
EXPECT_TRUE(policy_key->Create(policy_root, policy::kRegistrySubKey,
KEY_ALL_ACCESS));
@@ -136,28 +103,21 @@ bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) {
class PolicySettingsTest : public testing::Test {
protected:
void SetUp() {
- TempRegKeyOverride::DeleteAllTempKeys();
-
- hklm_pol_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
- hkcu_pol_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
-
ResetPolicySettings();
}
void TearDown() {
- hkcu_pol_.reset(NULL);
- hklm_pol_.reset(NULL);
- TempRegKeyOverride::DeleteAllTempKeys();
}
void ResetPolicySettings() {
- at_exit_manager_.ProcessCallbacksNow();
+ //at_exit_manager_.ProcessCallbacksNow();
+ DeleteAllSingletons();
}
// 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_;
+ // base::ShadowingAtExitManager at_exit_manager_;
+
+ ScopedVirtualizeHklmAndHkcu registry_virtualization_;
};
TEST_F(PolicySettingsTest, RendererForUrl) {