Chromium Code Reviews| Index: chrome_elf/blacklist/test/blacklist_test.cc |
| diff --git a/chrome_elf/blacklist/test/blacklist_test.cc b/chrome_elf/blacklist/test/blacklist_test.cc |
| index 39db737138c2852ed19bec7018ad24b5391193a2..7ff819390a5afadedba8a8ce4f1d7f8aed6dc6b6 100644 |
| --- a/chrome_elf/blacklist/test/blacklist_test.cc |
| +++ b/chrome_elf/blacklist/test/blacklist_test.cc |
| @@ -32,9 +32,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 { |
| @@ -117,18 +120,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(); |
| + int k_desired_blacklist_size = 5; |
|
Alexei Svitkine (slow)
2014/02/25 15:00:20
Nit: This should probably be:
const int kDesiredB
csharp
2014/02/25 15:20:50
Done.
|
| + for (int i = blacklist_size; i < k_desired_blacklist_size; ++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 < k_desired_blacklist_size; ++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, ¤t_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; |
| @@ -147,6 +182,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)); |
| @@ -168,5 +210,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); |
| } |
| } |