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; |
137 ASSERT_TRUE( | 137 nt::GetTestingOverride(nt::HKCU, &temp); |
138 ::SetEnvironmentVariableW(L"hkcu_override", nt::HKCU_override)); | 138 if (temp.length() != 0) { |
grt (UTC plus 2)
2016/09/30 09:32:16
nit: if (!temp.empty())
nit: omit braces :-)
penny
2016/10/01 01:44:25
Can you tell what the coding standard was in my pr
grt (UTC plus 2)
2016/10/02 20:10:54
https://groups.google.com/a/chromium.org/d/msg/chr
| |
139 ASSERT_TRUE(::SetEnvironmentVariableW(L"hkcu_override", temp.c_str())); | |
139 } | 140 } |
140 if (::wcslen(nt::HKLM_override) != 0) { | 141 nt::GetTestingOverride(nt::HKLM, &temp); |
141 ASSERT_TRUE( | 142 if (temp.length() != 0) { |
142 ::SetEnvironmentVariableW(L"hklm_override", nt::HKLM_override)); | 143 ASSERT_TRUE(::SetEnvironmentVariableW(L"hklm_override", temp.c_str())); |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 void SetUp() override { | 147 void SetUp() override { |
147 base::string16 temp; | 148 base::string16 temp; |
148 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); | 149 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); |
149 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); | 150 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); |
150 | 151 |
151 // Make the override path available to our test DLL. | 152 // Make the override path available to our test DLL. |
152 IpcOverrides(); | 153 IpcOverrides(); |
153 | 154 |
154 // Load the main test Dll now. | 155 // Load the main test Dll now. |
155 // Note: this has to happen after we set up the registry overrides. | 156 // Note: this has to happen after we set up the registry overrides. |
156 HMODULE dll = nullptr; | 157 HMODULE dll = nullptr; |
157 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll"); | 158 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll"); |
158 if (!dll) | 159 if (!dll) |
159 return; | 160 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 KEY_QUERY_VALUE | KEY_SET_VALUE)); | 197 KEY_QUERY_VALUE | KEY_SET_VALUE)); |
197 | 198 |
198 // Find out how many dlls were blocked before the test starts. | 199 // Find out how many dlls were blocked before the test starts. |
199 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_); | 200 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_); |
200 } | 201 } |
201 | 202 |
202 void TearDown() override { | 203 void TearDown() override { |
203 TestDll_RemoveDllFromBlacklist(kTestDllName1); | 204 TestDll_RemoveDllFromBlacklist(kTestDllName1); |
204 TestDll_RemoveDllFromBlacklist(kTestDllName2); | 205 TestDll_RemoveDllFromBlacklist(kTestDllName2); |
205 TestDll_RemoveDllFromBlacklist(kTestDllName3); | 206 TestDll_RemoveDllFromBlacklist(kTestDllName3); |
207 | |
208 base::string16 temp = L""; | |
grt (UTC plus 2)
2016/09/30 09:32:16
nit: omit the assignment. just let |temp| be defau
penny
2016/10/01 01:44:25
Done.
| |
209 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); | |
206 } | 210 } |
207 | |
208 // A scoped temporary directory to be destroyed with this test. | |
209 base::ScopedTempDir reg_override_dir_; | |
210 }; | 211 }; |
211 | 212 |
212 TEST_F(BlacklistTest, Beacon) { | 213 TEST_F(BlacklistTest, Beacon) { |
213 // Ensure that the beacon state starts off 'running' for this version. | 214 // Ensure that the beacon state starts off 'running' for this version. |
214 LONG result = blacklist_registry_key_->WriteValue( | 215 LONG result = blacklist_registry_key_->WriteValue( |
215 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING); | 216 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING); |
216 EXPECT_EQ(ERROR_SUCCESS, result); | 217 EXPECT_EQ(ERROR_SUCCESS, result); |
217 | 218 |
218 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, | 219 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, |
219 TEXT(CHROME_VERSION_STRING)); | 220 TEXT(CHROME_VERSION_STRING)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 &blacklist_state); | 383 &blacklist_state); |
383 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); | 384 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); |
384 | 385 |
385 DWORD attempt_count = blacklist::kBeaconMaxAttempts; | 386 DWORD attempt_count = blacklist::kBeaconMaxAttempts; |
386 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, | 387 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, |
387 &attempt_count); | 388 &attempt_count); |
388 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); | 389 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); |
389 } | 390 } |
390 | 391 |
391 } // namespace | 392 } // namespace |
OLD | NEW |