Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
it looks like this file is testing the functions i
pmonette_google.com
2014/06/10 19:34:38
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/environment_data_collection_win.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/scoped_native_library.h" | |
| 9 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace safe_browsing { | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
nit: it looks like if you remove the safe_browsing
pmonette_google.com
2014/06/10 19:34:38
Done.
| |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Helper function that returns true if a dll with filename |dll_name| is | |
| 17 // found in |process_report|. | |
| 18 bool ProcessReportContainsDll( | |
| 19 const ClientIncidentReport_EnvironmentData_Process& process_report, | |
| 20 const base::FilePath& dll_name) { | |
| 21 for (int i = 0; i < process_report.dlls_size(); ++i) { | |
| 22 base::FilePath current_dll = | |
| 23 base::FilePath::FromUTF8Unsafe(process_report.dlls(i).path()); | |
| 24 | |
| 25 if (current_dll.BaseName() == dll_name) | |
| 26 return true; | |
| 27 } | |
| 28 | |
| 29 return false; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 } // namespace safe_browsing | |
| 35 | |
| 36 TEST(SafeBrowsingEnvironmentDataCollectionTest, CollectDlls) { | |
| 37 // This test will check if the CollectDlls method works by loading | |
| 38 // a dll and then checking if we can find it within the process report. | |
| 39 // Pick msvidc32.dll as it is present from WinXP to Win8 and yet rarely used. | |
| 40 base::FilePath msvdc32_dll(L"msvidc32.dll"); | |
| 41 | |
| 42 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; | |
| 43 safe_browsing::CollectDlls(&process_report); | |
| 44 | |
| 45 ASSERT_FALSE( | |
| 46 safe_browsing::ProcessReportContainsDll(process_report, msvdc32_dll)); | |
| 47 | |
| 48 // Redo the same verification after loading a new dll. | |
| 49 base::ScopedNativeLibrary library(msvdc32_dll); | |
| 50 | |
| 51 process_report.clear_dlls(); | |
| 52 safe_browsing::CollectDlls(&process_report); | |
| 53 | |
| 54 ASSERT_TRUE( | |
| 55 safe_browsing::ProcessReportContainsDll(process_report, msvdc32_dll)); | |
| 56 } | |
| 57 | |
| 58 TEST(SafeBrowsingEnvironmentDataCollectionTest, VerifyLSP) { | |
| 59 // Populate our incident report with loaded modules. | |
| 60 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; | |
| 61 safe_browsing::CollectDlls(&process_report); | |
| 62 | |
| 63 // Look through dll entries and check that none contains the LSP feature. | |
| 64 bool lsp_feature_found = false; | |
| 65 for (int i = 0; i < process_report.dlls_size(); ++i) { | |
| 66 if (process_report.dlls(i).path() == path) { | |
| 67 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP | |
| 68 // through the features of each dll. | |
| 69 for (int j = 0; j < process_report.dlls(i).features_size(); ++j) { | |
| 70 if (process_report.dlls(i).features(j) == | |
| 71 safe_browsing:: | |
| 72 ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP) | |
| 73 lsp_feature_found = true; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 ASSERT_FALSE(lsp_feature_found); | |
| 79 | |
| 80 // Manually add an entry to the process report that will get marked as a LSP. | |
| 81 std::string path = "C:\\Windows\\system32\\mswsock.dll"; | |
| 82 int base_address = 0x77770000; | |
| 83 int length = 0x180000; | |
| 84 safe_browsing::AddDll(path, base_address, length, &process_report); | |
| 85 | |
| 86 // Look for dlls that are registered as a LSP. | |
| 87 safe_browsing::VerifyLSP(&process_report); | |
| 88 | |
| 89 // Look through dll entries and check if the one we added contains the LSP | |
| 90 // feature. | |
| 91 bool lsp_feature_found = false; | |
| 92 for (int i = 0; i < process_report.dlls_size(); ++i) { | |
| 93 if (process_report.dlls(i).path() == path) { | |
| 94 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP | |
| 95 // through the features of each dll. | |
| 96 for (int j = 0; j < process_report.dlls(i).features_size(); ++j) { | |
| 97 if (process_report.dlls(i).features(j) == | |
| 98 safe_browsing:: | |
| 99 ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP) | |
| 100 lsp_feature_found = true; | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 ASSERT_TRUE(lsp_feature_found); | |
| 106 } | |
| OLD | NEW |