This source file includes following definitions.
- SetUp
- SetupInfo
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include <windows.h>
#if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
#undef FACILITY_VISUALCPP
#endif
#include <DelayIMP.h>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/scoped_native_library.h"
#include "chrome/app/delay_load_hook_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class ChromeDelayLoadHookTest : public testing::Test {
public:
ChromeDelayLoadHookTest() : proc_ptr_(NULL) {
}
virtual void SetUp() OVERRIDE {
SetupInfo("kernel32.dll");
}
void SetupInfo(const char* dll_name) {
info_.cb = sizeof(info_);
info_.pidd = NULL;
info_.ppfn = &proc_ptr_;
info_.szDll = dll_name;
info_.dlp.fImportByName = TRUE;
info_.dlp.szProcName = "CreateFileA";
info_.hmodCur = NULL;
info_.pfnCur = NULL;
info_.dwLastError = 0;
}
FARPROC proc_ptr_;
DelayLoadInfo info_;
};
}
TEST_F(ChromeDelayLoadHookTest, HooksAreSetAtLinkTime) {
EXPECT_TRUE(__pfnDliNotifyHook2 == ChromeDelayLoadHook);
EXPECT_TRUE(__pfnDliFailureHook2 == ChromeDelayLoadHook);
}
TEST_F(ChromeDelayLoadHookTest, NonSuffixedDllsAreNotHandled) {
SetupInfo("kernel32.dll");
HMODULE none = reinterpret_cast<HMODULE>(
ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
base::ScopedNativeLibrary lib_holder(none);
ASSERT_TRUE(none == NULL);
}
TEST_F(ChromeDelayLoadHookTest, SuffixedDllsAreRedirected) {
SetupInfo("kernel32-delay.dll");
HMODULE kernel32 = reinterpret_cast<HMODULE>(
ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
base::ScopedNativeLibrary lib_holder(kernel32);
ASSERT_TRUE(kernel32 == ::GetModuleHandle(L"kernel32.dll"));
}
TEST_F(ChromeDelayLoadHookTest, IgnoresUnhandledNotifications) {
SetupInfo("kernel32-delay.dll");
EXPECT_TRUE(ChromeDelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
EXPECT_TRUE(ChromeDelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
EXPECT_TRUE(ChromeDelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
EXPECT_TRUE(ChromeDelayLoadHook(dliFailLoadLib, &info_) == NULL);
EXPECT_TRUE(ChromeDelayLoadHook(dliFailGetProc, &info_) == NULL);
}