| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Utilities for testing. | 5 // Utilities for testing. |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ceee/testing/utils/test_utils.h" | 10 #include "ceee/testing/utils/test_utils.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ScopedRegistryOverride::Override() { | 187 void ScopedRegistryOverride::Override() { |
| 188 // Wipe the keys we redirect to. | 188 // Wipe the keys we redirect to. |
| 189 // This gives us a stable run, even in the presence of previous | 189 // This gives us a stable run, even in the presence of previous |
| 190 // crashes or failures. | 190 // crashes or failures. |
| 191 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kReplacementRoot); | 191 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kReplacementRoot); |
| 192 ASSERT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | 192 ASSERT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); |
| 193 | 193 |
| 194 // Create the keys we're redirecting HKCU and HKLM to. | 194 // Create the keys we're redirecting HKCU and HKLM to. |
| 195 ASSERT_TRUE(hkcu_.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); | 195 ASSERT_EQ(ERROR_SUCCESS, |
| 196 ASSERT_TRUE(hklm_.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); | 196 hkcu_.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); |
| 197 ASSERT_EQ(ERROR_SUCCESS, |
| 198 hklm_.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); |
| 197 | 199 |
| 198 // Switch keys. | 200 // Switch keys. |
| 199 ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, | 201 ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, |
| 200 hkcu_.Handle())); | 202 hkcu_.Handle())); |
| 201 ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, | 203 ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, |
| 202 hklm_.Handle())); | 204 hklm_.Handle())); |
| 203 } | 205 } |
| 204 | 206 |
| 205 ScopedRegistryOverride::~ScopedRegistryOverride() { | 207 ScopedRegistryOverride::~ScopedRegistryOverride() { |
| 206 // Undo the redirection. | 208 // Undo the redirection. |
| 207 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | 209 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); |
| 208 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); | 210 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); |
| 209 | 211 |
| 210 // Close our handles and delete the temp keys we redirected to. | 212 // Close our handles and delete the temp keys we redirected to. |
| 211 hkcu_.Close(); | 213 hkcu_.Close(); |
| 212 hklm_.Close(); | 214 hklm_.Close(); |
| 213 EXPECT_EQ(ERROR_SUCCESS, SHDeleteKey(HKEY_CURRENT_USER, kReplacementRoot)); | 215 EXPECT_EQ(ERROR_SUCCESS, SHDeleteKey(HKEY_CURRENT_USER, kReplacementRoot)); |
| 214 } | 216 } |
| 215 | 217 |
| 216 } // namespace testing | 218 } // namespace testing |
| OLD | NEW |