summaryrefslogtreecommitdiffstats
path: root/chrome_elf/blacklist/test
diff options
context:
space:
mode:
authorcsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 17:01:41 +0000
committercsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 17:01:41 +0000
commitc80b3502ba5dda8c0fa8f712f585aa1aad45f385 (patch)
treebd4ff65796243c61e215dfb2bb0eedc1602369aa /chrome_elf/blacklist/test
parent12cc5113da4e1b49cb7c88d56f7c1599365ee3ce (diff)
downloadchromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.zip
chromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.tar.gz
chromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.tar.bz2
Add UMA stats to record when DLLs are successfully blocked in the Browser.
BUG=345287 Review URL: https://codereview.chromium.org/174013007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_elf/blacklist/test')
-rw-r--r--chrome_elf/blacklist/test/blacklist_test.cc51
-rw-r--r--chrome_elf/blacklist/test/blacklist_test_main_dll.def3
2 files changed, 51 insertions, 3 deletions
diff --git a/chrome_elf/blacklist/test/blacklist_test.cc b/chrome_elf/blacklist/test/blacklist_test.cc
index 096502d..e507446 100644
--- a/chrome_elf/blacklist/test/blacklist_test.cc
+++ b/chrome_elf/blacklist/test/blacklist_test.cc
@@ -33,9 +33,12 @@ extern "C" {
// functions on the test blacklist dll, not the ones linked into the test
// executable itself.
__declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name);
-__declspec(dllimport) bool TestDLL_IsBlacklistInitialized();
+__declspec(dllimport) bool TestDll_IsBlacklistInitialized();
__declspec(dllimport) bool TestDll_RemoveDllFromBlacklist(
const wchar_t* dll_name);
+__declspec(dllimport) bool TestDll_SuccessfullyBlocked(
+ const wchar_t** blocked_dlls,
+ int* size);
}
class BlacklistTest : public testing::Test {
@@ -118,18 +121,50 @@ TEST_F(BlacklistTest, AddAndRemoveModules) {
added_dlls[empty_spaces - 1].c_str()));
}
+TEST_F(BlacklistTest, SuccessfullyBlocked) {
+ // Ensure that we have at least 5 dlls to blacklist.
+ int blacklist_size = blacklist::BlacklistSize();
+ const int kDesiredBlacklistSize = 5;
+ for (int i = blacklist_size; i < kDesiredBlacklistSize; ++i) {
+ base::string16 new_dll_name(base::IntToString16(i) + L".dll");
+ EXPECT_TRUE(blacklist::AddDllToBlacklist(new_dll_name.c_str()));
+ }
+
+ // Block 5 dlls, one at a time, starting from the end of the list, and
+ // ensuring SuccesfullyBlocked correctly passes the list of blocked dlls.
+ for (int i = 0; i < kDesiredBlacklistSize; ++i) {
+ blacklist::BlockedDll(i);
+
+ int size = 0;
+ blacklist::SuccessfullyBlocked(NULL, &size);
+ EXPECT_EQ(i + 1, size);
+
+ std::vector<const wchar_t*> blocked_dlls(size);
+ blacklist::SuccessfullyBlocked(&(blocked_dlls[0]), &size);
+ EXPECT_EQ(i + 1, size);
+
+ for (size_t j = 0; j < blocked_dlls.size(); ++j) {
+ EXPECT_EQ(blocked_dlls[j], blacklist::g_troublesome_dlls[j]);
+ }
+ }
+}
+
TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
base::FilePath current_dir;
ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
// Ensure that the blacklist is loaded.
- ASSERT_TRUE(TestDLL_IsBlacklistInitialized());
+ ASSERT_TRUE(TestDll_IsBlacklistInitialized());
// Test that an un-blacklisted DLL can load correctly.
base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1));
EXPECT_TRUE(dll1.is_valid());
dll1.Reset(NULL);
+ int num_blocked_dlls = 0;
+ TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
+ EXPECT_EQ(0, num_blocked_dlls);
+
struct TestData {
const wchar_t* dll_name;
const wchar_t* dll_beacon;
@@ -148,6 +183,13 @@ TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
dll_blacklisted.Reset(NULL);
+ // Ensure that the dll is recorded as blocked.
+ int array_size = 1;
+ const wchar_t* blocked_dll = NULL;
+ TestDll_SuccessfullyBlocked(&blocked_dll, &array_size);
+ EXPECT_EQ(1, array_size);
+ EXPECT_EQ(test_data[i].dll_name, base::string16(blocked_dll));
+
// Remove the DLL from the blacklist. Ensure that it loads and that its
// entry point was called.
EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(test_data[i].dll_name));
@@ -169,5 +211,10 @@ TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
dll_blacklisted_different_case.Reset(NULL);
EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str()));
+
+ // The blocked dll was removed, so we shouldn't get anything returned
+ // here.
+ TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
+ EXPECT_EQ(0, num_blocked_dlls);
}
}
diff --git a/chrome_elf/blacklist/test/blacklist_test_main_dll.def b/chrome_elf/blacklist/test/blacklist_test_main_dll.def
index 82e0f0e..920dc6c 100644
--- a/chrome_elf/blacklist/test/blacklist_test_main_dll.def
+++ b/chrome_elf/blacklist/test/blacklist_test_main_dll.def
@@ -6,6 +6,7 @@ LIBRARY "blacklist_test_main_dll.dll"
EXPORTS
TestDll_AddDllToBlacklist=AddDllToBlacklist
- TestDLL_IsBlacklistInitialized=IsBlacklistInitialized
+ TestDll_IsBlacklistInitialized=IsBlacklistInitialized
+ TestDll_SuccessfullyBlocked=SuccessfullyBlocked
TestDll_RemoveDllFromBlacklist=RemoveDllFromBlacklist
InitBlacklistTestDll \ No newline at end of file