Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome_elf/blacklist/test/blacklist_test.cc

Issue 2345913003: [chrome_elf] NTRegistry - added wow64 redirection support. (Closed)
Patch Set: Final nits. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome_elf/BUILD.gn ('k') | chrome_elf/blacklist/test/blacklist_test_main_dll.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = nt::GetTestingOverride(nt::HKCU);
137 ASSERT_TRUE( 137 if (!temp.empty())
138 ::SetEnvironmentVariableW(L"hkcu_override", nt::HKCU_override)); 138 ASSERT_TRUE(::SetEnvironmentVariableW(L"hkcu_override", temp.c_str()));
139 } 139 temp = nt::GetTestingOverride(nt::HKLM);
140 if (::wcslen(nt::HKLM_override) != 0) { 140 if (!temp.empty())
141 ASSERT_TRUE( 141 ASSERT_TRUE(::SetEnvironmentVariableW(L"hklm_override", temp.c_str()));
142 ::SetEnvironmentVariableW(L"hklm_override", nt::HKLM_override));
143 }
144 } 142 }
145 143
146 void SetUp() override { 144 void SetUp() override {
147 base::string16 temp; 145 base::string16 temp;
148 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); 146 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp);
149 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); 147 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp));
150 148
151 // Make the override path available to our test DLL. 149 // Make the override path available to our test DLL.
152 IpcOverrides(); 150 IpcOverrides();
153 151
154 // Load the main test Dll now. 152 // Load the main test Dll now.
155 // Note: this has to happen after we set up the registry overrides. 153 // Note: this has to happen after we set up the registry overrides.
156 HMODULE dll = nullptr; 154 HMODULE dll = nullptr;
157 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll"); 155 dll = ::LoadLibraryW(L"blacklist_test_main_dll.dll");
158 if (!dll) 156 if (!dll)
159 return; 157 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 KEY_QUERY_VALUE | KEY_SET_VALUE)); 194 KEY_QUERY_VALUE | KEY_SET_VALUE));
197 195
198 // Find out how many dlls were blocked before the test starts. 196 // Find out how many dlls were blocked before the test starts.
199 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_); 197 TestDll_SuccessfullyBlocked(NULL, &num_initially_blocked_);
200 } 198 }
201 199
202 void TearDown() override { 200 void TearDown() override {
203 TestDll_RemoveDllFromBlacklist(kTestDllName1); 201 TestDll_RemoveDllFromBlacklist(kTestDllName1);
204 TestDll_RemoveDllFromBlacklist(kTestDllName2); 202 TestDll_RemoveDllFromBlacklist(kTestDllName2);
205 TestDll_RemoveDllFromBlacklist(kTestDllName3); 203 TestDll_RemoveDllFromBlacklist(kTestDllName3);
204
205 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, base::string16()));
206 } 206 }
207
208 // A scoped temporary directory to be destroyed with this test.
209 base::ScopedTempDir reg_override_dir_;
210 }; 207 };
211 208
212 TEST_F(BlacklistTest, Beacon) { 209 TEST_F(BlacklistTest, Beacon) {
213 // Ensure that the beacon state starts off 'running' for this version. 210 // Ensure that the beacon state starts off 'running' for this version.
214 LONG result = blacklist_registry_key_->WriteValue( 211 LONG result = blacklist_registry_key_->WriteValue(
215 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING); 212 blacklist::kBeaconState, blacklist::BLACKLIST_SETUP_RUNNING);
216 EXPECT_EQ(ERROR_SUCCESS, result); 213 EXPECT_EQ(ERROR_SUCCESS, result);
217 214
218 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, 215 result = blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
219 TEXT(CHROME_VERSION_STRING)); 216 TEXT(CHROME_VERSION_STRING));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 &blacklist_state); 379 &blacklist_state);
383 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); 380 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING);
384 381
385 DWORD attempt_count = blacklist::kBeaconMaxAttempts; 382 DWORD attempt_count = blacklist::kBeaconMaxAttempts;
386 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, 383 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount,
387 &attempt_count); 384 &attempt_count);
388 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); 385 EXPECT_EQ(static_cast<DWORD>(0), attempt_count);
389 } 386 }
390 387
391 } // namespace 388 } // namespace
OLDNEW
« no previous file with comments | « chrome_elf/BUILD.gn ('k') | chrome_elf/blacklist/test/blacklist_test_main_dll.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698