Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 // Returns an incident suitable for testing. | 131 // Returns an incident suitable for testing. |
| 132 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> | 132 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> |
| 133 MakeTestIncident() { | 133 MakeTestIncident() { |
| 134 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | 134 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( |
| 135 new safe_browsing::ClientIncidentReport_IncidentData()); | 135 new safe_browsing::ClientIncidentReport_IncidentData()); |
| 136 incident->set_incident_time_msec(kIncidentTimeMsec); | 136 incident->set_incident_time_msec(kIncidentTimeMsec); |
| 137 incident->mutable_tracked_preference(); | 137 incident->mutable_tracked_preference(); |
| 138 return incident.Pass(); | 138 return incident.Pass(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Confirms that the test incident was uploaded by the service. | 141 // Confirms that the test incident was uploaded by the service, then clears |
| 142 // the instance for subsequent incidents. | |
| 142 void ExpectTestIncidentUploaded() { | 143 void ExpectTestIncidentUploaded() { |
| 143 ASSERT_TRUE(uploaded_report_); | 144 ASSERT_TRUE(uploaded_report_); |
| 144 ASSERT_EQ(1, uploaded_report_->incident_size()); | 145 ASSERT_EQ(1, uploaded_report_->incident_size()); |
| 145 ASSERT_TRUE(uploaded_report_->incident(0).has_incident_time_msec()); | 146 ASSERT_TRUE(uploaded_report_->incident(0).has_incident_time_msec()); |
| 146 ASSERT_EQ(kIncidentTimeMsec, | 147 ASSERT_EQ(kIncidentTimeMsec, |
| 147 uploaded_report_->incident(0).incident_time_msec()); | 148 uploaded_report_->incident(0).incident_time_msec()); |
| 148 ASSERT_TRUE(uploaded_report_->has_environment()); | 149 ASSERT_TRUE(uploaded_report_->has_environment()); |
| 149 ASSERT_TRUE(uploaded_report_->environment().has_os()); | 150 ASSERT_TRUE(uploaded_report_->environment().has_os()); |
| 150 ASSERT_TRUE(uploaded_report_->environment().os().has_os_name()); | 151 ASSERT_TRUE(uploaded_report_->environment().os().has_os_name()); |
| 151 ASSERT_EQ(std::string(kFakeOsName), | 152 ASSERT_EQ(std::string(kFakeOsName), |
| 152 uploaded_report_->environment().os().os_name()); | 153 uploaded_report_->environment().os().os_name()); |
| 154 | |
| 155 uploaded_report_.reset(); | |
| 153 } | 156 } |
| 154 | 157 |
| 155 void ExpectNoUpload() { ASSERT_FALSE(uploaded_report_); } | 158 void ExpectNoUpload() { ASSERT_FALSE(uploaded_report_); } |
| 156 | 159 |
| 157 bool HasCollectedEnvironmentData() const { return environment_collected_; } | 160 bool HasCollectedEnvironmentData() const { return environment_collected_; } |
| 158 bool UploaderDestroyed() const { return uploader_destroyed_; } | 161 bool UploaderDestroyed() const { return uploader_destroyed_; } |
| 159 | 162 |
| 160 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 163 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 161 base::ThreadTaskRunnerHandle thread_task_runner_handle_; | 164 base::ThreadTaskRunnerHandle thread_task_runner_handle_; |
| 162 ScopedTestingLocalState local_state_; | 165 ScopedTestingLocalState local_state_; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 // Tests that an incident added during profile initialization when safe browsing | 270 // Tests that an incident added during profile initialization when safe browsing |
| 268 // is off is not uploaded. | 271 // is off is not uploaded. |
| 269 TEST_F(IncidentReportingServiceTest, NoSafeBrowsing) { | 272 TEST_F(IncidentReportingServiceTest, NoSafeBrowsing) { |
| 270 // Create the profile, thereby causing the test to begin. | 273 // Create the profile, thereby causing the test to begin. |
| 271 CreateProfileAndRunTest(false); | 274 CreateProfileAndRunTest(false); |
| 272 | 275 |
| 273 // Verify that no report upload took place. | 276 // Verify that no report upload took place. |
| 274 ExpectNoUpload(); | 277 ExpectNoUpload(); |
| 275 } | 278 } |
| 276 | 279 |
| 280 // Tests that an incident added after upload is not uploaded again. | |
|
mattm
2014/06/19 21:43:11
Add a test of incident reported and uploaded for o
mattm
2014/06/19 21:43:11
Add a test of profile gets destroyed while upload
grt (UTC plus 2)
2014/06/20 03:24:10
Done (TwoProfilesTwoUploads).
grt (UTC plus 2)
2014/06/20 03:24:10
Done (ProfileDestroyedDuringUpload).
| |
| 281 TEST_F(IncidentReportingServiceTest, OnlyOneUpload) { | |
| 282 // Create the profile, thereby causing the test to begin. | |
| 283 CreateProfileAndRunTest(true); | |
| 284 | |
| 285 // Verify that report upload took place and contained the incident and | |
| 286 // environment data. | |
| 287 ExpectTestIncidentUploaded(); | |
| 288 | |
| 289 // Add the incident to the service again. | |
| 290 instance_->GetAddIncidentCallback(testing_profile_.get()) | |
| 291 .Run(MakeTestIncident().Pass()); | |
| 292 | |
| 293 // Let all tasks run. | |
| 294 task_runner_->RunUntilIdle(); | |
| 295 | |
| 296 // Verify that no additional report upload took place. | |
| 297 ExpectNoUpload(); | |
| 298 } | |
| 299 | |
| 277 // Parallel uploads | 300 // Parallel uploads |
| 278 // Shutdown during processing | 301 // Shutdown during processing |
| 279 // environment colection taking longer than incident delay timer | 302 // environment colection taking longer than incident delay timer |
| 280 // environment colection taking longer than incident delay timer, and then | 303 // environment colection taking longer than incident delay timer, and then |
| 281 // another incident arriving | 304 // another incident arriving |
| OLD | NEW |