| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bool match = false; | 100 bool match = false; |
| 101 for (const char* kValidFilePattern : kValidFilePatterns) { | 101 for (const char* kValidFilePattern : kValidFilePatterns) { |
| 102 if (base::MatchPattern(import, kValidFilePattern)) { | 102 if (base::MatchPattern(import, kValidFilePattern)) { |
| 103 match = true; | 103 match = true; |
| 104 break; | 104 break; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << import; | 107 ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << import; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 TEST_F(ELFImportsTest, ChromeElfLoadSanityTest) { |
| 111 base::FilePath dll; |
| 112 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll)); |
| 113 dll = dll.Append(L"chrome_elf.dll"); |
| 114 |
| 115 // We don't expect user32 to be loaded in chrome_elf_unittests. If this test |
| 116 // case fails, then it means that a dependency on user32 has crept into the |
| 117 // chrome_elf_unittests executable, which needs to be removed. |
| 118 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); |
| 119 |
| 120 HMODULE chrome_elf_module_handle = ::LoadLibrary(dll.value().c_str()); |
| 121 EXPECT_TRUE(chrome_elf_module_handle != nullptr); |
| 122 // Loading chrome_elf.dll should not load user32.dll |
| 123 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); |
| 124 EXPECT_TRUE(!!::FreeLibrary(chrome_elf_module_handle)); |
| 125 } |
| 110 #endif // NDEBUG | 126 #endif // NDEBUG |
| 111 | 127 |
| 112 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { | 128 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { |
| 113 std::vector<std::string> exe_imports; | 129 std::vector<std::string> exe_imports; |
| 114 | 130 |
| 115 base::FilePath exe; | 131 base::FilePath exe; |
| 116 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); | 132 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); |
| 117 exe = exe.Append(L"chrome.exe"); | 133 exe = exe.Append(L"chrome.exe"); |
| 118 GetImports(exe, &exe_imports); | 134 GetImports(exe, &exe_imports); |
| 119 | 135 |
| 120 // Check that chrome.exe has imports. | 136 // Check that chrome.exe has imports. |
| 121 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " | 137 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " |
| 122 "target was built, instead of chrome_elf_unittests.exe"; | 138 "target was built, instead of chrome_elf_unittests.exe"; |
| 123 | 139 |
| 124 // Chrome.exe's first import must be ELF. | 140 // Chrome.exe's first import must be ELF. |
| 125 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << | 141 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << |
| 126 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " | 142 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " |
| 127 "target was built, instead of just chrome_elf_unittests.exe)"; | 143 "target was built, instead of just chrome_elf_unittests.exe)"; |
| 128 } | 144 } |
| 129 | 145 |
| 130 } // namespace | 146 } // namespace |
| OLD | NEW |