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 "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 14 matching lines...) Expand all Loading... |
25 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}"; | 25 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}"; |
26 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}"; | 26 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}"; |
27 | 27 |
28 extern const wchar_t* kEnvVars[]; | 28 extern const wchar_t* kEnvVars[]; |
29 | 29 |
30 extern "C" { | 30 extern "C" { |
31 // When modifying the blacklist in the test process, use the exported test dll | 31 // When modifying the blacklist in the test process, use the exported test dll |
32 // functions on the test blacklist dll, not the ones linked into the test | 32 // functions on the test blacklist dll, not the ones linked into the test |
33 // executable itself. | 33 // executable itself. |
34 __declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name); | 34 __declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name); |
35 __declspec(dllimport) bool TestDLL_IsBlacklistInitialized(); | |
36 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist( | 35 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist( |
37 const wchar_t* dll_name); | 36 const wchar_t* dll_name); |
38 } | 37 } |
39 | 38 |
40 class BlacklistTest : public testing::Test { | 39 class BlacklistTest : public testing::Test { |
41 virtual void SetUp() { | 40 virtual void SetUp() { |
42 // Force an import from blacklist_test_main_dll. | 41 // Force an import from blacklist_test_main_dll. |
43 InitBlacklistTestDll(); | 42 InitBlacklistTestDll(); |
44 } | 43 } |
45 | 44 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 113 } |
115 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(added_dlls[0].c_str())); | 114 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(added_dlls[0].c_str())); |
116 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist( | 115 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist( |
117 added_dlls[empty_spaces - 1].c_str())); | 116 added_dlls[empty_spaces - 1].c_str())); |
118 } | 117 } |
119 | 118 |
120 TEST_F(BlacklistTest, LoadBlacklistedLibrary) { | 119 TEST_F(BlacklistTest, LoadBlacklistedLibrary) { |
121 base::FilePath current_dir; | 120 base::FilePath current_dir; |
122 ASSERT_TRUE(PathService::Get(base::DIR_EXE, ¤t_dir)); | 121 ASSERT_TRUE(PathService::Get(base::DIR_EXE, ¤t_dir)); |
123 | 122 |
124 // Ensure that the blacklist is loaded. | |
125 ASSERT_TRUE(TestDLL_IsBlacklistInitialized()); | |
126 | |
127 // Test that an un-blacklisted DLL can load correctly. | 123 // Test that an un-blacklisted DLL can load correctly. |
128 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1)); | 124 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1)); |
129 EXPECT_TRUE(dll1.is_valid()); | 125 EXPECT_TRUE(dll1.is_valid()); |
130 dll1.Reset(NULL); | 126 dll1.Reset(NULL); |
131 | 127 |
132 struct TestData { | 128 struct TestData { |
133 const wchar_t* dll_name; | 129 const wchar_t* dll_name; |
134 const wchar_t* dll_beacon; | 130 const wchar_t* dll_beacon; |
135 } test_data[] = { | 131 } test_data[] = { |
136 { kTestDllName2, kDll2Beacon }, | 132 { kTestDllName2, kDll2Beacon }, |
(...skipping 26 matching lines...) Expand all Loading... |
163 EXPECT_TRUE(TestDll_AddDllToBlacklist(uppercase_name.c_str())); | 159 EXPECT_TRUE(TestDll_AddDllToBlacklist(uppercase_name.c_str())); |
164 base::ScopedNativeLibrary dll_blacklisted_different_case( | 160 base::ScopedNativeLibrary dll_blacklisted_different_case( |
165 current_dir.Append(test_data[i].dll_name)); | 161 current_dir.Append(test_data[i].dll_name)); |
166 EXPECT_FALSE(dll_blacklisted_different_case.is_valid()); | 162 EXPECT_FALSE(dll_blacklisted_different_case.is_valid()); |
167 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); | 163 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); |
168 dll_blacklisted_different_case.Reset(NULL); | 164 dll_blacklisted_different_case.Reset(NULL); |
169 | 165 |
170 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str())); | 166 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str())); |
171 } | 167 } |
172 } | 168 } |
OLD | NEW |