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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/environment_data_collection_win_unittest.cc

Issue 1513043002: clang/win: Let remaining chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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 unified diff | Download patch
OLDNEW
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/incident_reporting/environment_data_colle ction_win.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle ction_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 GetProcAddress(module_handle, kTestExportName)); 186 GetProcAddress(module_handle, kTestExportName));
187 ASSERT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr); 187 ASSERT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr);
188 188
189 uint8_t new_val = (*export_addr) + 1; 189 uint8_t new_val = (*export_addr) + 1;
190 SIZE_T bytes_written = 0; 190 SIZE_T bytes_written = 0;
191 WriteProcessMemory(GetCurrentProcess(), 191 WriteProcessMemory(GetCurrentProcess(),
192 export_addr, 192 export_addr,
193 reinterpret_cast<void*>(&new_val), 193 reinterpret_cast<void*>(&new_val),
194 1, 194 1,
195 &bytes_written); 195 &bytes_written);
196 ASSERT_EQ(1, bytes_written); 196 ASSERT_EQ(1u, bytes_written);
197 197
198 ClientIncidentReport_EnvironmentData_Process process_report; 198 ClientIncidentReport_EnvironmentData_Process process_report;
199 CollectModuleVerificationData(kTestDllNames, kTestDllNamesCount, 199 CollectModuleVerificationData(kTestDllNames, kTestDllNamesCount,
200 &process_report); 200 &process_report);
201 201
202 // CollectModuleVerificationData should return the single modified module and 202 // CollectModuleVerificationData should return the single modified module and
203 // its modified export. The other module, being unmodified, is omitted from 203 // its modified export. The other module, being unmodified, is omitted from
204 // the returned list of modules. 204 // the returned list of modules.
205 // AddressSanitizer build is special though, as it patches the code at 205 // AddressSanitizer build is special though, as it patches the code at
206 // startup, which makes every single module modified and introduces extra 206 // startup, which makes every single module modified and introduces extra
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const wchar_t kDWORDValueName[] = L"DWORDValue"; 251 const wchar_t kDWORDValueName[] = L"DWORDValue";
252 const wchar_t kStringData[] = L"string data"; 252 const wchar_t kStringData[] = L"string data";
253 const DWORD kDWORDData = 0xdeadbeef; 253 const DWORD kDWORDData = 0xdeadbeef;
254 254
255 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kStringValueName, kStringData)); 255 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kStringValueName, kStringData));
256 256
257 registry_data_pb.Clear(); 257 registry_data_pb.Clear();
258 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb); 258 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb);
259 259
260 // Expect 1 registry key, 1 value. 260 // Expect 1 registry key, 1 value.
261 EXPECT_EQ(1U, registry_data_pb.size()); 261 EXPECT_EQ(1, registry_data_pb.size());
262 EXPECT_EQ("HKEY_CURRENT_USER\\Software\\TestKey", 262 EXPECT_EQ("HKEY_CURRENT_USER\\Software\\TestKey",
263 registry_data_pb.Get(0).name()); 263 registry_data_pb.Get(0).name());
264 EXPECT_EQ(1U, registry_data_pb.Get(0).value_size()); 264 EXPECT_EQ(1, registry_data_pb.Get(0).value_size());
265 EXPECT_EQ(base::WideToUTF8(kStringValueName), 265 EXPECT_EQ(base::WideToUTF8(kStringValueName),
266 registry_data_pb.Get(0).value(0).name()); 266 registry_data_pb.Get(0).value(0).name());
267 EXPECT_EQ(REG_SZ, registry_data_pb.Get(0).value(0).type()); 267 EXPECT_EQ(static_cast<uint32_t>(REG_SZ),
268 registry_data_pb.Get(0).value(0).type());
268 const char* value_data = registry_data_pb.Get(0).value(0).data().c_str(); 269 const char* value_data = registry_data_pb.Get(0).value(0).data().c_str();
269 EXPECT_EQ(kStringData, 270 EXPECT_EQ(kStringData,
270 std::wstring(reinterpret_cast<const wchar_t*>(&value_data[0]))); 271 std::wstring(reinterpret_cast<const wchar_t*>(&value_data[0])));
271 272
272 // Add another value. 273 // Add another value.
273 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kDWORDValueName, kDWORDData)); 274 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kDWORDValueName, kDWORDData));
274 275
275 registry_data_pb.Clear(); 276 registry_data_pb.Clear();
276 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb); 277 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb);
277 278
278 // Expect 1 registry key, 2 values. 279 // Expect 1 registry key, 2 values.
279 EXPECT_EQ(1U, registry_data_pb.size()); 280 EXPECT_EQ(1, registry_data_pb.size());
280 EXPECT_EQ(2U, registry_data_pb.Get(0).value_size()); 281 EXPECT_EQ(2, registry_data_pb.Get(0).value_size());
281 282
282 // Add a subkey. 283 // Add a subkey.
283 const wchar_t kTestValueName[] = L"TestValue"; 284 const wchar_t kTestValueName[] = L"TestValue";
284 const wchar_t kTestData[] = L"test data"; 285 const wchar_t kTestData[] = L"test data";
285 286
286 ASSERT_EQ(ERROR_SUCCESS, key.CreateKey(kSubKey, KEY_READ)); 287 ASSERT_EQ(ERROR_SUCCESS, key.CreateKey(kSubKey, KEY_READ));
287 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ)); 288 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ));
288 ASSERT_EQ(ERROR_SUCCESS, key.OpenKey(kSubKey, KEY_READ | KEY_SET_VALUE)); 289 ASSERT_EQ(ERROR_SUCCESS, key.OpenKey(kSubKey, KEY_READ | KEY_SET_VALUE));
289 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kTestValueName, kTestData)); 290 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kTestValueName, kTestData));
290 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ)); 291 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ));
291 292
292 registry_data_pb.Clear(); 293 registry_data_pb.Clear();
293 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb); 294 CollectRegistryData(kRegKeysToCollect, 1, &registry_data_pb);
294 295
295 // Expect 1 subkey, 1 value. 296 // Expect 1 subkey, 1 value.
296 EXPECT_EQ(1U, registry_data_pb.Get(0).key_size()); 297 EXPECT_EQ(1, registry_data_pb.Get(0).key_size());
297 const ClientIncidentReport_EnvironmentData_OS_RegistryKey& subkey_pb = 298 const ClientIncidentReport_EnvironmentData_OS_RegistryKey& subkey_pb =
298 registry_data_pb.Get(0).key(0); 299 registry_data_pb.Get(0).key(0);
299 EXPECT_EQ(base::WideToUTF8(kSubKey), subkey_pb.name()); 300 EXPECT_EQ(base::WideToUTF8(kSubKey), subkey_pb.name());
300 EXPECT_EQ(1U, subkey_pb.value_size()); 301 EXPECT_EQ(1, subkey_pb.value_size());
301 EXPECT_EQ(base::WideToUTF8(kTestValueName), subkey_pb.value(0).name()); 302 EXPECT_EQ(base::WideToUTF8(kTestValueName), subkey_pb.value(0).name());
302 value_data = subkey_pb.value(0).data().c_str(); 303 value_data = subkey_pb.value(0).data().c_str();
303 EXPECT_EQ(kTestData, 304 EXPECT_EQ(kTestData,
304 std::wstring(reinterpret_cast<const wchar_t*>(&value_data[0]))); 305 std::wstring(reinterpret_cast<const wchar_t*>(&value_data[0])));
305 EXPECT_EQ(REG_SZ, subkey_pb.value(0).type()); 306 EXPECT_EQ(static_cast<uint32_t>(REG_SZ), subkey_pb.value(0).type());
306 } 307 }
307 308
308 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, 309 TEST(SafeBrowsingEnvironmentDataCollectionWinTest,
309 CollectDomainEnrollmentData) { 310 CollectDomainEnrollmentData) {
310 // The test may or may not be running on a domain-enrolled machine, so all we 311 // The test may or may not be running on a domain-enrolled machine, so all we
311 // can check is that some value is filled in. 312 // can check is that some value is filled in.
312 ClientIncidentReport_EnvironmentData_OS os_data; 313 ClientIncidentReport_EnvironmentData_OS os_data;
313 CollectDomainEnrollmentData(&os_data); 314 CollectDomainEnrollmentData(&os_data);
314 EXPECT_TRUE(os_data.has_is_enrolled_to_domain()); 315 EXPECT_TRUE(os_data.has_is_enrolled_to_domain());
315 } 316 }
316 317
317 } // namespace safe_browsing 318 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698