OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Main entry point for all unit tests. | 5 // Main entry point for all unit tests. |
6 | 6 |
7 #include "rlz_test_helpers.h" | 7 #include "rlz_test_helpers.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "rlz/lib/rlz_lib.h" | 17 #include "rlz/lib/rlz_lib.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include <shlwapi.h> | 21 #include <shlwapi.h> |
22 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
23 #include "base/win/windows_version.h" | |
24 #elif defined(OS_POSIX) | 23 #elif defined(OS_POSIX) |
25 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
26 #include "rlz/lib/rlz_value_store.h" | 25 #include "rlz/lib/rlz_value_store.h" |
27 #endif | 26 #endif |
28 | 27 |
29 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 // Path to recursively copy into the replacemment hives. These are needed | 32 // Path to recursively copy into the replacemment hives. These are needed |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Initialize temporary HKLM/HKCU registry hives used for testing. | 92 // Initialize temporary HKLM/HKCU registry hives used for testing. |
94 // Testing RLZ requires reading and writing to the Windows registry. To keep | 93 // Testing RLZ requires reading and writing to the Windows registry. To keep |
95 // the tests isolated from the machine's state, as well as to prevent the tests | 94 // the tests isolated from the machine's state, as well as to prevent the tests |
96 // from causing side effects in the registry, HKCU and HKLM are overridden for | 95 // from causing side effects in the registry, HKCU and HKLM are overridden for |
97 // the duration of the tests. RLZ tests don't expect the HKCU and KHLM hives to | 96 // the duration of the tests. RLZ tests don't expect the HKCU and KHLM hives to |
98 // be empty though, and this function initializes the minimum value needed so | 97 // be empty though, and this function initializes the minimum value needed so |
99 // that the test will run successfully. | 98 // that the test will run successfully. |
100 void InitializeRegistryOverridesForTesting( | 99 void InitializeRegistryOverridesForTesting( |
101 registry_util::RegistryOverrideManager* override_manager) { | 100 registry_util::RegistryOverrideManager* override_manager) { |
102 // For the moment, the HKCU hive requires no initialization. | 101 // For the moment, the HKCU hive requires no initialization. |
103 const bool do_copy = (base::win::GetVersion() >= base::win::VERSION_WIN7); | |
104 RegistryKeyData data; | 102 RegistryKeyData data; |
105 | 103 |
106 if (do_copy) { | 104 // Copy the following HKLM subtrees to the temporary location so that the |
107 // Copy the following HKLM subtrees to the temporary location so that the | 105 // win32 APIs used by the tests continue to work: |
108 // win32 APIs used by the tests continue to work: | 106 // |
109 // | 107 // HKLM\System\CurrentControlSet\Control\Lsa\AccessProviders |
110 // HKLM\System\CurrentControlSet\Control\Lsa\AccessProviders | 108 // |
111 // | 109 // This seems to be required since Win7. |
112 // This seems to be required since Win7. | 110 ReadRegistryTree(base::win::RegKey(HKEY_LOCAL_MACHINE, |
113 ReadRegistryTree(base::win::RegKey(HKEY_LOCAL_MACHINE, | 111 kHKLMAccessProviders, |
114 kHKLMAccessProviders, | 112 KEY_READ), &data); |
115 KEY_READ), &data); | |
116 } | |
117 | 113 |
118 ASSERT_NO_FATAL_FAILURE( | 114 ASSERT_NO_FATAL_FAILURE( |
119 override_manager->OverrideRegistry(HKEY_LOCAL_MACHINE)); | 115 override_manager->OverrideRegistry(HKEY_LOCAL_MACHINE)); |
120 ASSERT_NO_FATAL_FAILURE( | 116 ASSERT_NO_FATAL_FAILURE( |
121 override_manager->OverrideRegistry(HKEY_CURRENT_USER)); | 117 override_manager->OverrideRegistry(HKEY_CURRENT_USER)); |
122 | 118 |
123 if (do_copy) { | 119 base::win::RegKey key( |
124 base::win::RegKey key( | 120 HKEY_LOCAL_MACHINE, kHKLMAccessProviders, KEY_ALL_ACCESS); |
125 HKEY_LOCAL_MACHINE, kHKLMAccessProviders, KEY_ALL_ACCESS); | 121 WriteRegistryTree(data, &key); |
126 WriteRegistryTree(data, &key); | |
127 } | |
128 } | 122 } |
129 | 123 |
130 } // namespace | 124 } // namespace |
131 | 125 |
132 #endif // defined(OS_WIN) | 126 #endif // defined(OS_WIN) |
133 | 127 |
134 void RlzLibTestNoMachineStateHelper::SetUp() { | 128 void RlzLibTestNoMachineStateHelper::SetUp() { |
135 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
136 ASSERT_NO_FATAL_FAILURE( | 130 ASSERT_NO_FATAL_FAILURE( |
137 InitializeRegistryOverridesForTesting(&override_manager_)); | 131 InitializeRegistryOverridesForTesting(&override_manager_)); |
(...skipping 19 matching lines...) Expand all Loading... |
157 void RlzLibTestNoMachineState::TearDown() { | 151 void RlzLibTestNoMachineState::TearDown() { |
158 m_rlz_test_helper_.TearDown(); | 152 m_rlz_test_helper_.TearDown(); |
159 } | 153 } |
160 | 154 |
161 void RlzLibTestBase::SetUp() { | 155 void RlzLibTestBase::SetUp() { |
162 RlzLibTestNoMachineState::SetUp(); | 156 RlzLibTestNoMachineState::SetUp(); |
163 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
164 rlz_lib::CreateMachineState(); | 158 rlz_lib::CreateMachineState(); |
165 #endif // defined(OS_WIN) | 159 #endif // defined(OS_WIN) |
166 } | 160 } |
OLD | NEW |