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. | |
116 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); | |
robertshield
2016/06/20 16:59:54
Can you expand the comment here to explicitly stat
ananta
2016/06/20 19:08:03
Done.
| |
117 | |
118 HMODULE chrome_elf_module_handle = ::LoadLibrary(dll.value().c_str()); | |
119 EXPECT_TRUE(chrome_elf_module_handle != nullptr); | |
120 // Loading chrome_elf.dll should not load user32.dll | |
121 EXPECT_EQ(nullptr, ::GetModuleHandle(L"user32.dll")); | |
122 EXPECT_TRUE(!!::FreeLibrary(chrome_elf_module_handle)); | |
123 } | |
110 #endif // NDEBUG | 124 #endif // NDEBUG |
111 | 125 |
112 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { | 126 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { |
113 std::vector<std::string> exe_imports; | 127 std::vector<std::string> exe_imports; |
114 | 128 |
115 base::FilePath exe; | 129 base::FilePath exe; |
116 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); | 130 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); |
117 exe = exe.Append(L"chrome.exe"); | 131 exe = exe.Append(L"chrome.exe"); |
118 GetImports(exe, &exe_imports); | 132 GetImports(exe, &exe_imports); |
119 | 133 |
120 // Check that chrome.exe has imports. | 134 // Check that chrome.exe has imports. |
121 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " | 135 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " |
122 "target was built, instead of chrome_elf_unittests.exe"; | 136 "target was built, instead of chrome_elf_unittests.exe"; |
123 | 137 |
124 // Chrome.exe's first import must be ELF. | 138 // Chrome.exe's first import must be ELF. |
125 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << | 139 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << |
126 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " | 140 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " |
127 "target was built, instead of just chrome_elf_unittests.exe)"; | 141 "target was built, instead of just chrome_elf_unittests.exe)"; |
128 } | 142 } |
129 | 143 |
130 } // namespace | 144 } // namespace |
OLD | NEW |