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

Side by Side 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: Build config sketch, mostly works for x86 and x64. Move the hook back to base." Created 7 years, 9 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
6 // The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h, and in
7 // delayimp.h previous to VS2012.
8 #undef FACILITY_VISUALCPP
9 #endif
10 #include <DelayIMP.h>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/scoped_native_library.h"
15 #include "base/win/delay_load_hook.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace base {
19 namespace win {
20
21 namespace {
22
23 class DelayLoadHookTest : public testing::Test {
24 public:
25 DelayLoadHookTest() : proc_ptr_(NULL) {
26 }
27
28 virtual void SetUp() OVERRIDE {
29 SetupInfo("kernel32.dll");
30 }
31
32 void SetupInfo(const char* dll_name) {
33 info_.cb = sizeof(info_);
34 info_.pidd = NULL;
35 info_.ppfn = &proc_ptr_;
36 info_.szDll = dll_name;
37 info_.dlp.fImportByName = TRUE;
38 info_.dlp.szProcName = "CreateFileA";
39 info_.hmodCur = NULL;
40 info_.pfnCur = NULL;
41 info_.dwLastError = 0;
42 }
43
44 FARPROC proc_ptr_;
45 DelayLoadInfo info_;
46 };
47
48 } // namespace
49
50 TEST_F(DelayLoadHookTest, HooksAreSetAtLinkTime) {
51 // This test verifies that referencing the DelayLoadHook at link
52 // time results in overriding the delay loader's hook instances in the CRT
53 // ropriately.
54 EXPECT_TRUE(__pfnDliNotifyHook2 == DelayLoadHook);
55 EXPECT_TRUE(__pfnDliFailureHook2 == DelayLoadHook);
56 }
57
58 TEST_F(DelayLoadHookTest, NonSuffixedDllsAreNotHandled) {
59 // The hook should ignore non-suffixed DLLs.
60 SetupInfo("kernel32.dll");
61
62 HMODULE none = reinterpret_cast<HMODULE>(
63 DelayLoadHook(dliNotePreLoadLibrary, &info_));
64 // Make sure the library is released on exit.
65 base::ScopedNativeLibrary lib_holder(none);
66
67 ASSERT_TRUE(none == NULL);
68 }
69
70 TEST_F(DelayLoadHookTest, SuffixedDllsAreRedirected) {
71 // Check that a DLL name of the form "foo-delay.dll" gets redirected to
72 // the "foo.dll".
73 SetupInfo("kernel32-delay.dll");
74 HMODULE kernel32 = reinterpret_cast<HMODULE>(
75 DelayLoadHook(dliNotePreLoadLibrary, &info_));
76
77 // Make sure the library is released on exit.
78 base::ScopedNativeLibrary lib_holder(kernel32);
79
80 ASSERT_TRUE(kernel32 == ::GetModuleHandle(L"kernel32.dll"));
81
82 }
83
84 TEST_F(DelayLoadHookTest, IgnoresUnhandledNotifications) {
85 SetupInfo("kernel32-delay.dll");
86
87 // The hook should ignore all notifications but the preload notifications.
88 EXPECT_TRUE(DelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
89 EXPECT_TRUE(DelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
90 EXPECT_TRUE(DelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
91 EXPECT_TRUE(DelayLoadHook(dliFailLoadLib, &info_) == NULL);
92 EXPECT_TRUE(DelayLoadHook(dliFailGetProc, &info_) == NULL);
93 }
94
95 } // namespace win
96 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698