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

Unified Diff: base/win/delay_load_hook_unittest.cc

Issue 12295040: Stop delay loading user32.dll from chrome.dll on x86/Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« base/win/delay_load_hook.cc ('K') | « base/win/delay_load_hook.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/delay_load_hook_unittest.cc
diff --git a/base/win/delay_load_hook_unittest.cc b/base/win/delay_load_hook_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..561c514070985171b20da99c708bce93c30813ec
--- /dev/null
+++ b/base/win/delay_load_hook_unittest.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
+// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h, and in
+// delayimp.h previous to VS2012.
+#undef FACILITY_VISUALCPP
+#endif
+#include <DelayIMP.h>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/scoped_native_library.h"
+#include "base/win/delay_load_hook.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace win {
+
+namespace {
+
+class DelayLoadHookTest : public testing::Test {
+ public:
+ DelayLoadHookTest() : 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_;
+};
+
+} // namespace
+
+TEST_F(DelayLoadHookTest, HooksAreSetAtLinkTime) {
+ // This test verifies that referencing the ChromeDelayLoadHook at link
+ // time results in overriding the delay loader's hook instances in the CRT
+ // appropriately.
+ EXPECT_TRUE(__pfnDliNotifyHook2 == ChromeDelayLoadHook);
+ EXPECT_TRUE(__pfnDliFailureHook2 == ChromeDelayLoadHook);
+}
+
+TEST_F(DelayLoadHookTest, NonSuffixedDllsAreNotHandled) {
+ // The hook should ignore non-suffixed DLLs.
+ SetupInfo("kernel32.dll");
+
+ HMODULE none = reinterpret_cast<HMODULE>(
+ ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
+ // Make sure the library is released on exit.
+ base::ScopedNativeLibrary lib_holder(none);
+
+ ASSERT_TRUE(none == NULL);
+}
+
+TEST_F(DelayLoadHookTest, SuffixedDllsAreRedirected) {
+ // Check that a DLL name of the form "foo-delay.dll" gets redirected to
+ // the "foo.dll".
+ SetupInfo("kernel32-delay.dll");
+ HMODULE kernel32 = reinterpret_cast<HMODULE>(
+ ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
+
+ // Make sure the library is released on exit.
+ base::ScopedNativeLibrary lib_holder(kernel32);
+
+ ASSERT_TRUE(kernel32 == ::GetModuleHandle(L"kernel32.dll"));
+
+}
+
+TEST_F(DelayLoadHookTest, IgnoresUnhandledNotifications) {
+ SetupInfo("kernel32-delay.dll");
+
+ // The hook should ignore all notifications but the preload notifications
+ // and the failure notifications, wihch are tested in the other
+ EXPECT_TRUE(ChromeDelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
+ EXPECT_TRUE(ChromeDelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
+ EXPECT_TRUE(ChromeDelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
+}
+
+#if GTEST_HAS_DEATH_TEST
+
+TEST_F(DelayLoadHookTest, DiesOnFailedLoadLib) {
+ EXPECT_DEATH(ChromeDelayLoadHook(dliFailLoadLib, &info_), "");
+}
+
+TEST_F(DelayLoadHookTest, DiesOnFailedGetProc) {
+ EXPECT_DEATH(ChromeDelayLoadHook(dliFailGetProc, &info_), "");
+}
+
+#endif // GTEST_HAS_DEATH_TEST
+
+} // namespace win
+} // namespace base
« base/win/delay_load_hook.cc ('K') | « base/win/delay_load_hook.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698