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 "chrome/browser/safe_browsing/environment_data_collection_win.h" | 5 #include "chrome/browser/safe_browsing/environment_data_collection_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/scoped_native_library.h" | 10 #include "base/scoped_native_library.h" |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "base/test/test_reg_util_win.h" | |
13 #include "base/win/registry.h" | |
11 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
15 #include "chrome_elf/chrome_elf_constants.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
13 | 17 |
14 namespace { | 18 namespace { |
15 | 19 |
20 const wchar_t test_dll[] = L"testname.dll"; | |
21 | |
16 // Helper function that returns true if a dll with filename |dll_name| is | 22 // Helper function that returns true if a dll with filename |dll_name| is |
17 // found in |process_report|. | 23 // found in |process_report|. |
18 bool ProcessReportContainsDll( | 24 bool ProcessReportContainsDll( |
19 const safe_browsing::ClientIncidentReport_EnvironmentData_Process& | 25 const safe_browsing::ClientIncidentReport_EnvironmentData_Process& |
20 process_report, | 26 process_report, |
21 const base::FilePath& dll_name) { | 27 const base::FilePath& dll_name) { |
22 for (int i = 0; i < process_report.dll_size(); ++i) { | 28 for (int i = 0; i < process_report.dll_size(); ++i) { |
23 base::FilePath current_dll = | 29 base::FilePath current_dll = |
24 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path()); | 30 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path()); |
25 | 31 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 if (process_report.dll(i).feature(j) == | 110 if (process_report.dll(i).feature(j) == |
105 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: | 111 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: |
106 LSP) | 112 LSP) |
107 lsp_feature_found = true; | 113 lsp_feature_found = true; |
108 } | 114 } |
109 } | 115 } |
110 } | 116 } |
111 | 117 |
112 ASSERT_TRUE(lsp_feature_found); | 118 ASSERT_TRUE(lsp_feature_found); |
113 } | 119 } |
120 | |
121 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDllBlacklistData) { | |
122 // Ensure that CollectDllBlacklistData correctly adds the set of dll names | |
123 // currently stored in the registry to the report. | |
124 registry_util::RegistryOverrideManager override_manager; | |
125 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"safe_browsing_test"); | |
126 | |
127 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, | |
128 blacklist::kRegistryFinchListPath, | |
129 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
130 | |
131 // Check that with an empty registry the blacklisted dlls field is left empty. | |
132 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; | |
133 safe_browsing::CollectDllBlacklistData(&process_report); | |
134 EXPECT_EQ(0, process_report.blacklisted_dll_size()); | |
135 | |
136 // Check that after adding exactly one dll to the registry it appears in the | |
137 // process report. | |
138 blacklist_registry_key.WriteValue(test_dll, test_dll); | |
139 safe_browsing::CollectDllBlacklistData(&process_report); | |
140 ASSERT_EQ(1, process_report.blacklisted_dll_size()); | |
141 | |
142 std::wstring process_report_dll = | |
grt (UTC plus 2)
2014/06/19 20:06:59
use base::string16 rather than std::wstring to avo
krstnmnlsn
2014/06/19 22:13:15
Done.
| |
143 base::UTF8ToWide(process_report.blacklisted_dll(0)); | |
144 EXPECT_EQ(std::wstring(test_dll), process_report_dll); | |
145 } | |
grt (UTC plus 2)
2014/06/19 20:06:59
please add a test for the case where the registry
krstnmnlsn
2014/06/19 22:13:15
Done.
| |
OLD | NEW |