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

Side by Side Diff: chrome/browser/safe_browsing/certificate_reporting_service_browsertest.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 "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 19 matching lines...) Expand all
30 #include "net/dns/mock_host_resolver.h" 30 #include "net/dns/mock_host_resolver.h"
31 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
32 #include "net/url_request/report_sender.h" 32 #include "net/url_request/report_sender.h"
33 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
34 #include "net/url_request/url_request_filter.h" 34 #include "net/url_request/url_request_filter.h"
35 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
36 #include "url/scheme_host_port.h" 36 #include "url/scheme_host_port.h"
37 37
38 using certificate_reporting_test_utils::CertificateReportingServiceTestHelper; 38 using certificate_reporting_test_utils::CertificateReportingServiceTestHelper;
39 using certificate_reporting_test_utils::CertificateReportingServiceObserver; 39 using certificate_reporting_test_utils::CertificateReportingServiceObserver;
40 using certificate_reporting_test_utils::ObservedReport;
40 using certificate_reporting_test_utils::ReportExpectation; 41 using certificate_reporting_test_utils::ReportExpectation;
41 42
42 namespace { 43 namespace {
43 44
44 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; 45 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure";
45 46
46 void CleanUpOnIOThread() { 47 void CleanUpOnIOThread() {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
48 net::URLRequestFilter::GetInstance()->ClearHandlers(); 49 net::URLRequestFilter::GetInstance()->ClearHandlers();
49 } 50 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 certificate_reporting_test_utils::SetCertReportingOptIn( 228 certificate_reporting_test_utils::SetCertReportingOptIn(
228 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 229 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
229 230
230 // Let reports uploads successfully complete. 231 // Let reports uploads successfully complete.
231 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 232 test_helper()->SetFailureMode(certificate_reporting_test_utils::
232 ReportSendingResult::REPORTS_SUCCESSFUL); 233 ReportSendingResult::REPORTS_SUCCESSFUL);
233 234
234 // Reporting is opted in, so the report should succeed. 235 // Reporting is opted in, so the report should succeed.
235 SendReport("report0"); 236 SendReport("report0");
236 test_helper()->WaitForRequestsDestroyed( 237 test_helper()->WaitForRequestsDestroyed(
237 ReportExpectation::Successful({"report0"})); 238 ReportExpectation::Successful({ObservedReport::NotRetried("report0")}));
238 } 239 }
239 240
240 // Tests that report send attempts are not cancelled when extended reporting is 241 // Tests that report send attempts are not cancelled when extended reporting is
241 // opted in. Goes to an interstitial page and navigate away to force a report 242 // opted in. Goes to an interstitial page and navigate away to force a report
242 // send event. Repeats this three times and checks expected number of reports. 243 // send event. Repeats this three times and checks expected number of reports.
243 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, 244 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
244 OptedIn_ShouldQueueFailedReport) { 245 OptedIn_ShouldQueueFailedReport) {
245 SetExpectedHistogramCountOnTeardown(2); 246 SetExpectedHistogramCountOnTeardown(2);
246 247
247 certificate_reporting_test_utils::SetCertReportingOptIn( 248 certificate_reporting_test_utils::SetCertReportingOptIn(
248 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 249 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
249 // Let all reports fail. 250 // Let all reports fail.
250 test_helper()->SetFailureMode( 251 test_helper()->SetFailureMode(
251 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 252 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
252 253
253 // Send a failed report. 254 // Send a failed report.
254 SendReport("report0"); 255 SendReport("report0");
255 test_helper()->WaitForRequestsDestroyed( 256 test_helper()->WaitForRequestsDestroyed(
256 ReportExpectation::Failed({"report0"})); 257 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
257 258
258 // Send another failed report. 259 // Send another failed report.
259 SendReport("report1"); 260 SendReport("report1");
260 test_helper()->WaitForRequestsDestroyed( 261 test_helper()->WaitForRequestsDestroyed(
261 ReportExpectation::Failed({"report1"})); 262 ReportExpectation::Failed({ObservedReport::NotRetried("report1")}));
262 263
263 // Let all report uploads complete successfully now. 264 // Let all report uploads complete successfully now.
264 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 265 test_helper()->SetFailureMode(certificate_reporting_test_utils::
265 ReportSendingResult::REPORTS_SUCCESSFUL); 266 ReportSendingResult::REPORTS_SUCCESSFUL);
266 267
267 // Send another report. This time the report should be successfully sent. 268 // Send another report. This time the report should be successfully sent.
268 SendReport("report2"); 269 SendReport("report2");
269 test_helper()->WaitForRequestsDestroyed( 270 test_helper()->WaitForRequestsDestroyed(
270 ReportExpectation::Successful({"report2"})); 271 ReportExpectation::Successful({ObservedReport::NotRetried("report2")}));
271 272
272 // Send all pending reports. The two previously failed reports should have 273 // Send all pending reports. The two previously failed reports should have
273 // been queued, and now be sent successfully. 274 // been queued, and now be sent successfully.
274 SendPendingReports(); 275 SendPendingReports();
275 test_helper()->WaitForRequestsDestroyed( 276 test_helper()->WaitForRequestsDestroyed(
276 ReportExpectation::Successful({"report0", "report1"})); 277 ReportExpectation::Successful({ObservedReport::NotRetried("report0"),
278 ObservedReport::NotRetried("report1")}));
277 279
278 // Try sending pending reports again. Since there is no pending report, 280 // Try sending pending reports again. Since there is no pending report,
279 // nothing should be sent this time. If any report is sent, test teardown 281 // nothing should be sent this time. If any report is sent, test teardown
280 // will catch it. 282 // will catch it.
281 SendPendingReports(); 283 SendPendingReports();
282 } 284 }
283 285
284 // Opting in then opting out of extended reporting should clear the pending 286 // Opting in then opting out of extended reporting should clear the pending
285 // report queue. 287 // report queue.
286 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, 288 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
287 OptedIn_ThenOptedOut) { 289 OptedIn_ThenOptedOut) {
288 SetExpectedHistogramCountOnTeardown(1); 290 SetExpectedHistogramCountOnTeardown(1);
289 291
290 certificate_reporting_test_utils::SetCertReportingOptIn( 292 certificate_reporting_test_utils::SetCertReportingOptIn(
291 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 293 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
292 // Let all reports fail. 294 // Let all reports fail.
293 test_helper()->SetFailureMode( 295 test_helper()->SetFailureMode(
294 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 296 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
295 297
296 // Send a failed report. 298 // Send a failed report.
297 SendReport("report0"); 299 SendReport("report0");
298 test_helper()->WaitForRequestsDestroyed( 300 test_helper()->WaitForRequestsDestroyed(
299 ReportExpectation::Failed({"report0"})); 301 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
300 302
301 // Disable reporting. This should clear all pending reports. 303 // Disable reporting. This should clear all pending reports.
302 ChangeOptInAndWait( 304 ChangeOptInAndWait(
303 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); 305 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
304 306
305 // Send pending reports. No reports should be observed during test teardown. 307 // Send pending reports. No reports should be observed during test teardown.
306 SendPendingReports(); 308 SendPendingReports();
307 } 309 }
308 310
309 // Opting out, then in, then out of extended reporting should work as expected. 311 // Opting out, then in, then out of extended reporting should work as expected.
(...skipping 12 matching lines...) Expand all
322 SendReport("no-report"); 324 SendReport("no-report");
323 test_helper()->ExpectNoRequests(service()); 325 test_helper()->ExpectNoRequests(service());
324 326
325 // Enable reporting. 327 // Enable reporting.
326 ChangeOptInAndWait( 328 ChangeOptInAndWait(
327 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 329 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
328 330
329 // A failed report should be observed. 331 // A failed report should be observed.
330 SendReport("report0"); 332 SendReport("report0");
331 test_helper()->WaitForRequestsDestroyed( 333 test_helper()->WaitForRequestsDestroyed(
332 ReportExpectation::Failed({"report0"})); 334 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
333 335
334 // Disable reporting. This should reset the reporting service and 336 // Disable reporting. This should reset the reporting service and
335 // clear all pending reports. 337 // clear all pending reports.
336 ChangeOptInAndWait( 338 ChangeOptInAndWait(
337 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); 339 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
338 340
339 // Report should be cancelled since reporting is opted out. 341 // Report should be cancelled since reporting is opted out.
340 SendReport("report1"); 342 SendReport("report1");
341 test_helper()->ExpectNoRequests(service()); 343 test_helper()->ExpectNoRequests(service());
342 344
(...skipping 10 matching lines...) Expand all
353 355
354 certificate_reporting_test_utils::SetCertReportingOptIn( 356 certificate_reporting_test_utils::SetCertReportingOptIn(
355 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 357 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
356 // Let all reports fail. 358 // Let all reports fail.
357 test_helper()->SetFailureMode( 359 test_helper()->SetFailureMode(
358 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 360 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
359 361
360 // Send a delayed report. 362 // Send a delayed report.
361 SendReport("report0"); 363 SendReport("report0");
362 test_helper()->WaitForRequestsDestroyed( 364 test_helper()->WaitForRequestsDestroyed(
363 ReportExpectation::Failed({"report0"})); 365 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
364 366
365 // Disable SafeBrowsing. This should clear all pending reports. 367 // Disable SafeBrowsing. This should clear all pending reports.
366 ToggleSafeBrowsingAndWaitForServiceReset(false); 368 ToggleSafeBrowsingAndWaitForServiceReset(false);
367 369
368 // Send pending reports. No reports should be observed. 370 // Send pending reports. No reports should be observed.
369 SendPendingReports(); 371 SendPendingReports();
370 test_helper()->ExpectNoRequests(service()); 372 test_helper()->ExpectNoRequests(service());
371 373
372 // Re-enable SafeBrowsing and trigger another report which will be queued. 374 // Re-enable SafeBrowsing and trigger another report which will be queued.
373 ToggleSafeBrowsingAndWaitForServiceReset(true); 375 ToggleSafeBrowsingAndWaitForServiceReset(true);
374 SendReport("report1"); 376 SendReport("report1");
375 test_helper()->WaitForRequestsDestroyed( 377 test_helper()->WaitForRequestsDestroyed(
376 ReportExpectation::Failed({"report1"})); 378 ReportExpectation::Failed({ObservedReport::NotRetried("report1")}));
377 379
378 // Queued report should now be successfully sent. 380 // Queued report should now be successfully sent.
379 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 381 test_helper()->SetFailureMode(certificate_reporting_test_utils::
380 ReportSendingResult::REPORTS_SUCCESSFUL); 382 ReportSendingResult::REPORTS_SUCCESSFUL);
381 SendPendingReports(); 383 SendPendingReports();
382 test_helper()->WaitForRequestsDestroyed( 384 test_helper()->WaitForRequestsDestroyed(
383 ReportExpectation::Successful({"report1"})); 385 ReportExpectation::Successful({ObservedReport::Retried("report1")}));
384 } 386 }
385 387
386 // CertificateReportingService should ignore reports older than the report TTL. 388 // CertificateReportingService should ignore reports older than the report TTL.
387 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, 389 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
388 DontSendOldReports) { 390 DontSendOldReports) {
389 SetExpectedHistogramCountOnTeardown(5); 391 SetExpectedHistogramCountOnTeardown(5);
390 392
391 base::SimpleTestClock* clock = new base::SimpleTestClock(); 393 base::SimpleTestClock* clock = new base::SimpleTestClock();
392 base::Time reference_time = base::Time::Now(); 394 base::Time reference_time = base::Time::Now();
393 clock->SetNow(reference_time); 395 clock->SetNow(reference_time);
394 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock)); 396 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock));
395 397
396 // The service should ignore reports older than 24 hours. 398 // The service should ignore reports older than 24 hours.
397 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24)); 399 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24));
398 400
399 certificate_reporting_test_utils::SetCertReportingOptIn( 401 certificate_reporting_test_utils::SetCertReportingOptIn(
400 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 402 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
401 403
402 // Let all reports fail. 404 // Let all reports fail.
403 test_helper()->SetFailureMode( 405 test_helper()->SetFailureMode(
404 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 406 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
405 407
406 // Send a failed report. 408 // Send a failed report.
407 SendReport("report0"); 409 SendReport("report0");
408 test_helper()->WaitForRequestsDestroyed( 410 test_helper()->WaitForRequestsDestroyed(
409 ReportExpectation::Failed({"report0"})); 411 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
410 412
411 // Advance the clock a bit and trigger another failed report. 413 // Advance the clock a bit and trigger another failed report.
412 clock->Advance(base::TimeDelta::FromHours(5)); 414 clock->Advance(base::TimeDelta::FromHours(5));
413 SendReport("report1"); 415 SendReport("report1");
414 test_helper()->WaitForRequestsDestroyed( 416 test_helper()->WaitForRequestsDestroyed(
415 ReportExpectation::Failed({"report1"})); 417 ReportExpectation::Failed({ObservedReport::NotRetried("report1")}));
416 418
417 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference 419 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference
418 // time. This makes report0 older than 24 hours. report1 is now 20 hours. 420 // time. This makes report0 older than 24 hours. report1 is now 20 hours.
419 clock->Advance(base::TimeDelta::FromHours(20)); 421 clock->Advance(base::TimeDelta::FromHours(20));
420 422
421 // Send pending reports. report0 should be discarded since it's too old. 423 // Send pending reports. report0 should be discarded since it's too old.
422 // report1 should be queued again. 424 // report1 should be queued again.
423 SendPendingReports(); 425 SendPendingReports();
424 test_helper()->WaitForRequestsDestroyed( 426 test_helper()->WaitForRequestsDestroyed(
425 ReportExpectation::Failed({"report1"})); 427 ReportExpectation::Failed({ObservedReport::Retried("report1")}));
426 428
427 // Trigger another failed report. 429 // Trigger another failed report.
428 SendReport("report2"); 430 SendReport("report2");
429 test_helper()->WaitForRequestsDestroyed( 431 test_helper()->WaitForRequestsDestroyed(
430 ReportExpectation::Failed({"report2"})); 432 ReportExpectation::Failed({ObservedReport::NotRetried("report2")}));
431 433
432 // Advance the clock 5 hours. report1 will now be 25 hours old. 434 // Advance the clock 5 hours. report1 will now be 25 hours old.
433 clock->Advance(base::TimeDelta::FromHours(5)); 435 clock->Advance(base::TimeDelta::FromHours(5));
434 436
435 // Send pending reports. report1 should be discarded since it's too old. 437 // Send pending reports. report1 should be discarded since it's too old.
436 // report2 should be queued again. 438 // report2 should be queued again.
437 SendPendingReports(); 439 SendPendingReports();
438 test_helper()->WaitForRequestsDestroyed( 440 test_helper()->WaitForRequestsDestroyed(
439 ReportExpectation::Failed({"report2"})); 441 ReportExpectation::Failed({ObservedReport::Retried("report2")}));
440 442
441 // Advance the clock 20 hours again so that report2 is 25 hours old and is 443 // Advance the clock 20 hours again so that report2 is 25 hours old and is
442 // older than max age (24 hours). 444 // older than max age (24 hours).
443 clock->Advance(base::TimeDelta::FromHours(20)); 445 clock->Advance(base::TimeDelta::FromHours(20));
444 446
445 // Send pending reports. report2 should be discarded since it's too old. No 447 // Send pending reports. report2 should be discarded since it's too old. No
446 // other reports remain. If any report is sent, test teardown will catch it. 448 // other reports remain. If any report is sent, test teardown will catch it.
447 SendPendingReports(); 449 SendPendingReports();
448 } 450 }
449 451
(...skipping 16 matching lines...) Expand all
466 certificate_reporting_test_utils::SetCertReportingOptIn( 468 certificate_reporting_test_utils::SetCertReportingOptIn(
467 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 469 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
468 470
469 // Let all reports fail. 471 // Let all reports fail.
470 test_helper()->SetFailureMode( 472 test_helper()->SetFailureMode(
471 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); 473 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
472 474
473 // Trigger a failed report. 475 // Trigger a failed report.
474 SendReport("report0"); 476 SendReport("report0");
475 test_helper()->WaitForRequestsDestroyed( 477 test_helper()->WaitForRequestsDestroyed(
476 ReportExpectation::Failed({"report0"})); 478 ReportExpectation::Failed({ObservedReport::NotRetried("report0")}));
477 479
478 // Trigger three more reports within five hours of each other. After this: 480 // Trigger three more reports within five hours of each other. After this:
479 // report0 is 0 hours after reference time (15 hours old). 481 // report0 is 0 hours after reference time (15 hours old).
480 // report1 is 5 hours after reference time (10 hours old). 482 // report1 is 5 hours after reference time (10 hours old).
481 // report2 is 10 hours after reference time (5 hours old). 483 // report2 is 10 hours after reference time (5 hours old).
482 // report3 is 15 hours after reference time (0 hours old). 484 // report3 is 15 hours after reference time (0 hours old).
483 clock->Advance(base::TimeDelta::FromHours(5)); 485 clock->Advance(base::TimeDelta::FromHours(5));
484 SendReport("report1"); 486 SendReport("report1");
485 487
486 clock->Advance(base::TimeDelta::FromHours(5)); 488 clock->Advance(base::TimeDelta::FromHours(5));
487 SendReport("report2"); 489 SendReport("report2");
488 490
489 clock->Advance(base::TimeDelta::FromHours(5)); 491 clock->Advance(base::TimeDelta::FromHours(5));
490 SendReport("report3"); 492 SendReport("report3");
491 493
492 test_helper()->WaitForRequestsDestroyed( 494 test_helper()->WaitForRequestsDestroyed(
493 ReportExpectation::Failed({"report1", "report2", "report3"})); 495 ReportExpectation::Failed({ObservedReport::NotRetried("report1"),
496 ObservedReport::NotRetried("report2"),
497 ObservedReport::NotRetried("report3")}));
494 498
495 // Send pending reports. Four reports were generated above, but the service 499 // Send pending reports. Four reports were generated above, but the service
496 // only queues three reports, so report0 should be dropped since it's the 500 // only queues three reports, so report0 should be dropped since it's the
497 // oldest. 501 // oldest.
498 SendPendingReports(); 502 SendPendingReports();
499 test_helper()->WaitForRequestsDestroyed( 503 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Failed(
500 ReportExpectation::Failed({"report1", "report2", "report3"})); 504 {ObservedReport::Retried("report1"), ObservedReport::Retried("report2"),
505 ObservedReport::Retried("report3")}));
501 506
502 // Let all reports succeed. 507 // Let all reports succeed.
503 test_helper()->SetFailureMode(certificate_reporting_test_utils:: 508 test_helper()->SetFailureMode(certificate_reporting_test_utils::
504 ReportSendingResult::REPORTS_SUCCESSFUL); 509 ReportSendingResult::REPORTS_SUCCESSFUL);
505 510
506 // Advance the clock 15 hours. Current time is now 30 hours after reference 511 // Advance the clock 15 hours. Current time is now 30 hours after reference
507 // time, and the ages of reports are now as follows: 512 // time, and the ages of reports are now as follows:
508 // report1 is 25 hours old. 513 // report1 is 25 hours old.
509 // report2 is 20 hours old. 514 // report2 is 20 hours old.
510 // report3 is 15 hours old. 515 // report3 is 15 hours old.
511 clock->Advance(base::TimeDelta::FromHours(15)); 516 clock->Advance(base::TimeDelta::FromHours(15));
512 517
513 // Send pending reports. Only reports 2 and 3 should be sent, report 1 518 // Send pending reports. Only reports 2 and 3 should be sent, report 1
514 // should be ignored because it's too old. 519 // should be ignored because it's too old.
515 SendPendingReports(); 520 SendPendingReports();
516 test_helper()->WaitForRequestsDestroyed( 521 test_helper()->WaitForRequestsDestroyed(
517 ReportExpectation::Successful({"report2", "report3"})); 522 ReportExpectation::Successful({ObservedReport::Retried("report2"),
523 ObservedReport::Retried("report3")}));
518 } 524 }
519 525
520 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, 526 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
521 Delayed_Resumed) { 527 Delayed_Resumed) {
522 SetExpectedHistogramCountOnTeardown(0); 528 SetExpectedHistogramCountOnTeardown(0);
523 529
524 certificate_reporting_test_utils::SetCertReportingOptIn( 530 certificate_reporting_test_utils::SetCertReportingOptIn(
525 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 531 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
526 // Let all reports hang. 532 // Let all reports hang.
527 test_helper()->SetFailureMode( 533 test_helper()->SetFailureMode(
528 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); 534 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
529 535
530 // Trigger a report that hangs. 536 // Trigger a report that hangs.
531 SendReport("report0"); 537 SendReport("report0");
532 test_helper()->WaitForRequestsCreated( 538 test_helper()->WaitForRequestsCreated(
533 ReportExpectation::Delayed({"report0"})); 539 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
534 540
535 // Resume the report upload. The report upload should successfully complete. 541 // Resume the report upload. The report upload should successfully complete.
536 // The interceptor only observes request creations and not response 542 // The interceptor only observes request creations and not response
537 // completions, so there is nothing to observe. 543 // completions, so there is nothing to observe.
538 test_helper()->ResumeDelayedRequest(); 544 test_helper()->ResumeDelayedRequest();
539 test_helper()->WaitForRequestsDestroyed( 545 test_helper()->WaitForRequestsDestroyed(
540 ReportExpectation::Delayed({"report0"})); 546 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
541 } 547 }
542 548
543 // Same as above, but the service is shut down before resuming the delayed 549 // Same as above, but the service is shut down before resuming the delayed
544 // request. Should not crash. 550 // request. Should not crash.
545 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, 551 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
546 Delayed_Resumed_ServiceShutdown) { 552 Delayed_Resumed_ServiceShutdown) {
547 SetExpectedHistogramCountOnTeardown(0); 553 SetExpectedHistogramCountOnTeardown(0);
548 554
549 certificate_reporting_test_utils::SetCertReportingOptIn( 555 certificate_reporting_test_utils::SetCertReportingOptIn(
550 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 556 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
551 // Let all reports hang. 557 // Let all reports hang.
552 test_helper()->SetFailureMode( 558 test_helper()->SetFailureMode(
553 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); 559 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
554 560
555 // Trigger a report that hangs. 561 // Trigger a report that hangs.
556 SendReport("report0"); 562 SendReport("report0");
557 test_helper()->WaitForRequestsCreated( 563 test_helper()->WaitForRequestsCreated(
558 ReportExpectation::Delayed({"report0"})); 564 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
559 565
560 // Shutdown the service and resume the report upload. Shouldn't crash. 566 // Shutdown the service and resume the report upload. Shouldn't crash.
561 service()->Shutdown(); 567 service()->Shutdown();
562 test_helper()->ResumeDelayedRequest(); 568 test_helper()->ResumeDelayedRequest();
563 test_helper()->WaitForRequestsDestroyed( 569 test_helper()->WaitForRequestsDestroyed(
564 ReportExpectation::Delayed({"report0"})); 570 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
565 } 571 }
566 572
567 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting 573 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting
568 // service should clear its in-flight reports list. 574 // service should clear its in-flight reports list.
569 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { 575 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) {
570 SetExpectedHistogramCountOnTeardown(0); 576 SetExpectedHistogramCountOnTeardown(0);
571 577
572 certificate_reporting_test_utils::SetCertReportingOptIn( 578 certificate_reporting_test_utils::SetCertReportingOptIn(
573 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); 579 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
574 // Let all reports hang. 580 // Let all reports hang.
575 test_helper()->SetFailureMode( 581 test_helper()->SetFailureMode(
576 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); 582 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
577 583
578 // Trigger a report that hangs. 584 // Trigger a report that hangs.
579 SendReport("report0"); 585 SendReport("report0");
580 test_helper()->WaitForRequestsCreated( 586 test_helper()->WaitForRequestsCreated(
581 ReportExpectation::Delayed({"report0"})); 587 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
582 588
583 // Disable SafeBrowsing. This should clear all pending reports. 589 // Disable SafeBrowsing. This should clear all pending reports.
584 ToggleSafeBrowsingAndWaitForServiceReset(false); 590 ToggleSafeBrowsingAndWaitForServiceReset(false);
585 test_helper()->WaitForRequestsDestroyed( 591 test_helper()->WaitForRequestsDestroyed(
586 ReportExpectation::Delayed({"report0"})); 592 ReportExpectation::Delayed({ObservedReport::NotRetried("report0")}));
587 593
588 // Resume delayed report. No response should be observed since all pending 594 // Resume delayed report. No response should be observed since all pending
589 // reports should be cleared. 595 // reports should be cleared.
590 test_helper()->ResumeDelayedRequest(); 596 test_helper()->ResumeDelayedRequest();
591 test_helper()->ExpectNoRequests(service()); 597 test_helper()->ExpectNoRequests(service());
592 598
593 // Re-enable SafeBrowsing. 599 // Re-enable SafeBrowsing.
594 ToggleSafeBrowsingAndWaitForServiceReset(true); 600 ToggleSafeBrowsingAndWaitForServiceReset(true);
595 601
596 // Trigger a report that hangs. 602 // Trigger a report that hangs.
597 SendReport("report1"); 603 SendReport("report1");
598 test_helper()->WaitForRequestsCreated( 604 test_helper()->WaitForRequestsCreated(
599 ReportExpectation::Delayed({"report1"})); 605 ReportExpectation::Delayed({ObservedReport::NotRetried("report1")}));
600 606
601 // Resume the delayed report and wait for it to complete. 607 // Resume the delayed report and wait for it to complete.
602 test_helper()->ResumeDelayedRequest(); 608 test_helper()->ResumeDelayedRequest();
603 test_helper()->WaitForRequestsDestroyed( 609 test_helper()->WaitForRequestsDestroyed(
604 ReportExpectation::Delayed({"report1"})); 610 ReportExpectation::Delayed({ObservedReport::NotRetried("report1")}));
605 } 611 }
606 612
607 } // namespace safe_browsing 613 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698