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 "base/win/registry.h" |
| 12 |
| 13 namespace registry_util { |
| 14 |
| 15 // Allows a test to easily override a known location in the registry so that |
| 16 // it can start from a known good state, or make sure to not leave any |
| 17 // side effects once the test completes. |
| 18 class ScopedRegistryKeyOverride { |
| 19 public: |
| 20 static const wchar_t kTempTestKeyPath[]; |
| 21 |
| 22 ScopedRegistryKeyOverride(HKEY override, const std::wstring& temp_name); |
| 23 ~ScopedRegistryKeyOverride(); |
| 24 |
| 25 static void DeleteAllTempKeys(); |
| 26 |
| 27 protected: |
| 28 HKEY override_; |
| 29 base::win::RegKey temp_key_; |
| 30 std::wstring temp_name_; |
| 31 |
| 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride); |
| 34 }; |
| 35 |
| 36 // This object can be used to make sure that the temporary registry location |
| 37 // used by ScopedRegistryKeyOverride are cleared out before and after the |
| 38 // registry is overidden. Instantiate this class before any instances of |
| 39 // ScopedRegistryKeyOverride and destroy it after all instances. |
| 40 class ScopedRegistryTempPathCleanup { |
| 41 public: |
| 42 ScopedRegistryTempPathCleanup(); |
| 43 ~ScopedRegistryTempPathCleanup(); |
| 44 |
| 45 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryTempPathCleanup); |
| 47 }; |
| 48 |
| 49 } // namespace registry_util |
| 50 |
| 51 #endif // BASE_TEST_TEST_REG_UTIL_H_ |
OLD | NEW |