| OLD | NEW |
| 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 20 matching lines...) Expand all Loading... |
| 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::ReportExpectation; | 40 using certificate_reporting_test_utils::ReportExpectation; |
| 41 using certificate_reporting_test_utils::RetryStatus; |
| 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 } |
| 50 | 51 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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({{"report0", RetryStatus::NOT_RETRIED}})); |
| 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({{"report0", RetryStatus::NOT_RETRIED}})); |
| 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({{"report1", RetryStatus::NOT_RETRIED}})); |
| 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({{"report2", RetryStatus::NOT_RETRIED}})); |
| 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(ReportExpectation::Successful( |
| 276 ReportExpectation::Successful({"report0", "report1"})); | 277 {{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}})); |
| 277 | 278 |
| 278 // Try sending pending reports again. Since there is no pending report, | 279 // 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 | 280 // nothing should be sent this time. If any report is sent, test teardown |
| 280 // will catch it. | 281 // will catch it. |
| 281 SendPendingReports(); | 282 SendPendingReports(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 // Opting in then opting out of extended reporting should clear the pending | 285 // Opting in then opting out of extended reporting should clear the pending |
| 285 // report queue. | 286 // report queue. |
| 286 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 287 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 287 OptedIn_ThenOptedOut) { | 288 OptedIn_ThenOptedOut) { |
| 288 SetExpectedHistogramCountOnTeardown(1); | 289 SetExpectedHistogramCountOnTeardown(1); |
| 289 | 290 |
| 290 certificate_reporting_test_utils::SetCertReportingOptIn( | 291 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 291 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 292 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 292 // Let all reports fail. | 293 // Let all reports fail. |
| 293 test_helper()->SetFailureMode( | 294 test_helper()->SetFailureMode( |
| 294 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 295 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 295 | 296 |
| 296 // Send a failed report. | 297 // Send a failed report. |
| 297 SendReport("report0"); | 298 SendReport("report0"); |
| 298 test_helper()->WaitForRequestsDestroyed( | 299 test_helper()->WaitForRequestsDestroyed( |
| 299 ReportExpectation::Failed({"report0"})); | 300 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 300 | 301 |
| 301 // Disable reporting. This should clear all pending reports. | 302 // Disable reporting. This should clear all pending reports. |
| 302 ChangeOptInAndWait( | 303 ChangeOptInAndWait( |
| 303 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 304 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| 304 | 305 |
| 305 // Send pending reports. No reports should be observed during test teardown. | 306 // Send pending reports. No reports should be observed during test teardown. |
| 306 SendPendingReports(); | 307 SendPendingReports(); |
| 307 } | 308 } |
| 308 | 309 |
| 309 // Opting out, then in, then out of extended reporting should work as expected. | 310 // Opting out, then in, then out of extended reporting should work as expected. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 322 SendReport("no-report"); | 323 SendReport("no-report"); |
| 323 test_helper()->ExpectNoRequests(service()); | 324 test_helper()->ExpectNoRequests(service()); |
| 324 | 325 |
| 325 // Enable reporting. | 326 // Enable reporting. |
| 326 ChangeOptInAndWait( | 327 ChangeOptInAndWait( |
| 327 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 328 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 328 | 329 |
| 329 // A failed report should be observed. | 330 // A failed report should be observed. |
| 330 SendReport("report0"); | 331 SendReport("report0"); |
| 331 test_helper()->WaitForRequestsDestroyed( | 332 test_helper()->WaitForRequestsDestroyed( |
| 332 ReportExpectation::Failed({"report0"})); | 333 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 333 | 334 |
| 334 // Disable reporting. This should reset the reporting service and | 335 // Disable reporting. This should reset the reporting service and |
| 335 // clear all pending reports. | 336 // clear all pending reports. |
| 336 ChangeOptInAndWait( | 337 ChangeOptInAndWait( |
| 337 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 338 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| 338 | 339 |
| 339 // Report should be cancelled since reporting is opted out. | 340 // Report should be cancelled since reporting is opted out. |
| 340 SendReport("report1"); | 341 SendReport("report1"); |
| 341 test_helper()->ExpectNoRequests(service()); | 342 test_helper()->ExpectNoRequests(service()); |
| 342 | 343 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 353 | 354 |
| 354 certificate_reporting_test_utils::SetCertReportingOptIn( | 355 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 355 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 356 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 356 // Let all reports fail. | 357 // Let all reports fail. |
| 357 test_helper()->SetFailureMode( | 358 test_helper()->SetFailureMode( |
| 358 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 359 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 359 | 360 |
| 360 // Send a delayed report. | 361 // Send a delayed report. |
| 361 SendReport("report0"); | 362 SendReport("report0"); |
| 362 test_helper()->WaitForRequestsDestroyed( | 363 test_helper()->WaitForRequestsDestroyed( |
| 363 ReportExpectation::Failed({"report0"})); | 364 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 364 | 365 |
| 365 // Disable SafeBrowsing. This should clear all pending reports. | 366 // Disable SafeBrowsing. This should clear all pending reports. |
| 366 ToggleSafeBrowsingAndWaitForServiceReset(false); | 367 ToggleSafeBrowsingAndWaitForServiceReset(false); |
| 367 | 368 |
| 368 // Send pending reports. No reports should be observed. | 369 // Send pending reports. No reports should be observed. |
| 369 SendPendingReports(); | 370 SendPendingReports(); |
| 370 test_helper()->ExpectNoRequests(service()); | 371 test_helper()->ExpectNoRequests(service()); |
| 371 | 372 |
| 372 // Re-enable SafeBrowsing and trigger another report which will be queued. | 373 // Re-enable SafeBrowsing and trigger another report which will be queued. |
| 373 ToggleSafeBrowsingAndWaitForServiceReset(true); | 374 ToggleSafeBrowsingAndWaitForServiceReset(true); |
| 374 SendReport("report1"); | 375 SendReport("report1"); |
| 375 test_helper()->WaitForRequestsDestroyed( | 376 test_helper()->WaitForRequestsDestroyed( |
| 376 ReportExpectation::Failed({"report1"})); | 377 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 377 | 378 |
| 378 // Queued report should now be successfully sent. | 379 // Queued report should now be successfully sent. |
| 379 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 380 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
| 380 ReportSendingResult::REPORTS_SUCCESSFUL); | 381 ReportSendingResult::REPORTS_SUCCESSFUL); |
| 381 SendPendingReports(); | 382 SendPendingReports(); |
| 382 test_helper()->WaitForRequestsDestroyed( | 383 test_helper()->WaitForRequestsDestroyed( |
| 383 ReportExpectation::Successful({"report1"})); | 384 ReportExpectation::Successful({{"report1", RetryStatus::RETRIED}})); |
| 384 } | 385 } |
| 385 | 386 |
| 386 // CertificateReportingService should ignore reports older than the report TTL. | 387 // CertificateReportingService should ignore reports older than the report TTL. |
| 387 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 388 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 388 DontSendOldReports) { | 389 DontSendOldReports) { |
| 389 SetExpectedHistogramCountOnTeardown(5); | 390 SetExpectedHistogramCountOnTeardown(5); |
| 390 | 391 |
| 391 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 392 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
| 392 base::Time reference_time = base::Time::Now(); | 393 base::Time reference_time = base::Time::Now(); |
| 393 clock->SetNow(reference_time); | 394 clock->SetNow(reference_time); |
| 394 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock)); | 395 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock)); |
| 395 | 396 |
| 396 // The service should ignore reports older than 24 hours. | 397 // The service should ignore reports older than 24 hours. |
| 397 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24)); | 398 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24)); |
| 398 | 399 |
| 399 certificate_reporting_test_utils::SetCertReportingOptIn( | 400 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 400 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 401 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 401 | 402 |
| 402 // Let all reports fail. | 403 // Let all reports fail. |
| 403 test_helper()->SetFailureMode( | 404 test_helper()->SetFailureMode( |
| 404 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 405 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 405 | 406 |
| 406 // Send a failed report. | 407 // Send a failed report. |
| 407 SendReport("report0"); | 408 SendReport("report0"); |
| 408 test_helper()->WaitForRequestsDestroyed( | 409 test_helper()->WaitForRequestsDestroyed( |
| 409 ReportExpectation::Failed({"report0"})); | 410 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 410 | 411 |
| 411 // Advance the clock a bit and trigger another failed report. | 412 // Advance the clock a bit and trigger another failed report. |
| 412 clock->Advance(base::TimeDelta::FromHours(5)); | 413 clock->Advance(base::TimeDelta::FromHours(5)); |
| 413 SendReport("report1"); | 414 SendReport("report1"); |
| 414 test_helper()->WaitForRequestsDestroyed( | 415 test_helper()->WaitForRequestsDestroyed( |
| 415 ReportExpectation::Failed({"report1"})); | 416 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 416 | 417 |
| 417 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference | 418 // 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. | 419 // time. This makes report0 older than 24 hours. report1 is now 20 hours. |
| 419 clock->Advance(base::TimeDelta::FromHours(20)); | 420 clock->Advance(base::TimeDelta::FromHours(20)); |
| 420 | 421 |
| 421 // Send pending reports. report0 should be discarded since it's too old. | 422 // Send pending reports. report0 should be discarded since it's too old. |
| 422 // report1 should be queued again. | 423 // report1 should be queued again. |
| 423 SendPendingReports(); | 424 SendPendingReports(); |
| 424 test_helper()->WaitForRequestsDestroyed( | 425 test_helper()->WaitForRequestsDestroyed( |
| 425 ReportExpectation::Failed({"report1"})); | 426 ReportExpectation::Failed({{"report1", RetryStatus::RETRIED}})); |
| 426 | 427 |
| 427 // Trigger another failed report. | 428 // Trigger another failed report. |
| 428 SendReport("report2"); | 429 SendReport("report2"); |
| 429 test_helper()->WaitForRequestsDestroyed( | 430 test_helper()->WaitForRequestsDestroyed( |
| 430 ReportExpectation::Failed({"report2"})); | 431 ReportExpectation::Failed({{"report2", RetryStatus::NOT_RETRIED}})); |
| 431 | 432 |
| 432 // Advance the clock 5 hours. report1 will now be 25 hours old. | 433 // Advance the clock 5 hours. report1 will now be 25 hours old. |
| 433 clock->Advance(base::TimeDelta::FromHours(5)); | 434 clock->Advance(base::TimeDelta::FromHours(5)); |
| 434 | 435 |
| 435 // Send pending reports. report1 should be discarded since it's too old. | 436 // Send pending reports. report1 should be discarded since it's too old. |
| 436 // report2 should be queued again. | 437 // report2 should be queued again. |
| 437 SendPendingReports(); | 438 SendPendingReports(); |
| 438 test_helper()->WaitForRequestsDestroyed( | 439 test_helper()->WaitForRequestsDestroyed( |
| 439 ReportExpectation::Failed({"report2"})); | 440 ReportExpectation::Failed({{"report2", RetryStatus::RETRIED}})); |
| 440 | 441 |
| 441 // Advance the clock 20 hours again so that report2 is 25 hours old and is | 442 // Advance the clock 20 hours again so that report2 is 25 hours old and is |
| 442 // older than max age (24 hours). | 443 // older than max age (24 hours). |
| 443 clock->Advance(base::TimeDelta::FromHours(20)); | 444 clock->Advance(base::TimeDelta::FromHours(20)); |
| 444 | 445 |
| 445 // Send pending reports. report2 should be discarded since it's too old. No | 446 // 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. | 447 // other reports remain. If any report is sent, test teardown will catch it. |
| 447 SendPendingReports(); | 448 SendPendingReports(); |
| 448 } | 449 } |
| 449 | 450 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 466 certificate_reporting_test_utils::SetCertReportingOptIn( | 467 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 467 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 468 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 468 | 469 |
| 469 // Let all reports fail. | 470 // Let all reports fail. |
| 470 test_helper()->SetFailureMode( | 471 test_helper()->SetFailureMode( |
| 471 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 472 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 472 | 473 |
| 473 // Trigger a failed report. | 474 // Trigger a failed report. |
| 474 SendReport("report0"); | 475 SendReport("report0"); |
| 475 test_helper()->WaitForRequestsDestroyed( | 476 test_helper()->WaitForRequestsDestroyed( |
| 476 ReportExpectation::Failed({"report0"})); | 477 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 477 | 478 |
| 478 // Trigger three more reports within five hours of each other. After this: | 479 // Trigger three more reports within five hours of each other. After this: |
| 479 // report0 is 0 hours after reference time (15 hours old). | 480 // report0 is 0 hours after reference time (15 hours old). |
| 480 // report1 is 5 hours after reference time (10 hours old). | 481 // report1 is 5 hours after reference time (10 hours old). |
| 481 // report2 is 10 hours after reference time (5 hours old). | 482 // report2 is 10 hours after reference time (5 hours old). |
| 482 // report3 is 15 hours after reference time (0 hours old). | 483 // report3 is 15 hours after reference time (0 hours old). |
| 483 clock->Advance(base::TimeDelta::FromHours(5)); | 484 clock->Advance(base::TimeDelta::FromHours(5)); |
| 484 SendReport("report1"); | 485 SendReport("report1"); |
| 485 | 486 |
| 486 clock->Advance(base::TimeDelta::FromHours(5)); | 487 clock->Advance(base::TimeDelta::FromHours(5)); |
| 487 SendReport("report2"); | 488 SendReport("report2"); |
| 488 | 489 |
| 489 clock->Advance(base::TimeDelta::FromHours(5)); | 490 clock->Advance(base::TimeDelta::FromHours(5)); |
| 490 SendReport("report3"); | 491 SendReport("report3"); |
| 491 | 492 |
| 492 test_helper()->WaitForRequestsDestroyed( | 493 test_helper()->WaitForRequestsDestroyed( |
| 493 ReportExpectation::Failed({"report1", "report2", "report3"})); | 494 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}, |
| 495 {"report2", RetryStatus::NOT_RETRIED}, |
| 496 {"report3", RetryStatus::NOT_RETRIED}})); |
| 494 | 497 |
| 495 // Send pending reports. Four reports were generated above, but the service | 498 // 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 | 499 // only queues three reports, so report0 should be dropped since it's the |
| 497 // oldest. | 500 // oldest. |
| 498 SendPendingReports(); | 501 SendPendingReports(); |
| 499 test_helper()->WaitForRequestsDestroyed( | 502 test_helper()->WaitForRequestsDestroyed( |
| 500 ReportExpectation::Failed({"report1", "report2", "report3"})); | 503 ReportExpectation::Failed({{"report1", RetryStatus::RETRIED}, |
| 504 {"report2", RetryStatus::RETRIED}, |
| 505 {"report3", RetryStatus::RETRIED}})); |
| 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(ReportExpectation::Successful( |
| 517 ReportExpectation::Successful({"report2", "report3"})); | 522 {{"report2", RetryStatus::RETRIED}, {"report3", RetryStatus::RETRIED}})); |
| 518 } | 523 } |
| 519 | 524 |
| 520 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 525 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 521 Delayed_Resumed) { | 526 Delayed_Resumed) { |
| 522 SetExpectedHistogramCountOnTeardown(0); | 527 SetExpectedHistogramCountOnTeardown(0); |
| 523 | 528 |
| 524 certificate_reporting_test_utils::SetCertReportingOptIn( | 529 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 525 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 530 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 526 // Let all reports hang. | 531 // Let all reports hang. |
| 527 test_helper()->SetFailureMode( | 532 test_helper()->SetFailureMode( |
| 528 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 533 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| 529 | 534 |
| 530 // Trigger a report that hangs. | 535 // Trigger a report that hangs. |
| 531 SendReport("report0"); | 536 SendReport("report0"); |
| 532 test_helper()->WaitForRequestsCreated( | 537 test_helper()->WaitForRequestsCreated( |
| 533 ReportExpectation::Delayed({"report0"})); | 538 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 534 | 539 |
| 535 // Resume the report upload. The report upload should successfully complete. | 540 // Resume the report upload. The report upload should successfully complete. |
| 536 // The interceptor only observes request creations and not response | 541 // The interceptor only observes request creations and not response |
| 537 // completions, so there is nothing to observe. | 542 // completions, so there is nothing to observe. |
| 538 test_helper()->ResumeDelayedRequest(); | 543 test_helper()->ResumeDelayedRequest(); |
| 539 test_helper()->WaitForRequestsDestroyed( | 544 test_helper()->WaitForRequestsDestroyed( |
| 540 ReportExpectation::Delayed({"report0"})); | 545 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 541 } | 546 } |
| 542 | 547 |
| 543 // Same as above, but the service is shut down before resuming the delayed | 548 // Same as above, but the service is shut down before resuming the delayed |
| 544 // request. Should not crash. | 549 // request. Should not crash. |
| 545 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 550 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 546 Delayed_Resumed_ServiceShutdown) { | 551 Delayed_Resumed_ServiceShutdown) { |
| 547 SetExpectedHistogramCountOnTeardown(0); | 552 SetExpectedHistogramCountOnTeardown(0); |
| 548 | 553 |
| 549 certificate_reporting_test_utils::SetCertReportingOptIn( | 554 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 550 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 555 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 551 // Let all reports hang. | 556 // Let all reports hang. |
| 552 test_helper()->SetFailureMode( | 557 test_helper()->SetFailureMode( |
| 553 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 558 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| 554 | 559 |
| 555 // Trigger a report that hangs. | 560 // Trigger a report that hangs. |
| 556 SendReport("report0"); | 561 SendReport("report0"); |
| 557 test_helper()->WaitForRequestsCreated( | 562 test_helper()->WaitForRequestsCreated( |
| 558 ReportExpectation::Delayed({"report0"})); | 563 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 559 | 564 |
| 560 // Shutdown the service and resume the report upload. Shouldn't crash. | 565 // Shutdown the service and resume the report upload. Shouldn't crash. |
| 561 service()->Shutdown(); | 566 service()->Shutdown(); |
| 562 test_helper()->ResumeDelayedRequest(); | 567 test_helper()->ResumeDelayedRequest(); |
| 563 test_helper()->WaitForRequestsDestroyed( | 568 test_helper()->WaitForRequestsDestroyed( |
| 564 ReportExpectation::Delayed({"report0"})); | 569 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 565 } | 570 } |
| 566 | 571 |
| 567 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting | 572 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting |
| 568 // service should clear its in-flight reports list. | 573 // service should clear its in-flight reports list. |
| 569 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { | 574 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { |
| 570 SetExpectedHistogramCountOnTeardown(0); | 575 SetExpectedHistogramCountOnTeardown(0); |
| 571 | 576 |
| 572 certificate_reporting_test_utils::SetCertReportingOptIn( | 577 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 573 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 578 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 574 // Let all reports hang. | 579 // Let all reports hang. |
| 575 test_helper()->SetFailureMode( | 580 test_helper()->SetFailureMode( |
| 576 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 581 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| 577 | 582 |
| 578 // Trigger a report that hangs. | 583 // Trigger a report that hangs. |
| 579 SendReport("report0"); | 584 SendReport("report0"); |
| 580 test_helper()->WaitForRequestsCreated( | 585 test_helper()->WaitForRequestsCreated( |
| 581 ReportExpectation::Delayed({"report0"})); | 586 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 582 | 587 |
| 583 // Disable SafeBrowsing. This should clear all pending reports. | 588 // Disable SafeBrowsing. This should clear all pending reports. |
| 584 ToggleSafeBrowsingAndWaitForServiceReset(false); | 589 ToggleSafeBrowsingAndWaitForServiceReset(false); |
| 585 test_helper()->WaitForRequestsDestroyed( | 590 test_helper()->WaitForRequestsDestroyed( |
| 586 ReportExpectation::Delayed({"report0"})); | 591 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 587 | 592 |
| 588 // Resume delayed report. No response should be observed since all pending | 593 // Resume delayed report. No response should be observed since all pending |
| 589 // reports should be cleared. | 594 // reports should be cleared. |
| 590 test_helper()->ResumeDelayedRequest(); | 595 test_helper()->ResumeDelayedRequest(); |
| 591 test_helper()->ExpectNoRequests(service()); | 596 test_helper()->ExpectNoRequests(service()); |
| 592 | 597 |
| 593 // Re-enable SafeBrowsing. | 598 // Re-enable SafeBrowsing. |
| 594 ToggleSafeBrowsingAndWaitForServiceReset(true); | 599 ToggleSafeBrowsingAndWaitForServiceReset(true); |
| 595 | 600 |
| 596 // Trigger a report that hangs. | 601 // Trigger a report that hangs. |
| 597 SendReport("report1"); | 602 SendReport("report1"); |
| 598 test_helper()->WaitForRequestsCreated( | 603 test_helper()->WaitForRequestsCreated( |
| 599 ReportExpectation::Delayed({"report1"})); | 604 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 600 | 605 |
| 601 // Resume the delayed report and wait for it to complete. | 606 // Resume the delayed report and wait for it to complete. |
| 602 test_helper()->ResumeDelayedRequest(); | 607 test_helper()->ResumeDelayedRequest(); |
| 603 test_helper()->WaitForRequestsDestroyed( | 608 test_helper()->WaitForRequestsDestroyed( |
| 604 ReportExpectation::Delayed({"report1"})); | 609 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 605 } | 610 } |
| 606 | 611 |
| 607 } // namespace safe_browsing | 612 } // namespace safe_browsing |
| OLD | NEW |