Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: base/test/test_reg_util_win.h

Issue 57423008: Base: Make RegistryOverrideManager support sharded/parallel tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_H_ 5 #ifndef BASE_TEST_TEST_REG_UTIL_H_
6 #define BASE_TEST_TEST_REG_UTIL_H_ 6 #define BASE_TEST_TEST_REG_UTIL_H_
7 7
8 // Registry utility functions used only by tests. 8 // Registry utility functions used only by tests.
9 9
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/strings/string16.h"
13 #include "base/time/time.h"
14 #include "base/win/registry.h" 14 #include "base/win/registry.h"
15 15
16 namespace registry_util { 16 namespace registry_util {
17 17
18 // Allows a test to easily override registry hives so that it can start from a 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 19 // known good state, or make sure to not leave any side effects once the test
20 // completes. 20 // completes. This supports parallel tests. All the overrides are scoped to the
21 // lifetime of the override manager. Destroy the manager to undo the overrides.
22 //
23 // Overridden hives use keys stored at, for instance:
24 // HKCU\Software\Chromium\TempTestKeys\
25 // 13028145911617809\02AB211C-CF73-478D-8D91-618E11998AED
26 // The key path are comprises of:
27 // - The test key root, HKCU\Software\Chromium\TempTestKeys\
28 // - The base::Time::ToInternalValue of the creation time. This is used to
29 // delete stale keys left over from crashed tests.
30 // - A GUID used for preventing name collisions (although unlikely) between
31 // two RegistryOverrideManagers created with the same timestamp.
21 class RegistryOverrideManager { 32 class RegistryOverrideManager {
22 public: 33 public:
23 // All overridden hives will be descendents of this registry path under the 34 // All overridden hives will be descendents of this registry path under the
24 // main HKCU hive. 35 // main HKCU hive.
25 static const wchar_t kTempTestKeyPath[]; 36 static const wchar_t kTempTestKeyPath[];
grt (UTC plus 2) 2013/11/07 02:39:33 It feels to me like this should be an implementati
tommycli 2013/11/07 18:02:07 Unit test needs this to function properly. I moved
26 37
27 RegistryOverrideManager(); 38 RegistryOverrideManager();
28 ~RegistryOverrideManager(); 39 ~RegistryOverrideManager();
29 40
30 // Override the given registry hive using a temporary key named by temp_name 41 // Override the given registry hive using a temporary key named by temp_name
31 // under the temporary test key path. 42 // under the temporary test key path. There is no need to randomize
32 void OverrideRegistry(HKEY override, const std::wstring& temp_name); 43 // |override_name|, as a random parent key is generated. Multiple overrides to
33 44 // the same hive are not supported and lead to undefined behavior.
34 // Deletes all temporary test keys used by the overrides. 45 void OverrideRegistry(HKEY override, const string16& override_name);
35 static void DeleteAllTempKeys();
36
37 // Removes all overrides and deletes all temporary test keys used by the
38 // overrides.
39 void RemoveAllOverrides();
40 46
41 private: 47 private:
48 friend class RegistryOverrideManagerTest;
49
42 // Keeps track of one override. 50 // Keeps track of one override.
43 class ScopedRegistryKeyOverride { 51 class ScopedRegistryKeyOverride {
44 public: 52 public:
45 ScopedRegistryKeyOverride(HKEY override, const std::wstring& temp_name); 53 ScopedRegistryKeyOverride(HKEY override, const string16& key_path);
46 ~ScopedRegistryKeyOverride(); 54 ~ScopedRegistryKeyOverride();
47 55
48 private: 56 private:
49 HKEY override_; 57 HKEY override_;
50 base::win::RegKey temp_key_; 58 base::win::RegKey temp_key_;
51 std::wstring temp_name_;
52 59
53 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride); 60 DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride);
54 }; 61 };
55 62
56 std::vector<ScopedRegistryKeyOverride*> overrides_; 63 // Used for testing only.
64 RegistryOverrideManager(const base::Time& timestamp,
65 const string16& test_key_root);
66
67 base::Time timestamp_;
68 string16 guid_;
69
70 string16 test_key_root_;
71 ScopedVector<ScopedRegistryKeyOverride> overrides_;
57 72
58 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager); 73 DISALLOW_COPY_AND_ASSIGN(RegistryOverrideManager);
59 }; 74 };
60 75
61 } // namespace registry_util 76 } // namespace registry_util
62 77
63 #endif // BASE_TEST_TEST_REG_UTIL_H_ 78 #endif // BASE_TEST_TEST_REG_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698