OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 registry_util::RegistryOverrideManager override_manager_; | 126 registry_util::RegistryOverrideManager override_manager_; |
127 | 127 |
128 // The number of dlls initially blocked by the blacklist. | 128 // The number of dlls initially blocked by the blacklist. |
129 int num_initially_blocked_; | 129 int num_initially_blocked_; |
130 | 130 |
131 private: | 131 private: |
132 // This function puts registry-key redirection paths into | 132 // This function puts registry-key redirection paths into |
133 // process-specific environment variables, for our test DLLs to access. | 133 // process-specific environment variables, for our test DLLs to access. |
134 // This will only work as long as the IPC is within the same process. | 134 // This will only work as long as the IPC is within the same process. |
135 void IpcOverrides() { | 135 void IpcOverrides() { |
136 if (::wcslen(nt::HKCU_override) != 0) { | 136 base::string16 temp; |
grt (UTC plus 2)
2016/10/02 20:10:54
nit:
base::string16 temp = nt::GetTestingOverr
penny
2016/10/03 19:18:48
Done.
| |
137 ASSERT_TRUE( | 137 temp = nt::GetTestingOverride(nt::HKCU); |
138 ::SetEnvironmentVariableW(L"hkcu_override", nt::HKCU_override)); | 138 if (temp.length() != 0) |
grt (UTC plus 2)
2016/10/02 20:10:54
nit:
if (!temp.empty())
below, too
penny
2016/10/03 19:18:48
Done.
| |
139 } | 139 ASSERT_TRUE(::SetEnvironmentVariableW(L"hkcu_override", temp.c_str())); |
140 if (::wcslen(nt::HKLM_override) != 0) { | 140 temp = nt::GetTestingOverride(nt::HKLM); |
141 ASSERT_TRUE( | 141 if (temp.length() != 0) |
142 ::SetEnvironmentVariableW(L"hklm_override", nt::HKLM_override)); | 142 ASSERT_TRUE(::SetEnvironmentVariableW(L"hklm_override", temp.c_str())); |
143 } | |
144 } | 143 } |
145 | 144 |
146 void SetUp() override { | 145 void SetUp() override { |
147 base::string16 temp; | 146 base::string16 temp; |
148 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); | 147 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); |
149 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); | 148 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); |
150 | 149 |
151 // Make the override path available to our test DLL. | 150 // Make the override path available to our test DLL. |
152 IpcOverrides(); | 151 IpcOverrides(); |
153 | 152 |
154 // Load the main test Dll now. | 153 // Load the main test Dll now. |
155 // Note: this has to happen after we set up the registry overrides. | 154 // Note: this has to happen after we set up the registry overrides. |
156 HMODULE dll = nullptr; | 155 HMODULE dll = nullptr; |
157 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll"); | 156 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll"); |
158 if (!dll) | 157 if (!dll) |
159 return; | 158 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 KEY_QUERY_VALUE | KEY_SET_VALUE)); | 195 KEY_QUERY_VALUE | KEY_SET_VALUE)); |
197 | 196 |
198 // Find out how many dlls were blocked before the test starts. | 197 // Find out how many dlls were blocked before the test starts. |
199 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_); | 198 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_); |
200 } | 199 } |
201 | 200 |
202 void TearDown() override { | 201 void TearDown() override { |
203 TestDll_RemoveDllFromBlacklist(kTestDllName1); | 202 TestDll_RemoveDllFromBlacklist(kTestDllName1); |
204 TestDll_RemoveDllFromBlacklist(kTestDllName2); | 203 TestDll_RemoveDllFromBlacklist(kTestDllName2); |
205 TestDll_RemoveDllFromBlacklist(kTestDllName3); | 204 TestDll_RemoveDllFromBlacklist(kTestDllName3); |
205 | |
206 base::string16 temp; | |
207 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); | |
grt (UTC plus 2)
2016/10/02 20:10:54
nit:
ASSERT_TRUE(nt::SetTestingOverride(nt::HK
penny
2016/10/03 19:18:48
Done.
| |
206 } | 208 } |
207 | |
208 // A scoped temporary directory to be destroyed with this test. | |
209 base::ScopedTempDir reg_override_dir_; | |
210 }; | 209 }; |
211 | 210 |
212 TEST_F(BlacklistTest, Beacon) { | 211 TEST_F(BlacklistTest, Beacon) { |
213 // Ensure that the beacon state starts off 'running' for this version. | 212 // Ensure that the beacon state starts off 'running' for this version. |
214 LONG result = blacklist_registry_key_->WriteValue( | 213 LONG result = blacklist_registry_key_->WriteValue( |
215 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING); | 214 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING); |
216 EXPECT_EQ(ERROR_SUCCESS, result); | 215 EXPECT_EQ(ERROR_SUCCESS, result); |
217 | 216 |
218 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 217 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
219 TEXT(CHROME_VERSION_STRING)); | 218 TEXT(CHROME_VERSION_STRING)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 &blacklist_state); | 381 &blacklist_state); |
383 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); | 382 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); |
384 | 383 |
385 DWORD attempt_count = blacklist::kBeaconMaxAttempts; | 384 DWORD attempt_count = blacklist::kBeaconMaxAttempts; |
386 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, | 385 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, |
387 &attempt_count); | 386 &attempt_count); |
388 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); | 387 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); |
389 } | 388 } |
390 | 389 |
391 } // namespace | 390 } // namespace |
OLD | NEW |