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

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

Issue 1870003002: Convert //chrome/browser/safe_browsing from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments Created 4 years, 8 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 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/incident_reporting_ser vice.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser vice.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
8 #include <map> 9 #include <map>
9 #include <string> 10 #include <string>
10 #include <utility> 11 #include <utility>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
19 #include "base/test/mock_entropy_provider.h" 21 #include "base/test/mock_entropy_provider.h"
20 #include "base/test/test_simple_task_runner.h" 22 #include "base/test/test_simple_task_runner.h"
21 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
22 #include "base/threading/thread_local.h" 24 #include "base/threading/thread_local.h"
23 #include "build/build_config.h" 25 #include "build/build_config.h"
24 #include "chrome/browser/prefs/browser_prefs.h" 26 #include "chrome/browser/prefs/browser_prefs.h"
25 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" 27 #include "chrome/browser/safe_browsing/incident_reporting/incident.h"
(...skipping 23 matching lines...) Expand all
49 // collector, extension collector and report uploader via callbacks. 51 // collector, extension collector and report uploader via callbacks.
50 class TestIncidentReportingService 52 class TestIncidentReportingService
51 : public safe_browsing::IncidentReportingService { 53 : public safe_browsing::IncidentReportingService {
52 public: 54 public:
53 typedef base::Callback<void(Profile*)> PreProfileAddCallback; 55 typedef base::Callback<void(Profile*)> PreProfileAddCallback;
54 56
55 typedef base::Callback< 57 typedef base::Callback<
56 void(safe_browsing::ClientIncidentReport_EnvironmentData*)> 58 void(safe_browsing::ClientIncidentReport_EnvironmentData*)>
57 CollectEnvironmentCallback; 59 CollectEnvironmentCallback;
58 60
59 typedef base::Callback<scoped_ptr<safe_browsing::LastDownloadFinder>( 61 typedef base::Callback<std::unique_ptr<safe_browsing::LastDownloadFinder>(
60 const safe_browsing::LastDownloadFinder::LastDownloadCallback& 62 const safe_browsing::LastDownloadFinder::LastDownloadCallback&
61 callback)> CreateDownloadFinderCallback; 63 callback)>
64 CreateDownloadFinderCallback;
62 65
63 typedef base::Callback<scoped_ptr<safe_browsing::IncidentReportUploader>( 66 typedef base::Callback<
64 const safe_browsing::IncidentReportUploader::OnResultCallback&, 67 std::unique_ptr<safe_browsing::IncidentReportUploader>(
65 const safe_browsing::ClientIncidentReport& report)> StartUploadCallback; 68 const safe_browsing::IncidentReportUploader::OnResultCallback&,
69 const safe_browsing::ClientIncidentReport& report)>
70 StartUploadCallback;
66 71
67 TestIncidentReportingService( 72 TestIncidentReportingService(
68 const scoped_refptr<base::TaskRunner>& task_runner, 73 const scoped_refptr<base::TaskRunner>& task_runner,
69 const PreProfileAddCallback& pre_profile_add_callback, 74 const PreProfileAddCallback& pre_profile_add_callback,
70 const CollectEnvironmentCallback& collect_environment_callback, 75 const CollectEnvironmentCallback& collect_environment_callback,
71 const CreateDownloadFinderCallback& create_download_finder_callback, 76 const CreateDownloadFinderCallback& create_download_finder_callback,
72 const StartUploadCallback& start_upload_callback) 77 const StartUploadCallback& start_upload_callback)
73 : IncidentReportingService(NULL, 78 : IncidentReportingService(NULL,
74 NULL, 79 NULL,
75 base::TimeDelta::FromMilliseconds(5), 80 base::TimeDelta::FromMilliseconds(5),
(...skipping 25 matching lines...) Expand all
101 // operation. 106 // operation.
102 void DoExtensionCollection( 107 void DoExtensionCollection(
103 safe_browsing::ClientIncidentReport_ExtensionData* data) override { 108 safe_browsing::ClientIncidentReport_ExtensionData* data) override {
104 ASSERT_NE(static_cast<safe_browsing::ClientIncidentReport_ExtensionData*>( 109 ASSERT_NE(static_cast<safe_browsing::ClientIncidentReport_ExtensionData*>(
105 nullptr), 110 nullptr),
106 data); 111 data);
107 data->mutable_last_installed_extension()->set_id(kFakeExtensionId); 112 data->mutable_last_installed_extension()->set_id(kFakeExtensionId);
108 extension_collected_ = true; 113 extension_collected_ = true;
109 } 114 }
110 115
111 scoped_ptr<safe_browsing::LastDownloadFinder> CreateDownloadFinder( 116 std::unique_ptr<safe_browsing::LastDownloadFinder> CreateDownloadFinder(
112 const safe_browsing::LastDownloadFinder::LastDownloadCallback& callback) 117 const safe_browsing::LastDownloadFinder::LastDownloadCallback& callback)
113 override { 118 override {
114 return create_download_finder_callback_.Run(callback); 119 return create_download_finder_callback_.Run(callback);
115 } 120 }
116 121
117 scoped_ptr<safe_browsing::IncidentReportUploader> StartReportUpload( 122 std::unique_ptr<safe_browsing::IncidentReportUploader> StartReportUpload(
118 const safe_browsing::IncidentReportUploader::OnResultCallback& callback, 123 const safe_browsing::IncidentReportUploader::OnResultCallback& callback,
119 const scoped_refptr<net::URLRequestContextGetter>& 124 const scoped_refptr<net::URLRequestContextGetter>&
120 request_context_getter, 125 request_context_getter,
121 const safe_browsing::ClientIncidentReport& report) override { 126 const safe_browsing::ClientIncidentReport& report) override {
122 return start_upload_callback_.Run(callback, report); 127 return start_upload_callback_.Run(callback, report);
123 } 128 }
124 129
125 private: 130 private:
126 static TestIncidentReportingService& current() { 131 static TestIncidentReportingService& current() {
127 return *test_instance_.Get().Get(); 132 return *test_instance_.Get().Get();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 on_create_download_finder_action_ = action; 240 on_create_download_finder_action_ = action;
236 } 241 }
237 242
238 // Creates and returns a profile (owned by the profile manager) with or 243 // Creates and returns a profile (owned by the profile manager) with or
239 // without safe browsing enabled. An incident will be created within 244 // without safe browsing enabled. An incident will be created within
240 // PreProfileAdd if requested. |incidents_sent|, if provided, will be set 245 // PreProfileAdd if requested. |incidents_sent|, if provided, will be set
241 // in the profile's preference. 246 // in the profile's preference.
242 TestingProfile* CreateProfile(const std::string& profile_name, 247 TestingProfile* CreateProfile(const std::string& profile_name,
243 SafeBrowsingDisposition safe_browsing_opt_in, 248 SafeBrowsingDisposition safe_browsing_opt_in,
244 OnProfileAdditionAction on_addition_action, 249 OnProfileAdditionAction on_addition_action,
245 scoped_ptr<base::Value> incidents_sent) { 250 std::unique_ptr<base::Value> incidents_sent) {
246 // Create prefs for the profile with safe browsing enabled or not. 251 // Create prefs for the profile with safe browsing enabled or not.
247 scoped_ptr<syncable_prefs::TestingPrefServiceSyncable> prefs( 252 std::unique_ptr<syncable_prefs::TestingPrefServiceSyncable> prefs(
248 new syncable_prefs::TestingPrefServiceSyncable); 253 new syncable_prefs::TestingPrefServiceSyncable);
249 chrome::RegisterUserProfilePrefs(prefs->registry()); 254 chrome::RegisterUserProfilePrefs(prefs->registry());
250 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, 255 prefs->SetBoolean(prefs::kSafeBrowsingEnabled,
251 safe_browsing_opt_in != SAFE_BROWSING_OPT_OUT); 256 safe_browsing_opt_in != SAFE_BROWSING_OPT_OUT);
252 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, 257 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled,
253 safe_browsing_opt_in == EXTENDED_REPORTING_OPT_IN); 258 safe_browsing_opt_in == EXTENDED_REPORTING_OPT_IN);
254 if (incidents_sent) 259 if (incidents_sent)
255 prefs->Set(prefs::kSafeBrowsingIncidentsSent, *incidents_sent); 260 prefs->Set(prefs::kSafeBrowsingIncidentsSent, *incidents_sent);
256 261
257 // Remember whether or not to create an incident. 262 // Remember whether or not to create an incident.
(...skipping 12 matching lines...) Expand all
270 // finishes. 275 // finishes.
271 void DeleteProfileOnUpload(Profile* profile) { 276 void DeleteProfileOnUpload(Profile* profile) {
272 ASSERT_TRUE(on_start_upload_callback_.is_null()); 277 ASSERT_TRUE(on_start_upload_callback_.is_null());
273 on_start_upload_callback_ = 278 on_start_upload_callback_ =
274 base::Bind(&IncidentReportingServiceTest::DelayedDeleteProfile, 279 base::Bind(&IncidentReportingServiceTest::DelayedDeleteProfile,
275 base::Unretained(this), 280 base::Unretained(this),
276 profile); 281 profile);
277 } 282 }
278 283
279 // Returns an incident suitable for testing. 284 // Returns an incident suitable for testing.
280 scoped_ptr<safe_browsing::Incident> MakeTestIncident(const char* value) { 285 std::unique_ptr<safe_browsing::Incident> MakeTestIncident(const char* value) {
281 scoped_ptr<safe_browsing:: 286 std::unique_ptr<
282 ClientIncidentReport_IncidentData_TrackedPreferenceIncident> 287 safe_browsing::
288 ClientIncidentReport_IncidentData_TrackedPreferenceIncident>
283 incident( 289 incident(
284 new safe_browsing:: 290 new safe_browsing::
285 ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); 291 ClientIncidentReport_IncidentData_TrackedPreferenceIncident());
286 incident->set_path(kTestTrackedPrefPath); 292 incident->set_path(kTestTrackedPrefPath);
287 if (value) 293 if (value)
288 incident->set_atomic_value(value); 294 incident->set_atomic_value(value);
289 return make_scoped_ptr(new safe_browsing::TrackedPreferenceIncident( 295 return base::WrapUnique(new safe_browsing::TrackedPreferenceIncident(
290 std::move(incident), false /* is_personal */)); 296 std::move(incident), false /* is_personal */));
291 } 297 }
292 298
293 // Adds a test incident to the service. 299 // Adds a test incident to the service.
294 void AddTestIncident(Profile* profile) { 300 void AddTestIncident(Profile* profile) {
295 scoped_ptr<safe_browsing::IncidentReceiver> receiver( 301 std::unique_ptr<safe_browsing::IncidentReceiver> receiver(
296 instance_->GetIncidentReceiver()); 302 instance_->GetIncidentReceiver());
297 if (profile) 303 if (profile)
298 receiver->AddIncidentForProfile(profile, MakeTestIncident(nullptr)); 304 receiver->AddIncidentForProfile(profile, MakeTestIncident(nullptr));
299 else 305 else
300 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); 306 receiver->AddIncidentForProcess(MakeTestIncident(nullptr));
301 } 307 }
302 308
303 // Registers the callback to be run for delayed analysis. 309 // Registers the callback to be run for delayed analysis.
304 void RegisterAnalysis(OnDelayedAnalysisAction on_delayed_analysis_action) { 310 void RegisterAnalysis(OnDelayedAnalysisAction on_delayed_analysis_action) {
305 on_delayed_analysis_action_ = on_delayed_analysis_action; 311 on_delayed_analysis_action_ = on_delayed_analysis_action;
(...skipping 14 matching lines...) Expand all
320 return environment_collected_ && instance_->HasCollectedExtension(); 326 return environment_collected_ && instance_->HasCollectedExtension();
321 } 327 }
322 bool HasCreatedDownloadFinder() const { return download_finder_created_; } 328 bool HasCreatedDownloadFinder() const { return download_finder_created_; }
323 bool DownloadFinderDestroyed() const { return download_finder_destroyed_; } 329 bool DownloadFinderDestroyed() const { return download_finder_destroyed_; }
324 bool UploaderDestroyed() const { return uploader_destroyed_; } 330 bool UploaderDestroyed() const { return uploader_destroyed_; }
325 bool DelayedAnalysisRan() const { return delayed_analysis_ran_; } 331 bool DelayedAnalysisRan() const { return delayed_analysis_ran_; }
326 332
327 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 333 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
328 base::ThreadTaskRunnerHandle thread_task_runner_handle_; 334 base::ThreadTaskRunnerHandle thread_task_runner_handle_;
329 TestingProfileManager profile_manager_; 335 TestingProfileManager profile_manager_;
330 scoped_ptr<TestIncidentReportingService> instance_; 336 std::unique_ptr<TestIncidentReportingService> instance_;
331 base::Closure on_start_upload_callback_; 337 base::Closure on_start_upload_callback_;
332 OnCreateDownloadFinderAction on_create_download_finder_action_; 338 OnCreateDownloadFinderAction on_create_download_finder_action_;
333 OnDelayedAnalysisAction on_delayed_analysis_action_; 339 OnDelayedAnalysisAction on_delayed_analysis_action_;
334 safe_browsing::IncidentReportUploader::Result upload_result_; 340 safe_browsing::IncidentReportUploader::Result upload_result_;
335 bool environment_collected_; 341 bool environment_collected_;
336 bool download_finder_created_; 342 bool download_finder_created_;
337 scoped_ptr<safe_browsing::ClientIncidentReport> uploaded_report_; 343 std::unique_ptr<safe_browsing::ClientIncidentReport> uploaded_report_;
338 bool download_finder_destroyed_; 344 bool download_finder_destroyed_;
339 bool uploader_destroyed_; 345 bool uploader_destroyed_;
340 bool delayed_analysis_ran_; 346 bool delayed_analysis_ran_;
341 scoped_ptr<base::FieldTrialList> field_trial_list_; 347 std::unique_ptr<base::FieldTrialList> field_trial_list_;
342 scoped_refptr<base::FieldTrial> field_trial_; 348 scoped_refptr<base::FieldTrial> field_trial_;
343 349
344 private: 350 private:
345 // A fake IncidentReportUploader that posts a task to provide a given response 351 // A fake IncidentReportUploader that posts a task to provide a given response
346 // back to the incident reporting service. It also reports back to the test 352 // back to the incident reporting service. It also reports back to the test
347 // harness via a closure when it is deleted by the incident reporting service. 353 // harness via a closure when it is deleted by the incident reporting service.
348 class FakeUploader : public safe_browsing::IncidentReportUploader { 354 class FakeUploader : public safe_browsing::IncidentReportUploader {
349 public: 355 public:
350 FakeUploader( 356 FakeUploader(
351 const base::Closure& on_deleted, 357 const base::Closure& on_deleted,
352 const safe_browsing::IncidentReportUploader::OnResultCallback& callback, 358 const safe_browsing::IncidentReportUploader::OnResultCallback& callback,
353 safe_browsing::IncidentReportUploader::Result result) 359 safe_browsing::IncidentReportUploader::Result result)
354 : safe_browsing::IncidentReportUploader(callback), 360 : safe_browsing::IncidentReportUploader(callback),
355 on_deleted_(on_deleted), 361 on_deleted_(on_deleted),
356 result_(result) { 362 result_(result) {
357 // Post a task that will provide the response. 363 // Post a task that will provide the response.
358 base::ThreadTaskRunnerHandle::Get()->PostTask( 364 base::ThreadTaskRunnerHandle::Get()->PostTask(
359 FROM_HERE, 365 FROM_HERE,
360 base::Bind(&FakeUploader::FinishUpload, base::Unretained(this))); 366 base::Bind(&FakeUploader::FinishUpload, base::Unretained(this)));
361 } 367 }
362 ~FakeUploader() override { on_deleted_.Run(); } 368 ~FakeUploader() override { on_deleted_.Run(); }
363 369
364 private: 370 private:
365 void FinishUpload() { 371 void FinishUpload() {
366 // Callbacks have a tendency to delete the uploader, so no touching 372 // Callbacks have a tendency to delete the uploader, so no touching
367 // anything after this. 373 // anything after this.
368 callback_.Run(result_, 374 callback_.Run(result_,
369 scoped_ptr<safe_browsing::ClientIncidentResponse>()); 375 std::unique_ptr<safe_browsing::ClientIncidentResponse>());
370 } 376 }
371 377
372 base::Closure on_deleted_; 378 base::Closure on_deleted_;
373 safe_browsing::IncidentReportUploader::Result result_; 379 safe_browsing::IncidentReportUploader::Result result_;
374 380
375 DISALLOW_COPY_AND_ASSIGN(FakeUploader); 381 DISALLOW_COPY_AND_ASSIGN(FakeUploader);
376 }; 382 };
377 383
378 class FakeDownloadFinder : public safe_browsing::LastDownloadFinder { 384 class FakeDownloadFinder : public safe_browsing::LastDownloadFinder {
379 public: 385 public:
380 static scoped_ptr<safe_browsing::LastDownloadFinder> Create( 386 static std::unique_ptr<safe_browsing::LastDownloadFinder> Create(
381 const base::Closure& on_deleted, 387 const base::Closure& on_deleted,
382 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> 388 std::unique_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>
383 binary_download, 389 binary_download,
384 scoped_ptr<safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails> 390 std::unique_ptr<
391 safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails>
385 non_binary_download, 392 non_binary_download,
386 const safe_browsing::LastDownloadFinder::LastDownloadCallback& 393 const safe_browsing::LastDownloadFinder::LastDownloadCallback&
387 callback) { 394 callback) {
388 // Post a task to run the callback. 395 // Post a task to run the callback.
389 base::ThreadTaskRunnerHandle::Get()->PostTask( 396 base::ThreadTaskRunnerHandle::Get()->PostTask(
390 FROM_HERE, base::Bind(callback, base::Passed(&binary_download), 397 FROM_HERE, base::Bind(callback, base::Passed(&binary_download),
391 base::Passed(&non_binary_download))); 398 base::Passed(&non_binary_download)));
392 return scoped_ptr<safe_browsing::LastDownloadFinder>( 399 return std::unique_ptr<safe_browsing::LastDownloadFinder>(
393 new FakeDownloadFinder(on_deleted)); 400 new FakeDownloadFinder(on_deleted));
394 } 401 }
395 402
396 ~FakeDownloadFinder() override { on_deleted_.Run(); } 403 ~FakeDownloadFinder() override { on_deleted_.Run(); }
397 404
398 private: 405 private:
399 explicit FakeDownloadFinder(const base::Closure& on_deleted) 406 explicit FakeDownloadFinder(const base::Closure& on_deleted)
400 : on_deleted_(on_deleted) {} 407 : on_deleted_(on_deleted) {}
401 408
402 base::Closure on_deleted_; 409 base::Closure on_deleted_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 safe_browsing::ClientIncidentReport_EnvironmentData* data) { 498 safe_browsing::ClientIncidentReport_EnvironmentData* data) {
492 ASSERT_NE( 499 ASSERT_NE(
493 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL), 500 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL),
494 data); 501 data);
495 data->mutable_os()->set_os_name(kFakeOsName); 502 data->mutable_os()->set_os_name(kFakeOsName);
496 environment_collected_ = true; 503 environment_collected_ = true;
497 } 504 }
498 505
499 // A fake CreateDownloadFinder implementation invoked by the service during 506 // A fake CreateDownloadFinder implementation invoked by the service during
500 // operation. 507 // operation.
501 scoped_ptr<safe_browsing::LastDownloadFinder> CreateDownloadFinder( 508 std::unique_ptr<safe_browsing::LastDownloadFinder> CreateDownloadFinder(
502 const safe_browsing::LastDownloadFinder::LastDownloadCallback& callback) { 509 const safe_browsing::LastDownloadFinder::LastDownloadCallback& callback) {
503 download_finder_created_ = true; 510 download_finder_created_ = true;
504 scoped_ptr<safe_browsing::ClientIncidentReport_DownloadDetails> 511 std::unique_ptr<safe_browsing::ClientIncidentReport_DownloadDetails>
505 binary_download; 512 binary_download;
506 scoped_ptr<safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails> 513 std::unique_ptr<
514 safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails>
507 non_binary_download; 515 non_binary_download;
508 if (on_create_download_finder_action_ == 516 if (on_create_download_finder_action_ ==
509 ON_CREATE_DOWNLOAD_FINDER_NO_PROFILES) { 517 ON_CREATE_DOWNLOAD_FINDER_NO_PROFILES) {
510 return scoped_ptr<safe_browsing::LastDownloadFinder>(); 518 return std::unique_ptr<safe_browsing::LastDownloadFinder>();
511 } 519 }
512 if (on_create_download_finder_action_ == 520 if (on_create_download_finder_action_ ==
513 ON_CREATE_DOWNLOAD_FINDER_DOWNLOADS_FOUND || 521 ON_CREATE_DOWNLOAD_FINDER_DOWNLOADS_FOUND ||
514 on_create_download_finder_action_ == 522 on_create_download_finder_action_ ==
515 ON_CREATE_DOWNLOAD_FINDER_BINARY_DOWNLOAD_FOUND) { 523 ON_CREATE_DOWNLOAD_FINDER_BINARY_DOWNLOAD_FOUND) {
516 binary_download.reset( 524 binary_download.reset(
517 new safe_browsing::ClientIncidentReport_DownloadDetails); 525 new safe_browsing::ClientIncidentReport_DownloadDetails);
518 binary_download->set_token(kFakeDownloadToken); 526 binary_download->set_token(kFakeDownloadToken);
519 } 527 }
520 if (on_create_download_finder_action_ == 528 if (on_create_download_finder_action_ ==
521 ON_CREATE_DOWNLOAD_FINDER_DOWNLOADS_FOUND || 529 ON_CREATE_DOWNLOAD_FINDER_DOWNLOADS_FOUND ||
522 on_create_download_finder_action_ == 530 on_create_download_finder_action_ ==
523 ON_CREATE_DOWNLOAD_FINDER_NON_BINARY_DOWNLOAD_FOUND) { 531 ON_CREATE_DOWNLOAD_FINDER_NON_BINARY_DOWNLOAD_FOUND) {
524 non_binary_download.reset( 532 non_binary_download.reset(
525 new safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails); 533 new safe_browsing::ClientIncidentReport_NonBinaryDownloadDetails);
526 non_binary_download->set_host(kFakeDownloadHost); 534 non_binary_download->set_host(kFakeDownloadHost);
527 } 535 }
528 536
529 return scoped_ptr<safe_browsing::LastDownloadFinder>( 537 return std::unique_ptr<safe_browsing::LastDownloadFinder>(
530 FakeDownloadFinder::Create( 538 FakeDownloadFinder::Create(
531 base::Bind(&IncidentReportingServiceTest::OnDownloadFinderDestroyed, 539 base::Bind(&IncidentReportingServiceTest::OnDownloadFinderDestroyed,
532 base::Unretained(this)), 540 base::Unretained(this)),
533 std::move(binary_download), std::move(non_binary_download), 541 std::move(binary_download), std::move(non_binary_download),
534 callback)); 542 callback));
535 } 543 }
536 544
537 // A fake StartUpload implementation invoked by the service during operation. 545 // A fake StartUpload implementation invoked by the service during operation.
538 scoped_ptr<safe_browsing::IncidentReportUploader> StartUpload( 546 std::unique_ptr<safe_browsing::IncidentReportUploader> StartUpload(
539 const safe_browsing::IncidentReportUploader::OnResultCallback& callback, 547 const safe_browsing::IncidentReportUploader::OnResultCallback& callback,
540 const safe_browsing::ClientIncidentReport& report) { 548 const safe_browsing::ClientIncidentReport& report) {
541 // Remember the report that is being uploaded. 549 // Remember the report that is being uploaded.
542 uploaded_report_.reset(new safe_browsing::ClientIncidentReport(report)); 550 uploaded_report_.reset(new safe_browsing::ClientIncidentReport(report));
543 // Run and clear the OnStartUpload callback, if provided. 551 // Run and clear the OnStartUpload callback, if provided.
544 if (!on_start_upload_callback_.is_null()) { 552 if (!on_start_upload_callback_.is_null()) {
545 on_start_upload_callback_.Run(); 553 on_start_upload_callback_.Run();
546 on_start_upload_callback_ = base::Closure(); 554 on_start_upload_callback_ = base::Closure();
547 } 555 }
548 return make_scoped_ptr(new FakeUploader( 556 return base::WrapUnique(new FakeUploader(
549 base::Bind(&IncidentReportingServiceTest::OnUploaderDestroyed, 557 base::Bind(&IncidentReportingServiceTest::OnUploaderDestroyed,
550 base::Unretained(this)), 558 base::Unretained(this)),
551 callback, upload_result_)); 559 callback, upload_result_));
552 } 560 }
553 561
554 void OnDownloadFinderDestroyed() { download_finder_destroyed_ = true; } 562 void OnDownloadFinderDestroyed() { download_finder_destroyed_ = true; }
555 void OnUploaderDestroyed() { uploader_destroyed_ = true; } 563 void OnUploaderDestroyed() { uploader_destroyed_ = true; }
556 564
557 void OnDelayedAnalysis(scoped_ptr<safe_browsing::IncidentReceiver> receiver) { 565 void OnDelayedAnalysis(
566 std::unique_ptr<safe_browsing::IncidentReceiver> receiver) {
558 delayed_analysis_ran_ = true; 567 delayed_analysis_ran_ = true;
559 if (on_delayed_analysis_action_ == ON_DELAYED_ANALYSIS_ADD_INCIDENT) 568 if (on_delayed_analysis_action_ == ON_DELAYED_ANALYSIS_ADD_INCIDENT)
560 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); 569 receiver->AddIncidentForProcess(MakeTestIncident(nullptr));
561 } 570 }
562 571
563 #if defined(OS_WIN) 572 #if defined(OS_WIN)
564 registry_util::RegistryOverrideManager registry_override_manager_; 573 registry_util::RegistryOverrideManager registry_override_manager_;
565 #endif 574 #endif
566 575
567 // A mapping of profile name to its corresponding properties. 576 // A mapping of profile name to its corresponding properties.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 } 772 }
764 773
765 // Tests that incidents are only uploaded after a profile has been opted into 774 // Tests that incidents are only uploaded after a profile has been opted into
766 // extended reporting. 775 // extended reporting.
767 TEST_F(IncidentReportingServiceTest, NoUploadBeforeExtendedReporting) { 776 TEST_F(IncidentReportingServiceTest, NoUploadBeforeExtendedReporting) {
768 SetFieldTrialAndCreateService(false); 777 SetFieldTrialAndCreateService(false);
769 // Create the profile, thereby causing the test to begin. 778 // Create the profile, thereby causing the test to begin.
770 Profile* profile = CreateProfile("profile1", SAFE_BROWSING_OPT_IN, 779 Profile* profile = CreateProfile("profile1", SAFE_BROWSING_OPT_IN,
771 ON_PROFILE_ADDITION_NO_ACTION, nullptr); 780 ON_PROFILE_ADDITION_NO_ACTION, nullptr);
772 781
773 scoped_ptr<safe_browsing::IncidentReceiver> receiver( 782 std::unique_ptr<safe_browsing::IncidentReceiver> receiver(
774 instance_->GetIncidentReceiver()); 783 instance_->GetIncidentReceiver());
775 784
776 // Add a process-wide test incident. 785 // Add a process-wide test incident.
777 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); 786 receiver->AddIncidentForProcess(MakeTestIncident(nullptr));
778 787
779 // Let all tasks run. 788 // Let all tasks run.
780 task_runner_->RunUntilIdle(); 789 task_runner_->RunUntilIdle();
781 790
782 // Downloads and environment data should have not been collected 791 // Downloads and environment data should have not been collected
783 // (DownloadFinder will be created, but should be a no-op since no eligible 792 // (DownloadFinder will be created, but should be a no-op since no eligible
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1101
1093 // Tests that two process-wide incidents of the same type with different 1102 // Tests that two process-wide incidents of the same type with different
1094 // payloads added via the same callback lead to two uploads. 1103 // payloads added via the same callback lead to two uploads.
1095 TEST_F(IncidentReportingServiceTest, ProcessWideTwoUploads) { 1104 TEST_F(IncidentReportingServiceTest, ProcessWideTwoUploads) {
1096 SetFieldTrialAndCreateService(false); 1105 SetFieldTrialAndCreateService(false);
1097 // Add a profile that participates in safe browsing. 1106 // Add a profile that participates in safe browsing.
1098 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN, 1107 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN,
1099 ON_PROFILE_ADDITION_NO_ACTION, nullptr); 1108 ON_PROFILE_ADDITION_NO_ACTION, nullptr);
1100 1109
1101 // Add the test incident. 1110 // Add the test incident.
1102 scoped_ptr<safe_browsing::IncidentReceiver> receiver( 1111 std::unique_ptr<safe_browsing::IncidentReceiver> receiver(
1103 instance_->GetIncidentReceiver()); 1112 instance_->GetIncidentReceiver());
1104 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); 1113 receiver->AddIncidentForProcess(MakeTestIncident(nullptr));
1105 1114
1106 // Let all tasks run. 1115 // Let all tasks run.
1107 task_runner_->RunUntilIdle(); 1116 task_runner_->RunUntilIdle();
1108 1117
1109 // An upload should have taken place. 1118 // An upload should have taken place.
1110 ExpectTestIncidentUploadWithBinaryDownload(1); 1119 ExpectTestIncidentUploadWithBinaryDownload(1);
1111 1120
1112 // Add a variation on the incident to the service. 1121 // Add a variation on the incident to the service.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 1378
1370 // Test that a profile's prune state is properly cleaned upon load. 1379 // Test that a profile's prune state is properly cleaned upon load.
1371 TEST_F(IncidentReportingServiceTest, CleanLegacyPruneState) { 1380 TEST_F(IncidentReportingServiceTest, CleanLegacyPruneState) {
1372 SetFieldTrialAndCreateService(false); 1381 SetFieldTrialAndCreateService(false);
1373 const std::string omnibox_type(base::IntToString( 1382 const std::string omnibox_type(base::IntToString(
1374 static_cast<int32_t>(safe_browsing::IncidentType::OMNIBOX_INTERACTION))); 1383 static_cast<int32_t>(safe_browsing::IncidentType::OMNIBOX_INTERACTION)));
1375 const std::string preference_type(base::IntToString( 1384 const std::string preference_type(base::IntToString(
1376 static_cast<int32_t>(safe_browsing::IncidentType::TRACKED_PREFERENCE))); 1385 static_cast<int32_t>(safe_browsing::IncidentType::TRACKED_PREFERENCE)));
1377 1386
1378 // Set up a prune state dict with data to be cleared (and not). 1387 // Set up a prune state dict with data to be cleared (and not).
1379 scoped_ptr<base::DictionaryValue> incidents_sent(new base::DictionaryValue()); 1388 std::unique_ptr<base::DictionaryValue> incidents_sent(
1389 new base::DictionaryValue());
1380 base::DictionaryValue* type_dict = new base::DictionaryValue(); 1390 base::DictionaryValue* type_dict = new base::DictionaryValue();
1381 type_dict->SetStringWithoutPathExpansion("foo", "47"); 1391 type_dict->SetStringWithoutPathExpansion("foo", "47");
1382 incidents_sent->SetWithoutPathExpansion(omnibox_type, type_dict); 1392 incidents_sent->SetWithoutPathExpansion(omnibox_type, type_dict);
1383 type_dict = new base::DictionaryValue(); 1393 type_dict = new base::DictionaryValue();
1384 type_dict->SetStringWithoutPathExpansion("bar", "43"); 1394 type_dict->SetStringWithoutPathExpansion("bar", "43");
1385 incidents_sent->SetWithoutPathExpansion(preference_type, type_dict); 1395 incidents_sent->SetWithoutPathExpansion(preference_type, type_dict);
1386 1396
1387 // Add a profile. 1397 // Add a profile.
1388 Profile* profile = 1398 Profile* profile =
1389 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN, 1399 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN,
(...skipping 11 matching lines...) Expand all
1401 } 1411 }
1402 1412
1403 // Tests that an identical incident added after an incident is pruned and 1413 // Tests that an identical incident added after an incident is pruned and
1404 // cleared leads to an upload. 1414 // cleared leads to an upload.
1405 TEST_F(IncidentReportingServiceTest, ProcessWideUploadClearUpload) { 1415 TEST_F(IncidentReportingServiceTest, ProcessWideUploadClearUpload) {
1406 SetFieldTrialAndCreateService(false); 1416 SetFieldTrialAndCreateService(false);
1407 // Add a profile that participates in safe browsing. 1417 // Add a profile that participates in safe browsing.
1408 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN, 1418 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN,
1409 ON_PROFILE_ADDITION_NO_ACTION, nullptr); 1419 ON_PROFILE_ADDITION_NO_ACTION, nullptr);
1410 1420
1411 scoped_ptr<safe_browsing::IncidentReceiver> receiver( 1421 std::unique_ptr<safe_browsing::IncidentReceiver> receiver(
1412 instance_->GetIncidentReceiver()); 1422 instance_->GetIncidentReceiver());
1413 1423
1414 // Add the test incident. 1424 // Add the test incident.
1415 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); 1425 receiver->AddIncidentForProcess(MakeTestIncident(nullptr));
1416 1426
1417 // Let all tasks run. 1427 // Let all tasks run.
1418 task_runner_->RunUntilIdle(); 1428 task_runner_->RunUntilIdle();
1419 1429
1420 // An upload should have taken place. 1430 // An upload should have taken place.
1421 ExpectTestIncidentUploadWithBinaryDownload(1); 1431 ExpectTestIncidentUploadWithBinaryDownload(1);
(...skipping 19 matching lines...) Expand all
1441 // Ensure that no report processing remains. 1451 // Ensure that no report processing remains.
1442 ASSERT_FALSE(instance_->IsProcessingReport()); 1452 ASSERT_FALSE(instance_->IsProcessingReport());
1443 } 1453 }
1444 1454
1445 TEST_F(IncidentReportingServiceTest, ClearProcessIncidentOnCleanState) { 1455 TEST_F(IncidentReportingServiceTest, ClearProcessIncidentOnCleanState) {
1446 SetFieldTrialAndCreateService(false); 1456 SetFieldTrialAndCreateService(false);
1447 // Add a profile that participates in safe browsing. 1457 // Add a profile that participates in safe browsing.
1448 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN, 1458 CreateProfile("profile1", EXTENDED_REPORTING_OPT_IN,
1449 ON_PROFILE_ADDITION_NO_ACTION, nullptr); 1459 ON_PROFILE_ADDITION_NO_ACTION, nullptr);
1450 1460
1451 scoped_ptr<safe_browsing::IncidentReceiver> receiver( 1461 std::unique_ptr<safe_browsing::IncidentReceiver> receiver(
1452 instance_->GetIncidentReceiver()); 1462 instance_->GetIncidentReceiver());
1453 1463
1454 // Clear incident data. 1464 // Clear incident data.
1455 receiver->ClearIncidentForProcess(MakeTestIncident(nullptr)); 1465 receiver->ClearIncidentForProcess(MakeTestIncident(nullptr));
1456 1466
1457 // Let all tasks run. 1467 // Let all tasks run.
1458 task_runner_->RunUntilIdle(); 1468 task_runner_->RunUntilIdle();
1459 1469
1460 // No uploads should have taken place. 1470 // No uploads should have taken place.
1461 ExpectTestIncidentUploadWithBinaryDownload(0); 1471 ExpectTestIncidentUploadWithBinaryDownload(0);
1462 1472
1463 // Downloads and environment data should have not been collected. 1473 // Downloads and environment data should have not been collected.
1464 ASSERT_FALSE(HasCreatedDownloadFinder()); 1474 ASSERT_FALSE(HasCreatedDownloadFinder());
1465 ASSERT_FALSE(HasCollectedEnvironmentAndExtensionData()); 1475 ASSERT_FALSE(HasCollectedEnvironmentAndExtensionData());
1466 1476
1467 // Ensure that no report processing remains. 1477 // Ensure that no report processing remains.
1468 ASSERT_FALSE(instance_->IsProcessingReport()); 1478 ASSERT_FALSE(instance_->IsProcessingReport());
1469 } 1479 }
1470 1480
1471 // Parallel uploads 1481 // Parallel uploads
1472 // Shutdown during processing 1482 // Shutdown during processing
1473 // environment colection taking longer than incident delay timer 1483 // environment colection taking longer than incident delay timer
1474 // environment colection taking longer than incident delay timer, and then 1484 // environment colection taking longer than incident delay timer, and then
1475 // another incident arriving 1485 // another incident arriving
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698