1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_TEST_TEST_REG_UTIL_H_
6 #define BASE_TEST_TEST_REG_UTIL_H_
8 // Registry utility functions used only by tests.
13 #include "base/basictypes.h"
14 #include "base/win/registry.h"
16 namespace registry_util
{
18 // Allows a test to easily override registry hives so that it can start from a
19 // known good state, or make sure to not leave any side effects once the test
21 class RegistryOverrideManager
{
23 // All overridden hives will be descendents of this registry path under the
25 static const wchar_t kTempTestKeyPath
[];
27 RegistryOverrideManager();
28 ~RegistryOverrideManager();
30 // Override the given registry hive using a temporary key named by temp_name
31 // under the temporary test key path.
32 void OverrideRegistry(HKEY override
, const std::wstring
& temp_name
);
34 // Deletes all temporary test keys used by the overrides.
35 static void DeleteAllTempKeys();
37 // Removes all overrides and deletes all temporary test keys used by the
39 void RemoveAllOverrides();
42 // Keeps track of one override.
43 class ScopedRegistryKeyOverride
{
45 ScopedRegistryKeyOverride(HKEY override
, const std::wstring
& temp_name
);
46 ~ScopedRegistryKeyOverride();
50 base::win::RegKey temp_key_
;
51 std::wstring temp_name_
;
53 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride
);
56 std::vector
<ScopedRegistryKeyOverride
*> overrides_
;
58 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager
);
61 } // namespace registry_util
63 #endif // BASE_TEST_TEST_REG_UTIL_H_