OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TEST_TEST_REG_UTIL_WIN_H_ | 5 #ifndef BASE_TEST_TEST_REG_UTIL_WIN_H_ |
6 #define BASE_TEST_TEST_REG_UTIL_WIN_H_ | 6 #define BASE_TEST_TEST_REG_UTIL_WIN_H_ |
7 | 7 |
8 // Registry utility functions used only by tests. | 8 // Registry utility functions used only by tests. |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 21 matching lines...) Expand all Loading... |
32 // two RegistryOverrideManagers created with the same timestamp. | 32 // two RegistryOverrideManagers created with the same timestamp. |
33 class RegistryOverrideManager { | 33 class RegistryOverrideManager { |
34 public: | 34 public: |
35 RegistryOverrideManager(); | 35 RegistryOverrideManager(); |
36 ~RegistryOverrideManager(); | 36 ~RegistryOverrideManager(); |
37 | 37 |
38 // Override the given registry hive using a randomly generated temporary key. | 38 // Override the given registry hive using a randomly generated temporary key. |
39 // Multiple overrides to the same hive are not supported and lead to undefined | 39 // Multiple overrides to the same hive are not supported and lead to undefined |
40 // behavior. | 40 // behavior. |
41 // Optional return of the registry override path. | 41 // Optional return of the registry override path. |
| 42 // Calls to these functions must be wrapped in ASSERT_NO_FATAL_FAILURE to |
| 43 // ensure that tests do not proceeed in case of failure to override. |
42 void OverrideRegistry(HKEY override); | 44 void OverrideRegistry(HKEY override); |
43 void OverrideRegistry(HKEY override, base::string16* override_path); | 45 void OverrideRegistry(HKEY override, base::string16* override_path); |
44 | 46 |
45 private: | 47 private: |
46 friend class RegistryOverrideManagerTest; | 48 friend class RegistryOverrideManagerTest; |
47 | 49 |
48 // Keeps track of one override. | 50 // Keeps track of one override. |
49 class ScopedRegistryKeyOverride { | 51 class ScopedRegistryKeyOverride { |
50 public: | 52 public: |
51 ScopedRegistryKeyOverride(HKEY override, const base::string16& key_path); | 53 ScopedRegistryKeyOverride(HKEY override, const base::string16& key_path); |
52 ~ScopedRegistryKeyOverride(); | 54 ~ScopedRegistryKeyOverride(); |
53 | 55 |
54 private: | 56 private: |
55 HKEY override_; | 57 HKEY override_; |
56 base::win::RegKey temp_key_; | 58 base::string16 key_path_; |
57 | 59 |
58 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride); | 60 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride); |
59 }; | 61 }; |
60 | 62 |
61 // Used for testing only. | 63 // Used for testing only. |
62 RegistryOverrideManager(const base::Time& timestamp, | 64 RegistryOverrideManager(const base::Time& timestamp, |
63 const base::string16& test_key_root); | 65 const base::string16& test_key_root); |
64 | 66 |
65 base::Time timestamp_; | 67 base::Time timestamp_; |
66 base::string16 guid_; | 68 base::string16 guid_; |
67 | 69 |
68 base::string16 test_key_root_; | 70 base::string16 test_key_root_; |
69 std::vector<std::unique_ptr<ScopedRegistryKeyOverride>> overrides_; | 71 std::vector<std::unique_ptr<ScopedRegistryKeyOverride>> overrides_; |
70 | 72 |
71 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager); | 73 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager); |
72 }; | 74 }; |
73 | 75 |
74 // Generates a temporary key path that will be eventually deleted | 76 // Generates a temporary key path that will be eventually deleted |
75 // automatically if the process crashes. | 77 // automatically if the process crashes. |
76 base::string16 GenerateTempKeyPath(); | 78 base::string16 GenerateTempKeyPath(); |
77 | 79 |
78 } // namespace registry_util | 80 } // namespace registry_util |
79 | 81 |
80 #endif // BASE_TEST_TEST_REG_UTIL_WIN_H_ | 82 #endif // BASE_TEST_TEST_REG_UTIL_WIN_H_ |
OLD | NEW |