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

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: 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 unified diff | Download patch | Annotate | Revision Log
« base/win/delay_load_hook.cc ('K') | « base/win/delay_load_hook.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ChromeDelayLoadHook at link
52 // time results in overriding the delay loader's hook instances in the CRT
53 // appropriately.
54 EXPECT_TRUE(__pfnDliNotifyHook2 == ChromeDelayLoadHook);
55 EXPECT_TRUE(__pfnDliFailureHook2 == ChromeDelayLoadHook);
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 ChromeDelayLoadHook(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 ChromeDelayLoadHook(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 // and the failure notifications, wihch are tested in the other
89 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
90 EXPECT_TRUE(ChromeDelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
91 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
92 }
93
94 #if GTEST_HAS_DEATH_TEST
95
96 TEST_F(DelayLoadHookTest, DiesOnFailedLoadLib) {
97 EXPECT_DEATH(ChromeDelayLoadHook(dliFailLoadLib, &info_), "");
98 }
99
100 TEST_F(DelayLoadHookTest, DiesOnFailedGetProc) {
101 EXPECT_DEATH(ChromeDelayLoadHook(dliFailGetProc, &info_), "");
102 }
103
104 #endif // GTEST_HAS_DEATH_TEST
105
106 } // namespace win
107 } // namespace base
OLDNEW
« 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