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

Side by Side Diff: chrome/app/delay_load_hook_unittest_win.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: Reduce scope to chrome.dll/x86. Address review comments. 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 "chrome/app/delay_load_hook_win.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace {
19
20 class ChromeDelayLoadHookTest : public testing::Test {
21 public:
22 ChromeDelayLoadHookTest() : proc_ptr_(NULL) {
23 }
24
25 virtual void SetUp() OVERRIDE {
26 SetupInfo("kernel32.dll");
27 }
28
29 void SetupInfo(const char* dll_name) {
30 info_.cb = sizeof(info_);
31 info_.pidd = NULL;
32 info_.ppfn = &proc_ptr_;
33 info_.szDll = dll_name;
34 info_.dlp.fImportByName = TRUE;
35 info_.dlp.szProcName = "CreateFileA";
36 info_.hmodCur = NULL;
37 info_.pfnCur = NULL;
38 info_.dwLastError = 0;
39 }
40
41 FARPROC proc_ptr_;
42 DelayLoadInfo info_;
43 };
44
45 } // namespace
46
47 TEST_F(ChromeDelayLoadHookTest, HooksAreSetAtLinkTime) {
48 // This test verifies that referencing the ChromeDelayLoadHook at link
49 // time results in overriding the delay loader's hook instances in the CRT
50 // ropriately.
51 EXPECT_TRUE(__pfnDliNotifyHook2 == ChromeDelayLoadHook);
52 EXPECT_TRUE(__pfnDliFailureHook2 == ChromeDelayLoadHook);
53 }
54
55 TEST_F(ChromeDelayLoadHookTest, NonSuffixedDllsAreNotHandled) {
56 // The hook should ignore non-suffixed DLLs.
57 SetupInfo("kernel32.dll");
58
59 HMODULE none = reinterpret_cast<HMODULE>(
60 ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
61 // Make sure the library is released on exit.
62 base::ScopedNativeLibrary lib_holder(none);
63
64 ASSERT_TRUE(none == NULL);
65 }
66
67 TEST_F(ChromeDelayLoadHookTest, SuffixedDllsAreRedirected) {
68 // Check that a DLL name of the form "foo-delay.dll" gets redirected to
69 // the "foo.dll".
70 SetupInfo("kernel32-delay.dll");
71 HMODULE kernel32 = reinterpret_cast<HMODULE>(
72 ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
73
74 // Make sure the library is released on exit.
75 base::ScopedNativeLibrary lib_holder(kernel32);
76
77 ASSERT_TRUE(kernel32 == ::GetModuleHandle(L"kernel32.dll"));
78
79 }
80
81 TEST_F(ChromeDelayLoadHookTest, IgnoresUnhandledNotifications) {
82 SetupInfo("kernel32-delay.dll");
83
84 // The hook should ignore all notifications but the preload notifications.
85 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
86 EXPECT_TRUE(ChromeDelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
87 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
88 EXPECT_TRUE(ChromeDelayLoadHook(dliFailLoadLib, &info_) == NULL);
89 EXPECT_TRUE(ChromeDelayLoadHook(dliFailGetProc, &info_) == NULL);
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698