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

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

Issue 164833002: Revert 251095 "Revert 250828 "Add a UMA stat to track if the Bro..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 14 matching lines...) Expand all
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();
35 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist( 36 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist(
36 const wchar_t* dll_name); 37 const wchar_t* dll_name);
37 } 38 }
38 39
39 class BlacklistTest : public testing::Test { 40 class BlacklistTest : public testing::Test {
40 virtual void SetUp() { 41 virtual void SetUp() {
41 // Force an import from blacklist_test_main_dll. 42 // Force an import from blacklist_test_main_dll.
42 InitBlacklistTestDll(); 43 InitBlacklistTestDll();
43 } 44 }
44 45
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 114 }
114 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(added_dlls[0].c_str())); 115 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(added_dlls[0].c_str()));
115 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist( 116 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(
116 added_dlls[empty_spaces - 1].c_str())); 117 added_dlls[empty_spaces - 1].c_str()));
117 } 118 }
118 119
119 TEST_F(BlacklistTest, LoadBlacklistedLibrary) { 120 TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
120 base::FilePath current_dir; 121 base::FilePath current_dir;
121 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir)); 122 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
122 123
124 // Ensure that the blacklist is loaded.
125 ASSERT_TRUE(TestDLL_IsBlacklistInitialized());
126
123 // Test that an un-blacklisted DLL can load correctly. 127 // Test that an un-blacklisted DLL can load correctly.
124 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1)); 128 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1));
125 EXPECT_TRUE(dll1.is_valid()); 129 EXPECT_TRUE(dll1.is_valid());
126 dll1.Reset(NULL); 130 dll1.Reset(NULL);
127 131
128 struct TestData { 132 struct TestData {
129 const wchar_t* dll_name; 133 const wchar_t* dll_name;
130 const wchar_t* dll_beacon; 134 const wchar_t* dll_beacon;
131 } test_data[] = { 135 } test_data[] = {
132 { kTestDllName2, kDll2Beacon }, 136 { kTestDllName2, kDll2Beacon },
(...skipping 26 matching lines...) Expand all
159 EXPECT_TRUE(TestDll_AddDllToBlacklist(uppercase_name.c_str())); 163 EXPECT_TRUE(TestDll_AddDllToBlacklist(uppercase_name.c_str()));
160 base::ScopedNativeLibrary dll_blacklisted_different_case( 164 base::ScopedNativeLibrary dll_blacklisted_different_case(
161 current_dir.Append(test_data[i].dll_name)); 165 current_dir.Append(test_data[i].dll_name));
162 EXPECT_FALSE(dll_blacklisted_different_case.is_valid()); 166 EXPECT_FALSE(dll_blacklisted_different_case.is_valid());
163 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); 167 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
164 dll_blacklisted_different_case.Reset(NULL); 168 dll_blacklisted_different_case.Reset(NULL);
165 169
166 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str())); 170 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str()));
167 } 171 }
168 } 172 }
OLDNEW
« no previous file with comments | « trunk/src/chrome_elf/blacklist/blacklist.cc ('k') | trunk/src/chrome_elf/blacklist/test/blacklist_test_main_dll.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698