diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-14 07:43:20 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-14 07:43:20 +0000 |
commit | 20402235d708145f61c1fe41a4d7b8ddc35a15be (patch) | |
tree | 9acfda4ab3c09257f8515019c63a4981c49859c5 /rlz/win | |
parent | b7c04c11491d6c37c22b9ebb49696cafefb38c09 (diff) | |
download | chromium_src-20402235d708145f61c1fe41a4d7b8ddc35a15be.zip chromium_src-20402235d708145f61c1fe41a4d7b8ddc35a15be.tar.gz chromium_src-20402235d708145f61c1fe41a4d7b8ddc35a15be.tar.bz2 |
Use RegistryOverrideManager properly in RLZ tests.
Previously, rlz/test/rlz_test_helpers.cc and
chrome/browser/rlz/rlz_unittest.cc each did somewhat different things to
prepare the registry for tests. Now, rlz_test_helpers.cc does the prep
the right way using RegistryOverrideManager and rlz_unittests.cc uses
rlz_test_helpers.cc.
This unblocks the refactor in r234367 that was reverted in r234627.
BUG=314800
R=rogerta@chromium.org, tommycli@chromium.org
Review URL: https://codereview.chromium.org/63153009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'rlz/win')
-rw-r--r-- | rlz/win/dll/exports.cc | 2 | ||||
-rw-r--r-- | rlz/win/lib/machine_deal.h | 2 | ||||
-rw-r--r-- | rlz/win/lib/rlz_lib.h | 56 | ||||
-rw-r--r-- | rlz/win/lib/rlz_lib_win.cc | 53 |
4 files changed, 3 insertions, 110 deletions
diff --git a/rlz/win/dll/exports.cc b/rlz/win/dll/exports.cc index efe5cd98..eb7d88d 100644 --- a/rlz/win/dll/exports.cc +++ b/rlz/win/dll/exports.cc @@ -4,7 +4,7 @@ // // Functions exported by the RLZ DLL. -#include "rlz/win/lib/rlz_lib.h" +#include "rlz/lib/rlz_lib.h" #define RLZ_DLL_EXPORT extern "C" __declspec(dllexport) diff --git a/rlz/win/lib/machine_deal.h b/rlz/win/lib/machine_deal.h index 5b8b84a..b6156c4 100644 --- a/rlz/win/lib/machine_deal.h +++ b/rlz/win/lib/machine_deal.h @@ -8,7 +8,7 @@ #define RLZ_WIN_LIB_MACHINE_DEAL_H_ #include <string> -#include "rlz/win/lib/rlz_lib.h" +#include "rlz/lib/rlz_lib.h" namespace rlz_lib { diff --git a/rlz/win/lib/rlz_lib.h b/rlz/win/lib/rlz_lib.h deleted file mode 100644 index 3adbf97..0000000 --- a/rlz/win/lib/rlz_lib.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// A library to manage RLZ information for access-points shared -// across different client applications. -// -// All functions return true on success and false on error. -// This implemenation is thread safe. -// -// Each prototype mentions the registry access requirements: -// -// HKLM read: Will work from any process and at any privilege level on Vista. -// HKCU read: Calls made from the SYSTEM account must pass the current user's -// SID as the optional 'sid' param. Can be called from low integrity -// process on Vista. -// HKCU write: Calls made from the SYSTEM account must pass the current user's -// SID as the optional 'sid' param. Calls require at least medium -// integrity on Vista (e.g. Toolbar will need to use their broker) -// HKLM write: Calls must be made from an account with admin rights. No SID -// need be passed when running as SYSTEM. -// Functions which do not access registry will be marked with "no restrictions". - -#ifndef RLZ_WIN_LIB_RLZ_LIB_H_ -#define RLZ_WIN_LIB_RLZ_LIB_H_ - -// Clients can get away by just including rlz/lib/rlz_lib.h. This file only -// contains function definitions for files used by tests. It's mostly kept -// around for backwards-compatibility. - -#include "rlz/lib/rlz_lib.h" - -#include "base/win/registry.h" - -namespace rlz_lib { - -#if defined(OS_WIN) - -// Initialize temporary HKLM/HKCU registry hives used for testing. -// Testing RLZ requires reading and writing to the Windows registry. To keep -// the tests isolated from the machine's state, as well as to prevent the tests -// from causing side effects in the registry, HKCU and HKLM are overridden for -// the duration of the tests. RLZ tests don't expect the HKCU and KHLM hives to -// be empty though, and this function initializes the minimum value needed so -// that the test will run successfully. -// -// The two arguments to this function should be the keys that will represent -// the HKLM and HKCU registry hives during the tests. This function should be -// called *before* the hives are overridden. -void InitializeTempHivesForTesting(const base::win::RegKey& temp_hklm_key, - const base::win::RegKey& temp_hkcu_key); -#endif // defined(OS_WIN) - -} // namespace rlz_lib - -#endif // RLZ_WIN_LIB_RLZ_LIB_H_ diff --git a/rlz/win/lib/rlz_lib_win.cc b/rlz/win/lib/rlz_lib_win.cc index d8b1c1e..c765560 100644 --- a/rlz/win/lib/rlz_lib_win.cc +++ b/rlz/win/lib/rlz_lib_win.cc @@ -5,7 +5,7 @@ // A library to manage RLZ information for access-points shared // across different client applications. -#include "rlz/win/lib/rlz_lib.h" +#include "rlz/lib/rlz_lib.h" #include <windows.h> #include <aclapi.h> @@ -13,42 +13,11 @@ #include "base/basictypes.h" #include "base/win/registry.h" -#include "base/win/windows_version.h" #include "rlz/lib/assert.h" #include "rlz/lib/rlz_value_store.h" #include "rlz/win/lib/machine_deal.h" #include "rlz/win/lib/rlz_value_store_registry.h" -namespace { - -// Path to recursively copy into the replacemment hives. These are needed -// to make sure certain win32 APIs continue to run correctly once the real -// hives are replaced. -const wchar_t* kHKLMAccessProviders = - L"System\\CurrentControlSet\\Control\\Lsa\\AccessProviders"; - -// Helper functions - -void CopyRegistryTree(const base::win::RegKey& src, base::win::RegKey* dest) { - // First copy values. - for (base::win::RegistryValueIterator i(src.Handle(), L""); - i.Valid(); ++i) { - dest->WriteValue(i.Name(), reinterpret_cast<const void*>(i.Value()), - i.ValueSize(), i.Type()); - } - - // Next copy subkeys recursively. - for (base::win::RegistryKeyIterator i(src.Handle(), L""); - i.Valid(); ++i) { - base::win::RegKey subkey(dest->Handle(), i.Name(), KEY_ALL_ACCESS); - CopyRegistryTree(base::win::RegKey(src.Handle(), i.Name(), KEY_READ), - &subkey); - } -} - -} // namespace anonymous - - namespace rlz_lib { // OEM Deal confirmation storage functions. @@ -237,24 +206,4 @@ bool SetMachineDealCodeFromPingResponse(const char* response) { return MachineDealCode::SetFromPingResponse(response); } -void InitializeTempHivesForTesting(const base::win::RegKey& temp_hklm_key, - const base::win::RegKey& temp_hkcu_key) { - // For the moment, the HKCU hive requires no initialization. - - if (base::win::GetVersion() >= base::win::VERSION_WIN7) { - // Copy the following HKLM subtrees to the temporary location so that the - // win32 APIs used by the tests continue to work: - // - // HKLM\System\CurrentControlSet\Control\Lsa\AccessProviders - // - // This seems to be required since Win7. - base::win::RegKey dest(temp_hklm_key.Handle(), kHKLMAccessProviders, - KEY_ALL_ACCESS); - CopyRegistryTree(base::win::RegKey(HKEY_LOCAL_MACHINE, - kHKLMAccessProviders, - KEY_READ), - &dest); - } -} - } // namespace rlz_lib |