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/incident_reporting_service.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 355 |
356 // Properties for a profile that impact the behavior of the test. | 356 // Properties for a profile that impact the behavior of the test. |
357 struct ProfileProperties { | 357 struct ProfileProperties { |
358 ProfileProperties() : on_addition_action(ON_PROFILE_ADDITION_NO_ACTION) {} | 358 ProfileProperties() : on_addition_action(ON_PROFILE_ADDITION_NO_ACTION) {} |
359 | 359 |
360 // The action taken by the test fixture during profile initialization | 360 // The action taken by the test fixture during profile initialization |
361 // (before NOTIFICATION_PROFILE_ADDED is sent). | 361 // (before NOTIFICATION_PROFILE_ADDED is sent). |
362 OnProfileAdditionAction on_addition_action; | 362 OnProfileAdditionAction on_addition_action; |
363 }; | 363 }; |
364 | 364 |
365 // Returns the name of a profile as provided to CreateProfile. | |
366 static std::string GetProfileName(Profile* profile) { | |
367 // Cannot reliably use profile->GetProfileName() since the test needs the | |
368 // name before the profile manager sets it (which happens after profile | |
369 // addition). | |
370 return profile->GetPath().BaseName().AsUTF8Unsafe(); | |
371 } | |
372 | |
373 // Posts a task to delete the profile. | 365 // Posts a task to delete the profile. |
374 void DelayedDeleteProfile(Profile* profile) { | 366 void DelayedDeleteProfile(Profile* profile) { |
375 base::ThreadTaskRunnerHandle::Get()->PostTask( | 367 base::ThreadTaskRunnerHandle::Get()->PostTask( |
376 FROM_HERE, | 368 FROM_HERE, |
377 base::Bind(&TestingProfileManager::DeleteTestingProfile, | 369 base::Bind(&TestingProfileManager::DeleteTestingProfile, |
378 base::Unretained(&profile_manager_), | 370 base::Unretained(&profile_manager_), |
379 GetProfileName(profile))); | 371 profile->GetProfileName())); |
380 } | 372 } |
381 | 373 |
382 // A callback run by the test fixture when a profile is added. An incident | 374 // A callback run by the test fixture when a profile is added. An incident |
383 // is added. | 375 // is added. |
384 void PreProfileAdd(Profile* profile) { | 376 void PreProfileAdd(Profile* profile) { |
385 // The instance must have already been created. | 377 // The instance must have already been created. |
386 ASSERT_TRUE(instance_); | 378 ASSERT_TRUE(instance_); |
387 // Add a test incident to the service if requested. | 379 // Add a test incident to the service if requested. |
388 switch (profile_properties_[GetProfileName(profile)].on_addition_action) { | 380 switch (profile_properties_[profile->GetProfileName()].on_addition_action) { |
389 case ON_PROFILE_ADDITION_ADD_INCIDENT: | 381 case ON_PROFILE_ADDITION_ADD_INCIDENT: |
390 AddTestIncident(profile); | 382 AddTestIncident(profile); |
391 break; | 383 break; |
392 case ON_PROFILE_ADDITION_ADD_TWO_INCIDENTS: | 384 case ON_PROFILE_ADDITION_ADD_TWO_INCIDENTS: |
393 AddTestIncident(profile); | 385 AddTestIncident(profile); |
394 AddTestIncident(profile); | 386 AddTestIncident(profile); |
395 break; | 387 break; |
396 default: | 388 default: |
397 ASSERT_EQ( | 389 ASSERT_EQ( |
398 ON_PROFILE_ADDITION_NO_ACTION, | 390 ON_PROFILE_ADDITION_NO_ACTION, |
399 profile_properties_[GetProfileName(profile)].on_addition_action); | 391 profile_properties_[profile->GetProfileName()].on_addition_action); |
400 break; | 392 break; |
401 } | 393 } |
402 } | 394 } |
403 | 395 |
404 // A fake CollectEnvironmentData implementation invoked by the service during | 396 // A fake CollectEnvironmentData implementation invoked by the service during |
405 // operation. | 397 // operation. |
406 void CollectEnvironmentData( | 398 void CollectEnvironmentData( |
407 safe_browsing::ClientIncidentReport_EnvironmentData* data) { | 399 safe_browsing::ClientIncidentReport_EnvironmentData* data) { |
408 ASSERT_NE( | 400 ASSERT_NE( |
409 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL), | 401 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL), |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 | 881 |
890 // Verify that no additional report upload took place. | 882 // Verify that no additional report upload took place. |
891 AssertNoUpload(); | 883 AssertNoUpload(); |
892 } | 884 } |
893 | 885 |
894 // Parallel uploads | 886 // Parallel uploads |
895 // Shutdown during processing | 887 // Shutdown during processing |
896 // environment colection taking longer than incident delay timer | 888 // environment colection taking longer than incident delay timer |
897 // environment colection taking longer than incident delay timer, and then | 889 // environment colection taking longer than incident delay timer, and then |
898 // another incident arriving | 890 // another incident arriving |
OLD | NEW |