Chromium Code Reviews| Index: chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc |
| diff --git a/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc b/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc |
| index f7d4c8fbcf605d06da63cea3c8b47613c26d9796..25c538e1372603067fb0e37026cd07a1caba0e2d 100644 |
| --- a/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc |
| +++ b/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc |
| @@ -4,20 +4,38 @@ |
| #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| +#include <set> |
| #include <string> |
| +#include "base/bind.h" |
| #include "base/run_loop.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "base/test/simple_test_clock.h" |
| #include "base/time/clock.h" |
| #include "base/time/time.h" |
| +#include "chrome/browser/safe_browsing/certificate_reporting_service_test_utils.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/test/test_browser_thread.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| #include "net/base/network_delegate_impl.h" |
| #include "net/test/url_request/url_request_failed_job.h" |
| #include "net/test/url_request/url_request_mock_data_job.h" |
| +#include "net/url_request/url_request_filter.h" |
| #include "net/url_request/url_request_test_util.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -TEST(CertificateReportingServiceTest, BoundedReportList) { |
| +namespace { |
| +void ClearURLHandlers() { |
| + net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| +} |
| + |
| +// Maximum number of reports kept in the certificate reporting service's retry |
| +// queue. |
| +const size_t kMaxReportCountInQueue = 3; |
| + |
| +} // namespace |
| + |
| +TEST(CertificateReportingServiceReportListTest, BoundedReportList) { |
| // Create a report list with maximum of 2 items. |
| CertificateReportingService::BoundedReportList list(2 /* max_size */); |
| EXPECT_EQ(0u, list.items().size()); |
| @@ -56,7 +74,8 @@ TEST(CertificateReportingServiceTest, BoundedReportList) { |
| EXPECT_EQ("report2_five_minutes_old", list.items()[1].serialized_report); |
| } |
| -class CertificateReportingServiceReporterTest : public ::testing::Test { |
| +class CertificateReportingServiceReporterOnIOThreadTest |
| + : public ::testing::Test { |
| public: |
| void SetUp() override { |
| message_loop_.reset(new base::MessageLoopForIO()); |
| @@ -68,6 +87,8 @@ class CertificateReportingServiceReporterTest : public ::testing::Test { |
| net::URLRequestMockDataJob::AddUrlHandler(); |
| } |
| + void TearDown() override { ClearURLHandlers(); } |
| + |
| protected: |
| net::URLRequestContextGetter* url_request_context_getter() { |
| return url_request_context_getter_.get(); |
| @@ -80,7 +101,8 @@ class CertificateReportingServiceReporterTest : public ::testing::Test { |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| }; |
| -TEST_F(CertificateReportingServiceReporterTest, Reporter) { |
| +TEST_F(CertificateReportingServiceReporterOnIOThreadTest, |
| + Reporter_RetriesEnabled) { |
| std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); |
| base::Time reference_time = base::Time::Now(); |
| clock->SetNow(reference_time); |
| @@ -95,11 +117,13 @@ TEST_F(CertificateReportingServiceReporterTest, Reporter) { |
| CertificateReportingService::BoundedReportList* list = |
| new CertificateReportingService::BoundedReportList(2); |
| + // Create a reporter with retries enabled. |
| CertificateReportingService::Reporter reporter( |
| std::unique_ptr<certificate_reporting::ErrorReporter>( |
| certificate_error_reporter), |
| std::unique_ptr<CertificateReportingService::BoundedReportList>(list), |
| - clock.get(), base::TimeDelta::FromSeconds(100)); |
| + clock.get(), base::TimeDelta::FromSeconds(100), nullptr, |
| + true /* retries_enabled */); |
| EXPECT_EQ(0u, list->items().size()); |
| EXPECT_EQ(0u, reporter.inflight_report_count_for_testing()); |
| @@ -172,3 +196,470 @@ TEST_F(CertificateReportingServiceReporterTest, Reporter) { |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_EQ(0u, list->items().size()); |
| } |
| + |
| +// Same as above, but retries are disabled. |
| +TEST_F(CertificateReportingServiceReporterOnIOThreadTest, |
| + Reporter_RetriesDisabled) { |
| + std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); |
| + base::Time reference_time = base::Time::Now(); |
| + clock->SetNow(reference_time); |
| + |
| + const GURL kFailureURL = |
| + net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_SSL_PROTOCOL_ERROR); |
| + certificate_reporting::ErrorReporter* certificate_error_reporter = |
| + new certificate_reporting::ErrorReporter( |
| + url_request_context_getter()->GetURLRequestContext(), kFailureURL, |
| + net::ReportSender::DO_NOT_SEND_COOKIES); |
| + |
| + CertificateReportingService::BoundedReportList* list = |
| + new CertificateReportingService::BoundedReportList(2); |
| + |
| + // Create a reporter with retries disabled. |
| + CertificateReportingService::Reporter reporter( |
| + std::unique_ptr<certificate_reporting::ErrorReporter>( |
| + certificate_error_reporter), |
| + std::unique_ptr<CertificateReportingService::BoundedReportList>(list), |
| + clock.get(), base::TimeDelta::FromSeconds(100), nullptr, |
| + false /* retries_enabled */); |
| + EXPECT_EQ(0u, list->items().size()); |
| + EXPECT_EQ(0u, reporter.inflight_report_count_for_testing()); |
| + |
| + // Sending a failed report will not put the report in the retry list. |
| + reporter.Send("report1"); |
| + EXPECT_EQ(1u, reporter.inflight_report_count_for_testing()); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0u, reporter.inflight_report_count_for_testing()); |
| + ASSERT_EQ(0u, list->items().size()); |
| + |
| + // Sending a second failed report will also not put it in the retry list. |
| + clock->Advance(base::TimeDelta::FromSeconds(10)); |
| + reporter.Send("report2"); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_EQ(0u, list->items().size()); |
| + |
| + // Send pending reports. Nothing should be sent. |
| + clock->Advance(base::TimeDelta::FromSeconds(10)); |
| + reporter.SendPending(); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_EQ(0u, list->items().size()); |
| +} |
| + |
| +class CertificateReportingServiceTest |
| + : public ::testing::Test, |
| + public certificate_reporting_test_utils:: |
| + CertificateReportingServiceTestBase { |
| + public: |
| + CertificateReportingServiceTest() |
| + : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), |
| + io_task_runner_(content::BrowserThread::GetTaskRunnerForThread( |
| + content::BrowserThread::IO)), |
| + url_request_context_getter_( |
| + new net::TestURLRequestContextGetter(io_task_runner_)) {} |
| + |
| + ~CertificateReportingServiceTest() override {} |
| + |
| + void SetUp() override { |
| + SetUpInterceptor(); |
| + |
| + // Create an event observer to wait for a single "Reset" event that happens |
| + // on service initialization. |
| + certificate_reporting_test_utils::ReportEventObserver* observer = |
| + new certificate_reporting_test_utils::ReportEventObserver(1); |
| + |
| + service_.reset(new CertificateReportingService( |
| + url_request_context_getter_, |
| + std::unique_ptr<certificate_reporting_test_utils::ReportEventObserver>( |
| + observer), |
| + kMaxReportCountInQueue, base::TimeDelta::FromHours(24), &clock_)); |
| + // Wait for reporting service initialization. |
| + observer->WaitForEvents(); |
| + } |
| + |
| + void TearDown() override { |
| + // Wait for reporting service shutdown. |
| + certificate_reporting_test_utils::ReportEventObserver* event_observer = |
| + NewEventObserver(1); |
| + service()->Shutdown(); |
| + event_observer->WaitForEvents(); |
| + |
| + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ClearURLHandlers)); |
| + } |
| + |
| + protected: |
| + net::URLRequestContextGetter* url_request_context_getter() { |
| + return url_request_context_getter_.get(); |
| + } |
| + |
| + certificate_reporting_test_utils::ReportEventObserver* NewEventObserver( |
| + int num_events_to_wait_for) { |
| + certificate_reporting_test_utils::ReportEventObserver* observer = |
| + new certificate_reporting_test_utils::ReportEventObserver( |
| + num_events_to_wait_for); |
| + service_->SetEventObserverForTesting( |
| + std::unique_ptr<CertificateReportingService::EventObserver>(observer)); |
| + return observer; |
| + } |
| + |
| + CertificateReportingService* service() { return service_.get(); } |
| + |
| + // Sends a test report and checks expected events. |
| + void SendReport(int expected_completed_attempts, |
| + int expected_cancelled_attempts, |
| + const std::set<int>& expected_successful_report_ids, |
| + const std::set<int>& expected_failed_report_ids) { |
| + certificate_reporting_test_utils::ReportEventObserver* report_observer = |
| + NewEventObserver(expected_completed_attempts + |
| + expected_cancelled_attempts + |
| + expected_successful_report_ids.size() + |
| + expected_failed_report_ids.size()); |
| + service()->Send("test_report"); |
| + report_observer->WaitForEvents(); |
| + |
| + EXPECT_EQ(0, report_observer->num_resets()); |
|
Jialiu Lin
2016/11/30 22:18:06
nit: maybe move the expected value checking part o
meacer
2016/11/30 23:39:40
I actually did this in the follow up CL which I'll
Jialiu Lin
2016/11/30 23:54:58
Sure. I didn't review patchset#2. Sorry about that
|
| + EXPECT_EQ(expected_cancelled_attempts, |
| + report_observer->num_cancelled_attempts()); |
| + EXPECT_EQ(expected_completed_attempts, |
| + report_observer->num_completed_attempts()); |
| + EXPECT_EQ(expected_successful_report_ids, |
| + report_observer->successful_report_ids()); |
| + EXPECT_EQ(expected_failed_report_ids, report_observer->failed_report_ids()); |
| + } |
| + |
| + // Sends pending reports and checks expected events. |
| + void SendPendingReports(int expected_completed_attempts, |
| + int expected_cancelled_attempts, |
| + const std::set<int>& expected_successful_report_ids, |
| + const std::set<int>& expected_failed_report_ids) { |
| + certificate_reporting_test_utils::ReportEventObserver* report_observer = |
| + NewEventObserver(expected_completed_attempts + |
| + expected_cancelled_attempts + |
| + expected_successful_report_ids.size() + |
| + expected_failed_report_ids.size()); |
| + service()->SendPending(); |
| + report_observer->WaitForEvents(); |
| + |
| + EXPECT_EQ(0, report_observer->num_resets()); |
| + EXPECT_EQ(expected_cancelled_attempts, |
| + report_observer->num_cancelled_attempts()); |
| + EXPECT_EQ(expected_completed_attempts, |
| + report_observer->num_completed_attempts()); |
| + EXPECT_EQ(expected_successful_report_ids, |
| + report_observer->successful_report_ids()); |
| + EXPECT_EQ(expected_failed_report_ids, report_observer->failed_report_ids()); |
| + } |
| + |
| + // Sets service enabled state and waits for a reset event. |
| + void SetServiceEnabledAndWait(bool enabled) { |
| + certificate_reporting_test_utils::ReportEventObserver* report_observer = |
| + NewEventObserver(1); |
| + service()->SetEnabled(enabled); |
| + report_observer->WaitForEvents(); |
| + EXPECT_EQ(1, report_observer->num_resets()); |
| + EXPECT_EQ(0, report_observer->num_cancelled_attempts()); |
| + EXPECT_EQ(0, report_observer->num_completed_attempts()); |
| + EXPECT_EQ(std::set<int>(), report_observer->successful_report_ids()); |
| + EXPECT_EQ(std::set<int>(), report_observer->failed_report_ids()); |
| + } |
| + |
| + // Resumes delayed requests and checks expected events. |
| + void ResumeDelayedRequests( |
| + int num_expected_events, |
| + const std::set<int>& expected_successful_report_ids, |
| + const std::set<int>& expected_failed_report_ids) { |
| + certificate_reporting_test_utils::ReportEventObserver* report_observer = |
| + NewEventObserver(num_expected_events); |
| + ResumeDelayedRequest(); |
| + report_observer->WaitForEvents(); |
| + EXPECT_EQ(0, report_observer->num_completed_attempts()); |
| + EXPECT_EQ(0, report_observer->num_cancelled_attempts()); |
| + EXPECT_EQ(0, report_observer->num_resets()); |
| + EXPECT_EQ(expected_successful_report_ids, |
| + report_observer->successful_report_ids()); |
| + EXPECT_EQ(expected_failed_report_ids, report_observer->failed_report_ids()); |
| + } |
| + |
| + base::SimpleTestClock* clock() { return &clock_; } |
| + |
| + private: |
| + // Must be initialized before url_request_context_getter_ |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| + |
| + std::unique_ptr<CertificateReportingService> service_; |
| + base::SimpleTestClock clock_; |
| +}; |
| + |
| +TEST_F(CertificateReportingServiceTest, Send) { |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| + |
| + // Send a report. A failed report with id = 0 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{0} /* expected_failed_report_ids */); |
| + |
| + // Send another report. A failed report with id = 1 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{1} /* expected_failed_report_ids */); |
| + |
| + // Send pending reports. Previously failed reports should be observed again. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{0, 1} /* expected_failed_report_ids */); |
| + |
| + // Let all reports succeed. |
| + SetFailureMode(certificate_reporting_test_utils::ReportSendingResult:: |
| + REPORTS_SUCCESSFUL); |
| + |
| + // Send a third report. A successful report with id = 2 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>{2} /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Send pending reports again. Previously failed reports should be observed. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>{0, 1} /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, Disabled_ShouldNotSend) { |
| + // Let all reports succeed. |
| + SetFailureMode(certificate_reporting_test_utils::ReportSendingResult:: |
| + REPORTS_SUCCESSFUL); |
| + |
| + // Disable the service. |
| + SetServiceEnabledAndWait(false); |
| + |
| + // Send a report. Report attempt should be cancelled and no sent reports |
| + // should be observed. |
| + SendReport(0 /* expected_completed_attempts */, |
| + 1 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Enable the service and send a report again. A report with id = 0 should be |
| + // successfully sent. |
| + SetServiceEnabledAndWait(true); |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>{0} /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, Disabled_ShouldClearPendingReports) { |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| + |
| + // Send a report. A failed report with id = 0 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{0} /* expected_failed_report_ids */); |
| + |
| + // Disable the service. |
| + SetServiceEnabledAndWait(false); |
| + |
| + // Sending has no effect while disabled. |
| + SendPendingReports(0 /* expected_completed_attempts */, |
| + 1 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Re-enable the service and send pending reports. Pending reports should have |
| + // been cleared when the service was disabled, so no report should be seen. |
| + SetServiceEnabledAndWait(true); |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, DontSendOldReports) { |
| + base::Time reference_time = base::Time::Now(); |
| + clock()->SetNow(reference_time); |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| + |
| + // Send a report. A failed report with id = 0 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{0} /* expected_failed_report_ids */); |
| + |
| + // Advance the clock a bit and trigger another report. A failed report with |
| + // id = 1 should be observed. |
| + clock()->Advance(base::TimeDelta::FromHours(5)); |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{1} /* expected_failed_report_ids */); |
| + |
| + // Advance the clock to 20 hours, putting it 25 hours ahead of the reference |
| + // time. This makes the first report with id = 0 older than max age (24 |
| + // hours). The second report is now 20 hours. |
| + clock()->Advance(base::TimeDelta::FromHours(20)); |
| + // Send pending reports. First report (id = 0) should be discarded since |
| + // it's too old. Second report (id = 1) should be queued again. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{1} /* expected_failed_report_ids */); |
| + |
| + // Send a third report. A failed report with id = 2 should be observed. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{2} /* expected_failed_report_ids */); |
| + |
| + // Advance the clock 5 hours. The report with id = 1 will now be 25 hours old. |
| + clock()->Advance(base::TimeDelta::FromHours(5)); |
| + // Send pending reports. Report with id = 1 should be discarded since |
| + // it's too old. Report with id = 2 should be queued again. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{2} /* expected_failed_report_ids */); |
| + |
| + // Advance the clock 20 hours again so that the report with id = 2 is 25 hours |
| + // old and is older than max age (24 hours) |
| + clock()->Advance(base::TimeDelta::FromHours(20)); |
| + // Send pending reports. Report with id = 2 should be discarded since |
| + // it's too old. No other reports remain. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, DiscardOldReports) { |
| + base::Time reference_time = base::Time::Now(); |
| + clock()->SetNow(reference_time); |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| + |
| + // Trigger a failed report. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{0} /* expected_failed_report_ids */); |
| + |
| + // Trigger three more reports within two hours of each other. After this: |
| + // Report with id = 0 is 0 hours after reference time. |
| + // Report with id = 1 is 5 hours after reference time. |
| + // Report with id = 2 is 10 hours after reference time. |
| + // Report with id = 3 is 15 hours after reference time. |
| + for (size_t report_id = 1; report_id <= 3; report_id++) { |
| + clock()->Advance(base::TimeDelta::FromHours(5)); |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>(), /* expected_successful_report_ids */ |
| + std::set<int>{report_id} /* expected_failed_report_ids */); |
| + } |
| + |
| + // Send pending reports. Four reports were generated above, but the service |
| + // only queues three reports, so the very first one should be dropped since |
| + // it's the oldest. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{1, 2, 3} /* expected_failed_report_ids */); |
| + |
| + // Let all reports succeed. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| + |
| + // Advance clock to 15 hours. The current time is now 30 hours after |
| + // reference time. The ages of reports are now as follows: |
| + // Report with id = 1 is 25 hours old. |
| + // Report with id = 2 is 20 hours old. |
| + // Report with id = 3 is 15 hours old. |
| + clock()->Advance(base::TimeDelta::FromHours(15)); |
| + // Send pending reports. Only reports 2 and 3 should be sent, report 1 |
| + // should be ignored because it's too old. |
| + SendPendingReports(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>{2, 3} /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, Delayed_NotResumed_ShouldNotCrash) { |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| + // Send a report. The report is triggered but hangs, so no error or success |
| + // callbacks should be called. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, Delayed_Resumed) { |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| + // Send a report. The report upload hangs, so no error or success callbacks |
| + // should be called. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attempts */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Resume the report upload and run the callbacks. The report should be |
| + // successfully sent. |
| + ResumeDelayedRequests(1 /* num_expected_events */, |
| + std::set<int>{0} /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |
| + |
| +TEST_F(CertificateReportingServiceTest, Delayed_Reset) { |
| + // Let all reports fail. |
| + SetFailureMode( |
| + certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| + // Send a report. The report is triggered but hangs, so no error or success |
| + // callbacks should be called. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Disable the service. This should reset the reporting service and |
| + // clear all pending reports. |
| + SetServiceEnabledAndWait(false); |
| + |
| + // Resume delayed report. No response should be observed since the service |
| + // should have reset and all pending reports should be cleared. |
| + ResumeDelayedRequests(0 /* num_expected_events */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Enable the service. |
| + SetServiceEnabledAndWait(true); |
| + |
| + // Send a report. The report is triggered but hangs, so no error or success |
| + // callbacks should be called. The report id is again 0 since the pending |
| + // report queue has been cleared above. |
| + SendReport(1 /* expected_completed_attempts */, |
| + 0 /* expected_cancelled_attemps */, |
| + std::set<int>() /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| + |
| + // Resume delayed report. The report should be observed. |
| + ResumeDelayedRequests(1 /* num_expected_events */, |
| + std::set<int>{0} /* expected_successful_report_ids */, |
| + std::set<int>() /* expected_failed_report_ids */); |
| +} |