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

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

Issue 2692843002: Fail tests fast if overriding the Windows registry fails. (Closed)
Patch Set: sync to position 450085 Created 3 years, 10 months 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
« no previous file with comments | « base/test/test_reg_util_win.h ('k') | base/test/test_reg_util_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/test/test_reg_util_win.h" 5 #include "base/test/test_reg_util_win.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 key_path += kTimestampDelimiter + base::ASCIIToUTF16(base::GenerateGUID()); 63 key_path += kTimestampDelimiter + base::ASCIIToUTF16(base::GenerateGUID());
64 64
65 return key_path; 65 return key_path;
66 } 66 }
67 67
68 } // namespace 68 } // namespace
69 69
70 RegistryOverrideManager::ScopedRegistryKeyOverride::ScopedRegistryKeyOverride( 70 RegistryOverrideManager::ScopedRegistryKeyOverride::ScopedRegistryKeyOverride(
71 HKEY override, 71 HKEY override,
72 const base::string16& key_path) 72 const base::string16& key_path)
73 : override_(override) { 73 : override_(override), key_path_(key_path) {}
74 EXPECT_EQ(
75 ERROR_SUCCESS,
76 temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
77 EXPECT_EQ(ERROR_SUCCESS,
78 ::RegOverridePredefKey(override_, temp_key_.Handle()));
79 }
80 74
81 RegistryOverrideManager:: 75 RegistryOverrideManager::
82 ScopedRegistryKeyOverride::~ScopedRegistryKeyOverride() { 76 ScopedRegistryKeyOverride::~ScopedRegistryKeyOverride() {
83 ::RegOverridePredefKey(override_, NULL); 77 ::RegOverridePredefKey(override_, NULL);
84 temp_key_.DeleteKey(L""); 78 base::win::RegKey(HKEY_CURRENT_USER, L"", KEY_QUERY_VALUE)
79 .DeleteKey(key_path_.c_str());
85 } 80 }
86 81
87 RegistryOverrideManager::RegistryOverrideManager() 82 RegistryOverrideManager::RegistryOverrideManager()
88 : timestamp_(base::Time::Now()), test_key_root_(kTempTestKeyPath) { 83 : timestamp_(base::Time::Now()), test_key_root_(kTempTestKeyPath) {
89 DeleteStaleTestKeys(timestamp_, test_key_root_); 84 DeleteStaleTestKeys(timestamp_, test_key_root_);
90 } 85 }
91 86
92 RegistryOverrideManager::RegistryOverrideManager( 87 RegistryOverrideManager::RegistryOverrideManager(
93 const base::Time& timestamp, 88 const base::Time& timestamp,
94 const base::string16& test_key_root) 89 const base::string16& test_key_root)
95 : timestamp_(timestamp), test_key_root_(test_key_root) { 90 : timestamp_(timestamp), test_key_root_(test_key_root) {
96 DeleteStaleTestKeys(timestamp_, test_key_root_); 91 DeleteStaleTestKeys(timestamp_, test_key_root_);
97 } 92 }
98 93
99 RegistryOverrideManager::~RegistryOverrideManager() {} 94 RegistryOverrideManager::~RegistryOverrideManager() {}
100 95
101 void RegistryOverrideManager::OverrideRegistry(HKEY override) { 96 void RegistryOverrideManager::OverrideRegistry(HKEY override) {
102 OverrideRegistry(override, nullptr); 97 OverrideRegistry(override, nullptr);
103 } 98 }
104 99
105 void RegistryOverrideManager::OverrideRegistry(HKEY override, 100 void RegistryOverrideManager::OverrideRegistry(HKEY override,
106 base::string16* override_path) { 101 base::string16* override_path) {
107 base::string16 key_path = GenerateTempKeyPath(test_key_root_, timestamp_); 102 base::string16 key_path = GenerateTempKeyPath(test_key_root_, timestamp_);
103
104 base::win::RegKey temp_key;
105 ASSERT_EQ(ERROR_SUCCESS, temp_key.Create(HKEY_CURRENT_USER, key_path.c_str(),
106 KEY_ALL_ACCESS));
107 ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(override, temp_key.Handle()));
108
108 overrides_.push_back( 109 overrides_.push_back(
109 base::MakeUnique<ScopedRegistryKeyOverride>(override, key_path)); 110 base::MakeUnique<ScopedRegistryKeyOverride>(override, key_path));
110 if (override_path) 111 if (override_path)
111 override_path->assign(key_path); 112 override_path->assign(key_path);
112 } 113 }
113 114
114 base::string16 GenerateTempKeyPath() { 115 base::string16 GenerateTempKeyPath() {
115 return GenerateTempKeyPath(base::string16(kTempTestKeyPath), 116 return GenerateTempKeyPath(base::string16(kTempTestKeyPath),
116 base::Time::Now()); 117 base::Time::Now());
117 } 118 }
118 119
119 } // namespace registry_util 120 } // namespace registry_util
OLDNEW
« no previous file with comments | « base/test/test_reg_util_win.h ('k') | base/test/test_reg_util_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698