Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Unified Diff: chrome/browser/safe_browsing/environment_data_collection_unittest.cc

Issue 323953002: Support for recording registered LSPs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grt
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/environment_data_collection_unittest.cc
diff --git a/chrome/browser/safe_browsing/environment_data_collection_unittest.cc b/chrome/browser/safe_browsing/environment_data_collection_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3101bd74cb67db899ad7024bff1b7890e712f581
--- /dev/null
+++ b/chrome/browser/safe_browsing/environment_data_collection_unittest.cc
@@ -0,0 +1,106 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/environment_data_collection_win.h"
+
+#include "base/files/file_path.h"
+#include "base/scoped_native_library.h"
+#include "chrome/common/safe_browsing/csd.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+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.
+
+namespace {
+
+// Helper function that returns true if a dll with filename |dll_name| is
+// found in |process_report|.
+bool ProcessReportContainsDll(
+ const ClientIncidentReport_EnvironmentData_Process& process_report,
+ const base::FilePath& dll_name) {
+ for (int i = 0; i < process_report.dlls_size(); ++i) {
+ base::FilePath current_dll =
+ base::FilePath::FromUTF8Unsafe(process_report.dlls(i).path());
+
+ if (current_dll.BaseName() == dll_name)
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
+} // namespace safe_browsing
+
+TEST(SafeBrowsingEnvironmentDataCollectionTest, CollectDlls) {
+ // This test will check if the CollectDlls method works by loading
+ // a dll and then checking if we can find it within the process report.
+ // Pick msvidc32.dll as it is present from WinXP to Win8 and yet rarely used.
+ base::FilePath msvdc32_dll(L"msvidc32.dll");
+
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
+ safe_browsing::CollectDlls(&process_report);
+
+ ASSERT_FALSE(
+ safe_browsing::ProcessReportContainsDll(process_report, msvdc32_dll));
+
+ // Redo the same verification after loading a new dll.
+ base::ScopedNativeLibrary library(msvdc32_dll);
+
+ process_report.clear_dlls();
+ safe_browsing::CollectDlls(&process_report);
+
+ ASSERT_TRUE(
+ safe_browsing::ProcessReportContainsDll(process_report, msvdc32_dll));
+}
+
+TEST(SafeBrowsingEnvironmentDataCollectionTest, VerifyLSP) {
+ // Populate our incident report with loaded modules.
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
+ safe_browsing::CollectDlls(&process_report);
+
+ // Look through dll entries and check that none contains the LSP feature.
+ bool lsp_feature_found = false;
+ for (int i = 0; i < process_report.dlls_size(); ++i) {
+ if (process_report.dlls(i).path() == path) {
+ // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
+ // through the features of each dll.
+ for (int j = 0; j < process_report.dlls(i).features_size(); ++j) {
+ if (process_report.dlls(i).features(j) ==
+ safe_browsing::
+ ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP)
+ lsp_feature_found = true;
+ }
+ }
+ }
+
+ ASSERT_FALSE(lsp_feature_found);
+
+ // Manually add an entry to the process report that will get marked as a LSP.
+ std::string path = "C:\\Windows\\system32\\mswsock.dll";
+ int base_address = 0x77770000;
+ int length = 0x180000;
+ safe_browsing::AddDll(path, base_address, length, &process_report);
+
+ // Look for dlls that are registered as a LSP.
+ safe_browsing::VerifyLSP(&process_report);
+
+ // Look through dll entries and check if the one we added contains the LSP
+ // feature.
+ bool lsp_feature_found = false;
+ for (int i = 0; i < process_report.dlls_size(); ++i) {
+ if (process_report.dlls(i).path() == path) {
+ // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
+ // through the features of each dll.
+ for (int j = 0; j < process_report.dlls(i).features_size(); ++j) {
+ if (process_report.dlls(i).features(j) ==
+ safe_browsing::
+ ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP)
+ lsp_feature_found = true;
+ }
+ }
+ }
+
+ ASSERT_TRUE(lsp_feature_found);
+}

Powered by Google App Engine
This is Rietveld 408576698