OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef BASE_TEST_TEST_REG_UTIL_H_ |
| 6 #define BASE_TEST_TEST_REG_UTIL_H_ |
| 7 #pragma once |
| 8 |
| 9 // Registry utility functions used only by tests. |
| 10 |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/basictypes.h" |
| 15 #include "base/win/registry.h" |
| 16 |
| 17 namespace registry_util { |
| 18 |
| 19 // Allows a test to easily override registry hives so that it can start from a |
| 20 // known good state, or make sure to not leave any side effects once the test |
| 21 // completes. |
| 22 class RegistryOverrideManager { |
| 23 public: |
| 24 // All overridden hives will be descendents of this registry path under the |
| 25 // main HKCU hive. |
| 26 static const wchar_t kTempTestKeyPath[]; |
| 27 |
| 28 RegistryOverrideManager(); |
| 29 ~RegistryOverrideManager(); |
| 30 |
| 31 // Override the given registry hive using a temporary key named by temp_name |
| 32 // under the temporary test key path. |
| 33 void OverrideRegistry(HKEY override, const std::wstring& temp_name); |
| 34 |
| 35 // Deletes all temporary test keys used by the overrides. |
| 36 static void DeleteAllTempKeys(); |
| 37 |
| 38 // Removes all overrides and deletes all temporary test keys used by the |
| 39 // overrides. |
| 40 void RemoveAllOverrides(); |
| 41 |
| 42 private: |
| 43 // Keeps track of one override. |
| 44 class ScopedRegistryKeyOverride { |
| 45 public: |
| 46 ScopedRegistryKeyOverride(HKEY override, const std::wstring& temp_name); |
| 47 ~ScopedRegistryKeyOverride(); |
| 48 |
| 49 private: |
| 50 HKEY override_; |
| 51 base::win::RegKey temp_key_; |
| 52 std::wstring temp_name_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride); |
| 55 }; |
| 56 |
| 57 std::vector<ScopedRegistryKeyOverride*> overrides_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager); |
| 60 }; |
| 61 |
| 62 } // namespace registry_util |
| 63 |
| 64 #endif // BASE_TEST_TEST_REG_UTIL_H_ |
OLD | NEW |