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

Side by Side Diff: chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc

Issue 2632533002: Add retry information to certificate reports. (Closed)
Patch Set: Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/certificate_reporting_service.h" 5 #include "chrome/browser/safe_browsing/certificate_reporting_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 #include "net/cert/x509_util.h" 29 #include "net/cert/x509_util.h"
30 #include "net/ssl/ssl_info.h" 30 #include "net/ssl/ssl_info.h"
31 #include "net/test/url_request/url_request_failed_job.h" 31 #include "net/test/url_request/url_request_failed_job.h"
32 #include "net/test/url_request/url_request_mock_data_job.h" 32 #include "net/test/url_request/url_request_mock_data_job.h"
33 #include "net/url_request/url_request_filter.h" 33 #include "net/url_request/url_request_filter.h"
34 #include "net/url_request/url_request_test_util.h" 34 #include "net/url_request/url_request_test_util.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using certificate_reporting_test_utils::CertificateReportingServiceTestHelper; 37 using certificate_reporting_test_utils::CertificateReportingServiceTestHelper;
38 using certificate_reporting_test_utils::CertificateReportingServiceObserver; 38 using certificate_reporting_test_utils::CertificateReportingServiceObserver;
39 using certificate_reporting_test_utils::ObservedReport;
39 using certificate_reporting_test_utils::ReportExpectation; 40 using certificate_reporting_test_utils::ReportExpectation;
40 41
41 namespace { 42 namespace {
42 43
43 // Maximum number of reports kept in the certificate reporting service's retry 44 // Maximum number of reports kept in the certificate reporting service's retry
44 // queue. 45 // queue.
45 const size_t kMaxReportCountInQueue = 3; 46 const size_t kMaxReportCountInQueue = 3;
46 47
47 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; 48 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure";
48 49
(...skipping 20 matching lines...) Expand all
69 std::string MakeReport(const std::string& hostname) { 70 std::string MakeReport(const std::string& hostname) {
70 net::SSLInfo ssl_info; 71 net::SSLInfo ssl_info;
71 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert(); 72 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
72 73
73 certificate_reporting::ErrorReport report(hostname, ssl_info); 74 certificate_reporting::ErrorReport report(hostname, ssl_info);
74 std::string serialized_report; 75 std::string serialized_report;
75 EXPECT_TRUE(report.Serialize(&serialized_report)); 76 EXPECT_TRUE(report.Serialize(&serialized_report));
76 return serialized_report; 77 return serialized_report;
77 } 78 }
78 79
80 void AssertReport(const CertificateReportingService::Report& report,
estark 2017/01/13 23:26:22 CheckReport?
meacer 2017/01/17 22:24:27 Done.
81 const std::string& expected_hostname,
82 bool expected_is_retry_upload,
83 const base::Time& expected_creation_time) {
84 certificate_reporting::ErrorReport error_report;
85 EXPECT_TRUE(error_report.InitializeFromString(report.serialized_report));
86 EXPECT_EQ(expected_hostname, error_report.hostname());
87 EXPECT_EQ(expected_is_retry_upload, error_report.is_retry_upload());
88 EXPECT_EQ(expected_creation_time, report.creation_time);
89 }
90
79 void ClearURLHandlers() { 91 void ClearURLHandlers() {
80 net::URLRequestFilter::GetInstance()->ClearHandlers(); 92 net::URLRequestFilter::GetInstance()->ClearHandlers();
81 } 93 }
82 94
83 // Class for histogram testing. The failed report histogram is checked once 95 // Class for histogram testing. The failed report histogram is checked once
84 // after teardown to ensure all in flight requests have completed. 96 // after teardown to ensure all in flight requests have completed.
85 class ReportHistogramTestHelper { 97 class ReportHistogramTestHelper {
86 public: 98 public:
87 // Sets the expected histogram value to be checked during teardown. 99 // Sets the expected histogram value to be checked during teardown.
88 void SetExpectedFailedReportCount(unsigned int num_expected_failed_report) { 100 void SetExpectedFailedReportCount(unsigned int num_expected_failed_report) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 191
180 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 192 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
181 ReportHistogramTestHelper histogram_test_helper_; 193 ReportHistogramTestHelper histogram_test_helper_;
182 }; 194 };
183 195
184 TEST_F(CertificateReportingServiceReporterOnIOThreadTest, 196 TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
185 Reporter_RetriesEnabled) { 197 Reporter_RetriesEnabled) {
186 SetExpectedFailedReportCountOnTearDown(6); 198 SetExpectedFailedReportCountOnTearDown(6);
187 199
188 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); 200 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock());
189 base::Time reference_time = base::Time::Now(); 201 const base::Time reference_time = base::Time::Now();
190 clock->SetNow(reference_time); 202 clock->SetNow(reference_time);
191 203
192 const GURL kFailureURL = 204 const GURL kFailureURL =
193 net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_SSL_PROTOCOL_ERROR); 205 net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_SSL_PROTOCOL_ERROR);
194 certificate_reporting::ErrorReporter* certificate_error_reporter = 206 certificate_reporting::ErrorReporter* certificate_error_reporter =
195 new certificate_reporting::ErrorReporter( 207 new certificate_reporting::ErrorReporter(
196 url_request_context_getter()->GetURLRequestContext(), kFailureURL, 208 url_request_context_getter()->GetURLRequestContext(), kFailureURL,
197 net::ReportSender::DO_NOT_SEND_COOKIES); 209 net::ReportSender::DO_NOT_SEND_COOKIES);
198 210
199 CertificateReportingService::BoundedReportList* list = 211 CertificateReportingService::BoundedReportList* list =
200 new CertificateReportingService::BoundedReportList(2); 212 new CertificateReportingService::BoundedReportList(2);
201 213
202 // Create a reporter with retries enabled. 214 // Create a reporter with retries enabled.
203 CertificateReportingService::Reporter reporter( 215 CertificateReportingService::Reporter reporter(
204 std::unique_ptr<certificate_reporting::ErrorReporter>( 216 std::unique_ptr<certificate_reporting::ErrorReporter>(
205 certificate_error_reporter), 217 certificate_error_reporter),
206 std::unique_ptr<CertificateReportingService::BoundedReportList>(list), 218 std::unique_ptr<CertificateReportingService::BoundedReportList>(list),
207 clock.get(), base::TimeDelta::FromSeconds(100), 219 clock.get(), base::TimeDelta::FromSeconds(100),
208 true /* retries_enabled */); 220 true /* retries_enabled */);
209 EXPECT_EQ(0u, list->items().size()); 221 EXPECT_EQ(0u, list->items().size());
210 EXPECT_EQ(0u, reporter.inflight_report_count_for_testing()); 222 EXPECT_EQ(0u, reporter.inflight_report_count_for_testing());
211 223
212 // Sending a failed report will put the report in the retry list. 224 // Sending a failed report will put the report in the retry list.
213 reporter.Send("report1"); 225 reporter.Send(MakeReport("report1"));
214 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing()); 226 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing());
215 base::RunLoop().RunUntilIdle(); 227 base::RunLoop().RunUntilIdle();
216 228
217 EXPECT_EQ(0u, reporter.inflight_report_count_for_testing()); 229 EXPECT_EQ(0u, reporter.inflight_report_count_for_testing());
218 ASSERT_EQ(1u, list->items().size()); 230 ASSERT_EQ(1u, list->items().size());
219 EXPECT_EQ("report1", list->items()[0].serialized_report); 231 AssertReport(list->items()[0], "report1", false, reference_time);
220 EXPECT_EQ(reference_time, list->items()[0].creation_time);
221 232
222 // Sending a second failed report will also put it in the retry list. 233 // Sending a second failed report will also put it in the retry list.
223 clock->Advance(base::TimeDelta::FromSeconds(10)); 234 clock->Advance(base::TimeDelta::FromSeconds(10));
224 reporter.Send("report2"); 235 reporter.Send(MakeReport("report2"));
225 base::RunLoop().RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
226 ASSERT_EQ(2u, list->items().size()); 237 ASSERT_EQ(2u, list->items().size());
227 EXPECT_EQ("report2", list->items()[0].serialized_report); 238 AssertReport(list->items()[0], "report2", false,
228 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(10), 239 reference_time + base::TimeDelta::FromSeconds(10));
229 list->items()[0].creation_time); 240 AssertReport(list->items()[1], "report1", false, reference_time);
230 EXPECT_EQ("report1", list->items()[1].serialized_report);
231 EXPECT_EQ(reference_time, list->items()[1].creation_time);
232 241
233 // Sending a third report should remove the first report from the retry list. 242 // Sending a third report should remove the first report from the retry list.
234 clock->Advance(base::TimeDelta::FromSeconds(10)); 243 clock->Advance(base::TimeDelta::FromSeconds(10));
235 reporter.Send("report3"); 244 reporter.Send(MakeReport("report3"));
236 base::RunLoop().RunUntilIdle(); 245 base::RunLoop().RunUntilIdle();
237 ASSERT_EQ(2u, list->items().size()); 246 ASSERT_EQ(2u, list->items().size());
238 EXPECT_EQ("report3", list->items()[0].serialized_report); 247 AssertReport(list->items()[0], "report3", false,
239 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(20), 248 reference_time + base::TimeDelta::FromSeconds(20));
240 list->items()[0].creation_time); 249 AssertReport(list->items()[1], "report2", false,
241 EXPECT_EQ("report2", list->items()[1].serialized_report); 250 reference_time + base::TimeDelta::FromSeconds(10));
242 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(10),
243 list->items()[1].creation_time);
244 251
245 // Retry sending all pending reports. All should fail and get added to the 252 // Retry sending all pending reports. All should fail and get added to the
246 // retry list again. Report creation time doesn't change for retried reports. 253 // retry list again. Report creation time doesn't change for retried reports.
247 clock->Advance(base::TimeDelta::FromSeconds(10)); 254 clock->Advance(base::TimeDelta::FromSeconds(10));
248 reporter.SendPending(); 255 reporter.SendPending();
249 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
250 ASSERT_EQ(2u, list->items().size()); 257 ASSERT_EQ(2u, list->items().size());
251 EXPECT_EQ("report3", list->items()[0].serialized_report); 258 AssertReport(list->items()[0], "report3", true,
252 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(20), 259 reference_time + base::TimeDelta::FromSeconds(20));
253 list->items()[0].creation_time); 260 AssertReport(list->items()[1], "report2", true,
254 EXPECT_EQ("report2", list->items()[1].serialized_report); 261 reference_time + base::TimeDelta::FromSeconds(10));
255 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(10),
256 list->items()[1].creation_time);
257 262
258 // Advance the clock to 115 seconds. This makes report3 95 seconds old, and 263 // Advance the clock to 115 seconds. This makes report3 95 seconds old, and
259 // report2 105 seconds old. report2 should be dropped because it's older than 264 // report2 105 seconds old. report2 should be dropped because it's older than
260 // max age (100 seconds). 265 // max age (100 seconds).
261 clock->SetNow(reference_time + base::TimeDelta::FromSeconds(115)); 266 clock->SetNow(reference_time + base::TimeDelta::FromSeconds(115));
262 reporter.SendPending(); 267 reporter.SendPending();
263 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing()); 268 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing());
264 base::RunLoop().RunUntilIdle(); 269 base::RunLoop().RunUntilIdle();
265 ASSERT_EQ(1u, list->items().size()); 270 ASSERT_EQ(1u, list->items().size());
266 EXPECT_EQ("report3", list->items()[0].serialized_report); 271 AssertReport(list->items()[0], "report3", true,
267 EXPECT_EQ(reference_time + base::TimeDelta::FromSeconds(20), 272 reference_time + base::TimeDelta::FromSeconds(20));
268 list->items()[0].creation_time);
269 273
270 // Retry again, this time successfully. There should be no pending reports 274 // Send pending reports again, this time successfully. There should be no
271 // left. 275 // pending reports left.
272 const GURL kSuccessURL = 276 const GURL kSuccessURL =
273 net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); 277 net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
274 certificate_error_reporter->set_upload_url_for_testing(kSuccessURL); 278 certificate_error_reporter->set_upload_url_for_testing(kSuccessURL);
275 clock->Advance(base::TimeDelta::FromSeconds(1)); 279 clock->Advance(base::TimeDelta::FromSeconds(1));
276 reporter.SendPending(); 280 reporter.SendPending();
277 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing()); 281 EXPECT_EQ(1u, reporter.inflight_report_count_for_testing());
278 base::RunLoop().RunUntilIdle(); 282 base::RunLoop().RunUntilIdle();
279 EXPECT_EQ(0u, list->items().size()); 283 EXPECT_EQ(0u, list->items().size());
280 } 284 }
281 285
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 450
447 scoped_refptr<safe_browsing::SafeBrowsingService> sb_service_; 451 scoped_refptr<safe_browsing::SafeBrowsingService> sb_service_;
448 safe_browsing::TestSafeBrowsingServiceFactory sb_service_factory; 452 safe_browsing::TestSafeBrowsingServiceFactory sb_service_factory;
449 TestingProfile profile_; 453 TestingProfile profile_;
450 454
451 CertificateReportingServiceTestHelper test_helper_; 455 CertificateReportingServiceTestHelper test_helper_;
452 ReportHistogramTestHelper histogram_test_helper_; 456 ReportHistogramTestHelper histogram_test_helper_;
453 CertificateReportingServiceObserver service_observer_; 457 CertificateReportingServiceObserver service_observer_;
454 }; 458 };
455 459
456 TEST_F(CertificateReportingServiceTest, Send) { 460 TEST_F(CertificateReportingServiceTest, SendSuccessful) {
461 SetExpectedFailedReportCountOnTearDown(0);
462
463 // Let all reports succeed.
464 test_helper()->SetFailureMode(certificate_reporting_test_utils::
465 ReportSendingResult::REPORTS_SUCCESSFUL);
466
467 service()->Send(MakeReport("report0"));
468 service()->Send(MakeReport("report1"));
469 test_helper()->WaitForRequestsDestroyed(
470 ReportExpectation::Successful({ObservedReport::NotRetried("report0"),
471 ObservedReport::NotRetried("report1")}));
472 }
473
474 TEST_F(CertificateReportingServiceTest, SendFailure) {
457 SetExpectedFailedReportCountOnTearDown(4); 475 SetExpectedFailedReportCountOnTearDown(4);
458 476
459 // Let all reports fail. 477 // Let all reports fail.
460 test_helper()->SetFailureMode( 478 test_helper()->SetFailureMode(
461 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 479 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
462 480
463 // Send two reports. Both should fail and get queued. 481 // Send two reports. Both should fail and get queued.
464 service()->Send(MakeReport("report0")); 482 service()->Send(MakeReport("report0"));
465 service()->Send(MakeReport("report1")); 483 service()->Send(MakeReport("report1"));
466 test_helper()->WaitForRequestsDestroyed( 484 test_helper()->WaitForRequestsDestroyed(
467 ReportExpectation::Failed({"report0", "report1"})); 485 ReportExpectation::Failed({ObservedReport::NotRetried("report0"),
486 ObservedReport::NotRetried("report1")}));
468 487
469 // Send pending reports. Previously queued reports should be queued again. 488 // Send pending reports. Previously queued reports should be queued again.
470 service()->SendPending(); 489 service()->SendPending();
471 test_helper()->WaitForRequestsDestroyed( 490 test_helper()->WaitForRequestsDestroyed(
472 ReportExpectation::Failed({"report0", "report1"})); 491 ReportExpectation::Failed({ObservedReport::Retried("report0"),
492 ObservedReport::Retried("report1")}));
473 493
474 // Let all reports succeed. 494 // Let all reports succeed.
475 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 495 test_helper()->SetFailureMode(certificate_reporting_test_utils::
476 ReportSendingResult::REPORTS_SUCCESSFUL); 496 ReportSendingResult::REPORTS_SUCCESSFUL);
477 497
478 // Send a third report. This should not be queued. 498 // Send a third report. This should not be queued.
479 service()->Send(MakeReport("report2")); 499 service()->Send(MakeReport("report2"));
480 test_helper()->WaitForRequestsDestroyed( 500 test_helper()->WaitForRequestsDestroyed(
481 ReportExpectation::Successful({"report2"})); 501 ReportExpectation::Successful({ObservedReport::NotRetried("report2")}));
482 502
483 // Send pending reports. Previously failed and queued two reports should be 503 // Send pending reports. Previously failed and queued two reports should be
484 // observed. 504 // observed.
485 service()->SendPending(); 505 service()->SendPending();
486 test_helper()->WaitForRequestsDestroyed( 506 test_helper()->WaitForRequestsDestroyed(
487 ReportExpectation::Successful({"report0", "report1"})); 507 ReportExpectation::Successful({ObservedReport::Retried("report0"),
508 ObservedReport::Retried("report1")}));
488 } 509 }
489 510
490 TEST_F(CertificateReportingServiceTest, Disabled_ShouldNotSend) { 511 TEST_F(CertificateReportingServiceTest, Disabled_ShouldNotSend) {
491 SetExpectedFailedReportCountOnTearDown(0); 512 SetExpectedFailedReportCountOnTearDown(0);
492 513
493 // Let all reports succeed. 514 // Let all reports succeed.
494 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 515 test_helper()->SetFailureMode(certificate_reporting_test_utils::
495 ReportSendingResult::REPORTS_SUCCESSFUL); 516 ReportSendingResult::REPORTS_SUCCESSFUL);
496 517
497 // Disable the service. 518 // Disable the service.
498 SetServiceEnabledAndWait(false); 519 SetServiceEnabledAndWait(false);
499 520
500 // Send a report. Report attempt should be cancelled and no sent reports 521 // Send a report. Report attempt should be cancelled and no sent reports
501 // should be observed. 522 // should be observed.
502 service()->Send(MakeReport("report0")); 523 service()->Send(MakeReport("report0"));
503 524
504 // Enable the service and send a report again. It should be sent successfully. 525 // Enable the service and send a report again. It should be sent successfully.
505 SetServiceEnabledAndWait(true); 526 SetServiceEnabledAndWait(true);
506 527
507 service()->Send(MakeReport("report1")); 528 service()->Send(MakeReport("report1"));
508 test_helper()->WaitForRequestsDestroyed( 529 test_helper()->WaitForRequestsDestroyed(
509 ReportExpectation::Successful({"report1"})); 530 ReportExpectation::Successful({ObservedReport::NotRetried("report1")}));
510 } 531 }
511 532
512 TEST_F(CertificateReportingServiceTest, Disabled_ShouldClearPendingReports) { 533 TEST_F(CertificateReportingServiceTest, Disabled_ShouldClearPendingReports) {
513 SetExpectedFailedReportCountOnTearDown(1); 534 SetExpectedFailedReportCountOnTearDown(1);
514 535
515 // Let all reports fail. 536 // Let all reports fail.
516 test_helper()->SetFailureMode( 537 test_helper()->SetFailureMode(
517 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 538 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
518 539
519 service()->Send(MakeReport("report0")); 540 service()->Send(MakeReport("report0"));
520 test_helper()->WaitForRequestsDestroyed( 541 test_helper()->WaitForRequestsDestroyed(
521 ReportExpectation::Failed({"report0"})); 542 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
522 543
523 // Disable the service. 544 // Disable the service.
524 SetServiceEnabledAndWait(false); 545 SetServiceEnabledAndWait(false);
525 546
526 // Sending has no effect while disabled. 547 // Sending has no effect while disabled.
527 service()->SendPending(); 548 service()->SendPending();
528 549
529 // Re-enable the service and send pending reports. Pending reports should have 550 // Re-enable the service and send pending reports. Pending reports should have
530 // been cleared when the service was disabled, so no report should be seen. 551 // been cleared when the service was disabled, so no report should be seen.
531 SetServiceEnabledAndWait(true); 552 SetServiceEnabledAndWait(true);
532 553
533 // Sending with empty queue has no effect. 554 // Sending with empty queue has no effect.
534 service()->SendPending(); 555 service()->SendPending();
535 } 556 }
536 557
537 TEST_F(CertificateReportingServiceTest, DontSendOldReports) { 558 TEST_F(CertificateReportingServiceTest, DontSendOldReports) {
538 SetExpectedFailedReportCountOnTearDown(5); 559 SetExpectedFailedReportCountOnTearDown(5);
539 560
540 SetNow(base::Time::Now()); 561 SetNow(base::Time::Now());
541 // Let all reports fail. 562 // Let all reports fail.
542 test_helper()->SetFailureMode( 563 test_helper()->SetFailureMode(
543 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 564 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
544 565
545 // Send a report, then advance the clock and send another report. 566 // Send a report, then advance the clock and send another report.
546 service()->Send(MakeReport("report0")); 567 service()->Send(MakeReport("report0"));
547 AdvanceClock(base::TimeDelta::FromHours(5)); 568 AdvanceClock(base::TimeDelta::FromHours(5));
548 service()->Send(MakeReport("report1")); 569 service()->Send(MakeReport("report1"));
549 test_helper()->WaitForRequestsDestroyed( 570 test_helper()->WaitForRequestsDestroyed(
550 ReportExpectation::Failed({"report0", "report1"})); 571 ReportExpectation::Failed({ObservedReport::NotRetried("report0"),
572 ObservedReport::NotRetried("report1")}));
551 573
552 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference 574 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference
553 // time. This makes the report0 older than max age (24 hours). The report1 is 575 // time. This makes the report0 older than max age (24 hours). The report1 is
554 // now 20 hours old. 576 // now 20 hours old.
555 AdvanceClock(base::TimeDelta::FromHours(20)); 577 AdvanceClock(base::TimeDelta::FromHours(20));
556 // Send pending reports. report0 should be discarded since it's too old. 578 // Send pending reports. report0 should be discarded since it's too old.
557 // report1 should be queued again. 579 // report1 should be queued again.
558 service()->SendPending(); 580 service()->SendPending();
559 test_helper()->WaitForRequestsDestroyed( 581 test_helper()->WaitForRequestsDestroyed(
560 ReportExpectation::Failed({"report1"})); 582 ReportExpectation::Failed({ObservedReport::Retried("report1")}));
561 583
562 // Send a third report. 584 // Send a third report.
563 service()->Send(MakeReport("report2")); 585 service()->Send(MakeReport("report2"));
564 test_helper()->WaitForRequestsDestroyed( 586 test_helper()->WaitForRequestsDestroyed(
565 ReportExpectation::Failed({"report2"})); 587 ReportExpectation::Failed({ObservedReport::NotRetried("report2")}));
566 588
567 // Advance the clock 5 hours. The report1 will now be 25 hours old. 589 // Advance the clock 5 hours. The report1 will now be 25 hours old.
568 AdvanceClock(base::TimeDelta::FromHours(5)); 590 AdvanceClock(base::TimeDelta::FromHours(5));
569 // Send pending reports. report1 should be discarded since it's too old. 591 // Send pending reports. report1 should be discarded since it's too old.
570 // report2 should be queued again. 592 // report2 should be queued again.
571 service()->SendPending(); 593 service()->SendPending();
572 test_helper()->WaitForRequestsDestroyed( 594 test_helper()->WaitForRequestsDestroyed(
573 ReportExpectation::Failed({"report2"})); 595 ReportExpectation::Failed({ObservedReport::Retried("report2")}));
574 596
575 // Advance the clock 20 hours again so that report2 is 25 hours old and is 597 // Advance the clock 20 hours again so that report2 is 25 hours old and is
576 // older than max age (24 hours) 598 // older than max age (24 hours)
577 AdvanceClock(base::TimeDelta::FromHours(20)); 599 AdvanceClock(base::TimeDelta::FromHours(20));
578 // Send pending reports. report2 should be discarded since it's too old. No 600 // Send pending reports. report2 should be discarded since it's too old. No
579 // other reports remain. 601 // other reports remain.
580 service()->SendPending(); 602 service()->SendPending();
581 } 603 }
582 604
583 TEST_F(CertificateReportingServiceTest, DiscardOldReports) { 605 TEST_F(CertificateReportingServiceTest, DiscardOldReports) {
(...skipping 13 matching lines...) Expand all
597 619
598 AdvanceClock(base::TimeDelta::FromHours(5)); 620 AdvanceClock(base::TimeDelta::FromHours(5));
599 service()->Send(MakeReport("report1")); 621 service()->Send(MakeReport("report1"));
600 622
601 AdvanceClock(base::TimeDelta::FromHours(5)); 623 AdvanceClock(base::TimeDelta::FromHours(5));
602 service()->Send(MakeReport("report2")); 624 service()->Send(MakeReport("report2"));
603 625
604 AdvanceClock(base::TimeDelta::FromHours(5)); 626 AdvanceClock(base::TimeDelta::FromHours(5));
605 service()->Send(MakeReport("report3")); 627 service()->Send(MakeReport("report3"));
606 test_helper()->WaitForRequestsDestroyed( 628 test_helper()->WaitForRequestsDestroyed(
607 ReportExpectation::Failed({"report0", "report1", "report2", "report3"})); 629 ReportExpectation::Failed({ObservedReport::NotRetried("report0"),
630 ObservedReport::NotRetried("report1"),
631 ObservedReport::NotRetried("report2"),
632 ObservedReport::NotRetried("report3")}));
608 633
609 // Send pending reports. Four reports were generated above, but the service 634 // Send pending reports. Four reports were generated above, but the service
610 // only queues three reports, so the very first one should be dropped since 635 // only queues three reports, so the very first one should be dropped since
611 // it's the oldest. 636 // it's the oldest.
612 service()->SendPending(); 637 service()->SendPending();
613 test_helper()->WaitForRequestsDestroyed( 638 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Failed(
614 ReportExpectation::Failed({"report1", "report2", "report3"})); 639 {ObservedReport::Retried("report1"), ObservedReport::Retried("report2"),
640 ObservedReport::Retried("report3")}));
615 641
616 // Let all reports succeed. 642 // Let all reports succeed.
617 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 643 test_helper()->SetFailureMode(certificate_reporting_test_utils::
618 ReportSendingResult::REPORTS_SUCCESSFUL); 644 ReportSendingResult::REPORTS_SUCCESSFUL);
619 645
620 // Advance the clock by 15 hours. Current time is now 30 hours after reference 646 // Advance the clock by 15 hours. Current time is now 30 hours after reference
621 // time. The ages of reports are now as follows: 647 // time. The ages of reports are now as follows:
622 // report1 is 25 hours old. 648 // report1 is 25 hours old.
623 // report2 is 20 hours old. 649 // report2 is 20 hours old.
624 // report3 is 15 hours old. 650 // report3 is 15 hours old.
625 AdvanceClock(base::TimeDelta::FromHours(15)); 651 AdvanceClock(base::TimeDelta::FromHours(15));
626 // Send pending reports. Only report2 and report3 should be sent, report1 652 // Send pending reports. Only report2 and report3 should be sent, report1
627 // should be ignored because it's too old. 653 // should be ignored because it's too old.
628 service()->SendPending(); 654 service()->SendPending();
629 test_helper()->WaitForRequestsDestroyed( 655 test_helper()->WaitForRequestsDestroyed(
630 ReportExpectation::Successful({"report2", "report3"})); 656 ReportExpectation::Successful({ObservedReport::Retried("report2"),
657 ObservedReport::Retried("report3")}));
631 658
632 // Do a final send. No reports should be sent. 659 // Do a final send. No reports should be sent.
633 service()->SendPending(); 660 service()->SendPending();
634 } 661 }
635 662
636 // A delayed report should successfully upload when it's resumed. 663 // A delayed report should successfully upload when it's resumed.
637 TEST_F(CertificateReportingServiceTest, Delayed_Resumed) { 664 TEST_F(CertificateReportingServiceTest, Delayed_Resumed) {
638 SetExpectedFailedReportCountOnTearDown(0); 665 SetExpectedFailedReportCountOnTearDown(0);
639 666
640 // Let reports hang. 667 // Let reports hang.
641 test_helper()->SetFailureMode( 668 test_helper()->SetFailureMode(
642 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); 669 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
643 // Send a report. The report upload hangs, so no error or success callbacks 670 // Send a report. The report upload hangs, so no error or success callbacks
644 // should be called. 671 // should be called.
645 service()->Send(MakeReport("report0")); 672 service()->Send(MakeReport("report0"));
646 673
647 // Resume the report upload and run the callbacks. The report should be 674 // Resume the report upload and run the callbacks. The report should be
648 // successfully sent. 675 // successfully sent.
649 test_helper()->ResumeDelayedRequest(); 676 test_helper()->ResumeDelayedRequest();
650 test_helper()->WaitForRequestsDestroyed( 677 test_helper()->WaitForRequestsDestroyed(
651 ReportExpectation::Delayed({"report0"})); 678 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
652 } 679 }
653 680
654 // Delayed reports should cleaned when the service is reset. 681 // Delayed reports should cleaned when the service is reset.
655 TEST_F(CertificateReportingServiceTest, Delayed_Reset) { 682 TEST_F(CertificateReportingServiceTest, Delayed_Reset) {
656 SetExpectedFailedReportCountOnTearDown(0); 683 SetExpectedFailedReportCountOnTearDown(0);
657 684
658 // Let reports hang. 685 // Let reports hang.
659 test_helper()->SetFailureMode( 686 test_helper()->SetFailureMode(
660 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); 687 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
661 // Send a report. The report is triggered but hangs, so no error or success 688 // Send a report. The report is triggered but hangs, so no error or success
(...skipping 13 matching lines...) Expand all
675 SetServiceEnabledAndWait(true); 702 SetServiceEnabledAndWait(true);
676 703
677 // Send a report. The report is triggered but hangs, so no error or success 704 // Send a report. The report is triggered but hangs, so no error or success
678 // callbacks should be called. The report id is again 0 since the pending 705 // callbacks should be called. The report id is again 0 since the pending
679 // report queue has been cleared above. 706 // report queue has been cleared above.
680 service()->Send(MakeReport("report1")); 707 service()->Send(MakeReport("report1"));
681 708
682 // Resume delayed report. Two reports are successfully sent. 709 // Resume delayed report. Two reports are successfully sent.
683 test_helper()->ResumeDelayedRequest(); 710 test_helper()->ResumeDelayedRequest();
684 test_helper()->WaitForRequestsDestroyed( 711 test_helper()->WaitForRequestsDestroyed(
685 ReportExpectation::Delayed({"report0", "report1"})); 712 ReportExpectation::Delayed({ObservedReport::NotRetried("report0"),
713 ObservedReport::NotRetried("report1")}));
686 } 714 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698