OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <windows.h> | 6 #include <windows.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // the real run (above, in ChromeElfLoadSanityTest) can run it with an argument | 137 // the real run (above, in ChromeElfLoadSanityTest) can run it with an argument |
138 // added to the command line. | 138 // added to the command line. |
139 TEST_F(ELFImportsTest, DISABLED_ChromeElfLoadSanityTestImpl) { | 139 TEST_F(ELFImportsTest, DISABLED_ChromeElfLoadSanityTestImpl) { |
140 base::FilePath dll; | 140 base::FilePath dll; |
141 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll)); | 141 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll)); |
142 dll = dll.Append(L"chrome_elf.dll"); | 142 dll = dll.Append(L"chrome_elf.dll"); |
143 | 143 |
144 // We don't expect user32 to be loaded in chrome_elf_unittests. If this test | 144 // We don't expect user32 to be loaded in chrome_elf_unittests. If this test |
145 // case fails, then it means that a dependency on user32 has crept into the | 145 // case fails, then it means that a dependency on user32 has crept into the |
146 // chrome_elf_unittests executable, which needs to be removed. | 146 // chrome_elf_unittests executable, which needs to be removed. |
147 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); | 147 // NOTE: it may be a secondary dependency of another system DLL. If so, |
| 148 // try adding a "/DELAYLOAD:<blah>.dll" to the build.gn file. |
| 149 ASSERT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); |
148 | 150 |
149 HMODULE chrome_elf_module_handle = ::LoadLibrary(dll.value().c_str()); | 151 HMODULE chrome_elf_module_handle = ::LoadLibrary(dll.value().c_str()); |
150 EXPECT_TRUE(chrome_elf_module_handle != nullptr); | 152 EXPECT_TRUE(chrome_elf_module_handle != nullptr); |
151 // Loading chrome_elf.dll should not load user32.dll | 153 // Loading chrome_elf.dll should not load user32.dll |
152 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); | 154 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); |
153 EXPECT_TRUE(!!::FreeLibrary(chrome_elf_module_handle)); | 155 EXPECT_TRUE(!!::FreeLibrary(chrome_elf_module_handle)); |
154 } | 156 } |
155 | 157 |
156 #endif // NDEBUG && !COMPONENT_BUILD | 158 #endif // NDEBUG && !COMPONENT_BUILD |
157 | 159 |
158 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { | 160 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { |
159 std::vector<std::string> exe_imports; | 161 std::vector<std::string> exe_imports; |
160 | 162 |
161 base::FilePath exe; | 163 base::FilePath exe; |
162 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); | 164 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); |
163 exe = exe.Append(L"chrome.exe"); | 165 exe = exe.Append(L"chrome.exe"); |
164 GetImports(exe, &exe_imports); | 166 GetImports(exe, &exe_imports); |
165 | 167 |
166 // Check that chrome.exe has imports. | 168 // Check that chrome.exe has imports. |
167 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " | 169 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " |
168 "target was built, instead of chrome_elf_unittests.exe"; | 170 "target was built, instead of chrome_elf_unittests.exe"; |
169 | 171 |
170 // Chrome.exe's first import must be ELF. | 172 // Chrome.exe's first import must be ELF. |
171 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << | 173 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << |
172 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " | 174 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " |
173 "target was built, instead of just chrome_elf_unittests.exe)"; | 175 "target was built, instead of just chrome_elf_unittests.exe)"; |
174 } | 176 } |
175 | 177 |
176 } // namespace | 178 } // namespace |
OLD | NEW |