Temporarily disable durable storage browser test
[chromium-blink-merge.git] / chrome / app / delay_load_hook_unittest_win.cc
blob8ef56b6d1d60423511a16b52aa7b899d6a4592d6
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.
5 #include <windows.h>
6 #include <DelayIMP.h>
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/scoped_native_library.h"
11 #include "chrome/app/delay_load_hook_win.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace {
16 class ChromeDelayLoadHookTest : public testing::Test {
17 public:
18 ChromeDelayLoadHookTest() : proc_ptr_(NULL) {
21 void SetUp() override {
22 SetupInfo("kernel32.dll");
25 void SetupInfo(const char* dll_name) {
26 info_.cb = sizeof(info_);
27 info_.pidd = NULL;
28 info_.ppfn = &proc_ptr_;
29 info_.szDll = dll_name;
30 info_.dlp.fImportByName = TRUE;
31 info_.dlp.szProcName = "CreateFileA";
32 info_.hmodCur = NULL;
33 info_.pfnCur = NULL;
34 info_.dwLastError = 0;
37 FARPROC proc_ptr_;
38 DelayLoadInfo info_;
41 } // namespace
43 TEST_F(ChromeDelayLoadHookTest, HooksAreSetAtLinkTime) {
44 // This test verifies that referencing the ChromeDelayLoadHook at link
45 // time results in overriding the delay loader's hook instances in the CRT
46 // ropriately.
47 EXPECT_TRUE(__pfnDliNotifyHook2 == ChromeDelayLoadHook);
48 EXPECT_TRUE(__pfnDliFailureHook2 == ChromeDelayLoadHook);
51 TEST_F(ChromeDelayLoadHookTest, NonSuffixedDllsAreNotHandled) {
52 // The hook should ignore non-suffixed DLLs.
53 SetupInfo("kernel32.dll");
55 HMODULE none = reinterpret_cast<HMODULE>(
56 ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
57 // Make sure the library is released on exit.
58 base::ScopedNativeLibrary lib_holder(none);
60 ASSERT_TRUE(none == NULL);
63 TEST_F(ChromeDelayLoadHookTest, SuffixedDllsAreRedirected) {
64 // Check that a DLL name of the form "foo-delay.dll" gets redirected to
65 // the "foo.dll".
66 SetupInfo("kernel32-delay.dll");
67 HMODULE kernel32 = reinterpret_cast<HMODULE>(
68 ChromeDelayLoadHook(dliNotePreLoadLibrary, &info_));
70 // Make sure the library is released on exit.
71 base::ScopedNativeLibrary lib_holder(kernel32);
73 ASSERT_TRUE(kernel32 == ::GetModuleHandle(L"kernel32.dll"));
76 TEST_F(ChromeDelayLoadHookTest, IgnoresUnhandledNotifications) {
77 SetupInfo("kernel32-delay.dll");
79 // The hook should ignore all notifications but the preload notifications.
80 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteStartProcessing, &info_) == NULL);
81 EXPECT_TRUE(ChromeDelayLoadHook(dliNotePreGetProcAddress, &info_) == NULL);
82 EXPECT_TRUE(ChromeDelayLoadHook(dliNoteEndProcessing, &info_) == NULL);
83 EXPECT_TRUE(ChromeDelayLoadHook(dliFailLoadLib, &info_) == NULL);
84 EXPECT_TRUE(ChromeDelayLoadHook(dliFailGetProc, &info_) == NULL);