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

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

Issue 1513043002: clang/win: Let remaining chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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
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 "base/environment.h" 5 #include "base/environment.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_native_library.h" 10 #include "base/scoped_native_library.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 class BlacklistTest : public testing::Test { 58 class BlacklistTest : public testing::Test {
59 protected: 59 protected:
60 BlacklistTest() : override_manager_(), num_initially_blocked_(0) { 60 BlacklistTest() : override_manager_(), num_initially_blocked_(0) {
61 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); 61 override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
62 } 62 }
63 63
64 void CheckBlacklistedDllsNotLoaded() { 64 void CheckBlacklistedDllsNotLoaded() {
65 base::FilePath current_dir; 65 base::FilePath current_dir;
66 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir)); 66 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
67 67
68 for (int i = 0; i < arraysize(test_data); ++i) { 68 for (size_t i = 0; i < arraysize(test_data); ++i) {
69 // Ensure that the dll has not been loaded both by inspecting the handle 69 // Ensure that the dll has not been loaded both by inspecting the handle
70 // returned by LoadLibrary and by looking for an environment variable that 70 // returned by LoadLibrary and by looking for an environment variable that
71 // is set when the DLL's entry point is called. 71 // is set when the DLL's entry point is called.
72 base::ScopedNativeLibrary dll_blacklisted( 72 base::ScopedNativeLibrary dll_blacklisted(
73 current_dir.Append(test_data[i].dll_name)); 73 current_dir.Append(test_data[i].dll_name));
74 EXPECT_FALSE(dll_blacklisted.is_valid()); 74 EXPECT_FALSE(dll_blacklisted.is_valid());
75 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); 75 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
76 dll_blacklisted.Reset(NULL); 76 dll_blacklisted.Reset(NULL);
77 77
78 // Ensure that the dll is recorded as blocked. 78 // Ensure that the dll is recorded as blocked.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Test that an un-blacklisted DLL can load correctly. 226 // Test that an un-blacklisted DLL can load correctly.
227 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1)); 227 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1));
228 EXPECT_TRUE(dll1.is_valid()); 228 EXPECT_TRUE(dll1.is_valid());
229 dll1.Reset(NULL); 229 dll1.Reset(NULL);
230 230
231 int num_blocked_dlls = 0; 231 int num_blocked_dlls = 0;
232 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls); 232 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
233 EXPECT_EQ(num_initially_blocked_, num_blocked_dlls); 233 EXPECT_EQ(num_initially_blocked_, num_blocked_dlls);
234 234
235 // Add all DLLs to the blacklist then check they are blocked. 235 // Add all DLLs to the blacklist then check they are blocked.
236 for (int i = 0; i < arraysize(test_data); ++i) { 236 for (size_t i = 0; i < arraysize(test_data); ++i) {
237 EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name)); 237 EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name));
238 } 238 }
239 CheckBlacklistedDllsNotLoaded(); 239 CheckBlacklistedDllsNotLoaded();
240 } 240 }
241 241
242 TEST_F(BlacklistTest, AddDllsFromRegistryToBlacklist) { 242 TEST_F(BlacklistTest, AddDllsFromRegistryToBlacklist) {
243 // Ensure that the blacklist is loaded. 243 // Ensure that the blacklist is loaded.
244 ASSERT_TRUE(TestDll_IsBlacklistInitialized()); 244 ASSERT_TRUE(TestDll_IsBlacklistInitialized());
245 245
246 // Delete the finch registry key to clear its values. 246 // Delete the finch registry key to clear its values.
247 base::win::RegKey key(HKEY_CURRENT_USER, 247 base::win::RegKey key(HKEY_CURRENT_USER,
248 blacklist::kRegistryFinchListPath, 248 blacklist::kRegistryFinchListPath,
249 KEY_QUERY_VALUE | KEY_SET_VALUE); 249 KEY_QUERY_VALUE | KEY_SET_VALUE);
250 key.DeleteKey(L""); 250 key.DeleteKey(L"");
251 251
252 // Add the test dlls to the registry (with their name as both key and value). 252 // Add the test dlls to the registry (with their name as both key and value).
253 base::win::RegKey finch_blacklist_registry_key( 253 base::win::RegKey finch_blacklist_registry_key(
254 HKEY_CURRENT_USER, 254 HKEY_CURRENT_USER,
255 blacklist::kRegistryFinchListPath, 255 blacklist::kRegistryFinchListPath,
256 KEY_QUERY_VALUE | KEY_SET_VALUE); 256 KEY_QUERY_VALUE | KEY_SET_VALUE);
257 for (int i = 0; i < arraysize(test_data); ++i) { 257 for (size_t i = 0; i < arraysize(test_data); ++i) {
258 finch_blacklist_registry_key.WriteValue(test_data[i].dll_name, 258 finch_blacklist_registry_key.WriteValue(test_data[i].dll_name,
259 test_data[i].dll_name); 259 test_data[i].dll_name);
260 } 260 }
261 261
262 TestDll_AddDllsFromRegistryToBlacklist(); 262 TestDll_AddDllsFromRegistryToBlacklist();
263 CheckBlacklistedDllsNotLoaded(); 263 CheckBlacklistedDllsNotLoaded();
264 } 264 }
265 265
266 void TestResetBeacon(scoped_ptr<base::win::RegKey>& key, 266 void TestResetBeacon(scoped_ptr<base::win::RegKey>& key,
267 DWORD input_state, 267 DWORD input_state,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 &blacklist_state); 336 &blacklist_state);
337 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING); 337 EXPECT_EQ(blacklist_state, blacklist::BLACKLIST_SETUP_RUNNING);
338 338
339 DWORD attempt_count = blacklist::kBeaconMaxAttempts; 339 DWORD attempt_count = blacklist::kBeaconMaxAttempts;
340 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount, 340 blacklist_registry_key_->ReadValueDW(blacklist::kBeaconAttemptCount,
341 &attempt_count); 341 &attempt_count);
342 EXPECT_EQ(static_cast<DWORD>(0), attempt_count); 342 EXPECT_EQ(static_cast<DWORD>(0), attempt_count);
343 } 343 }
344 344
345 } // namespace 345 } // namespace
OLDNEW
« no previous file with comments | « chrome/utility/importer/edge_database_reader_unittest_win.cc ('k') | chrome_elf/elf_imports_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698