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

Unified Diff: chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc

Issue 2503243003: Wire up CertificateReportingService to handle report uploads (Closed)
Patch Set: Rebase onto crrev/2543523002 Created 4 years 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 side-by-side diff with in-line comments
Download patch
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 948b0aea03eca4c1f0112330c9daab59382cca4d..b64e53c8406978f70605af054bef5278ab56bdf5 100644
--- a/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
+++ b/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
@@ -14,6 +14,9 @@
#include "base/time/clock.h"
#include "base/time/time.h"
#include "chrome/browser/safe_browsing/certificate_reporting_service_test_utils.h"
+#include "chrome/browser/safe_browsing/safe_browsing_service.h"
+#include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
+#include "chrome/test/base/testing_profile.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"
@@ -28,11 +31,6 @@ 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) {
@@ -245,19 +243,17 @@ TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
ASSERT_EQ(0u, list->items().size());
}
+namespace {
+
+const size_t kMaxReportCountInQueue = 3;
+
+} // namespace
+
class CertificateReportingServiceTest
: public ::testing::Test,
public certificate_reporting_test_utils::
CertificateReportingServiceTestBase {
public:
- enum ReportSendStatus {
- // Indicates that the send attempt is completed.
- EXPECT_SEND_ATTEMPT_COMPLETED,
- // Indicates that the send attempt is cancelled (e.g. extended reporting was
- // not opted in).
- EXPECT_SEND_ATTEMPT_CANCELLED,
- };
-
CertificateReportingServiceTest()
: thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD),
io_task_runner_(content::BrowserThread::GetTaskRunnerForThread(
@@ -270,13 +266,16 @@ class CertificateReportingServiceTest
void SetUp() override {
SetUpInterceptor();
+ safe_browsing::SafeBrowsingService::RegisterFactory(&sb_service_factory);
+ sb_service_ = sb_service_factory.CreateSafeBrowsingService();
+
// 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_,
+ sb_service_, url_request_context_getter_, &profile_,
std::unique_ptr<certificate_reporting_test_utils::ReportEventObserver>(
observer),
kMaxReportCountInQueue, base::TimeDelta::FromHours(24), &clock_));
@@ -313,7 +312,7 @@ class CertificateReportingServiceTest
CertificateReportingService* service() { return service_.get(); }
// Sends a test report and checks expected events.
- void SendReport(ReportSendStatus expected_send_attempt_status,
+ void SendReport(ObservedReportEvent expected_observed_event,
const std::set<int>& expected_successful_report_ids,
const std::set<int>& expected_failed_report_ids) {
// Observe events: 1 event for send completion or cancellation,
@@ -324,21 +323,14 @@ class CertificateReportingServiceTest
service()->Send("test_report");
report_observer->WaitForEvents();
- EXPECT_EQ(0u, report_observer->num_resets());
- if (expected_send_attempt_status == EXPECT_SEND_ATTEMPT_COMPLETED) {
- EXPECT_EQ(1u, report_observer->num_completed_attempts());
- EXPECT_EQ(0u, report_observer->num_cancelled_attempts());
- } else {
- EXPECT_EQ(0u, report_observer->num_completed_attempts());
- EXPECT_EQ(1u, report_observer->num_cancelled_attempts());
- }
- EXPECT_EQ(expected_successful_report_ids,
- report_observer->successful_report_ids());
- EXPECT_EQ(expected_failed_report_ids, report_observer->failed_report_ids());
+ EXPECT_NE(EXPECT_SERVICE_RESET, expected_observed_event);
+ CheckExpectedResults(*report_observer, expected_observed_event,
+ expected_successful_report_ids,
+ expected_failed_report_ids);
}
// Sends pending reports and checks expected events.
- void SendPendingReports(ReportSendStatus expected_send_attempt_status,
+ void SendPendingReports(ObservedReportEvent expected_observed_event,
const std::set<int>& expected_successful_report_ids,
const std::set<int>& expected_failed_report_ids) {
// Observe events: 1 event for send completion or cancellation,
@@ -349,17 +341,10 @@ class CertificateReportingServiceTest
service()->SendPending();
report_observer->WaitForEvents();
- EXPECT_EQ(0u, report_observer->num_resets());
- if (expected_send_attempt_status == EXPECT_SEND_ATTEMPT_COMPLETED) {
- EXPECT_EQ(1u, report_observer->num_completed_attempts());
- EXPECT_EQ(0u, report_observer->num_cancelled_attempts());
- } else {
- EXPECT_EQ(0u, report_observer->num_completed_attempts());
- EXPECT_EQ(1u, report_observer->num_cancelled_attempts());
- }
- EXPECT_EQ(expected_successful_report_ids,
- report_observer->successful_report_ids());
- EXPECT_EQ(expected_failed_report_ids, report_observer->failed_report_ids());
+ EXPECT_NE(EXPECT_SERVICE_RESET, expected_observed_event);
+ CheckExpectedResults(*report_observer, expected_observed_event,
+ expected_successful_report_ids,
+ expected_failed_report_ids);
}
// Sets service enabled state and waits for a reset event.
@@ -368,11 +353,9 @@ class CertificateReportingServiceTest
NewEventObserver(1u);
service()->SetEnabled(enabled);
report_observer->WaitForEvents();
- EXPECT_EQ(1u, report_observer->num_resets());
- EXPECT_EQ(0u, report_observer->num_cancelled_attempts());
- EXPECT_EQ(0u, 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());
+
+ CheckExpectedResults(*report_observer, EXPECT_SERVICE_RESET,
+ std::set<int>(), std::set<int>());
}
// Resumes delayed requests and checks expected events.
@@ -384,12 +367,10 @@ class CertificateReportingServiceTest
NewEventObserver(num_expected_events);
ResumeDelayedRequest();
report_observer->WaitForEvents();
- EXPECT_EQ(0u, report_observer->num_completed_attempts());
- EXPECT_EQ(0u, report_observer->num_cancelled_attempts());
- EXPECT_EQ(0u, 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());
+
+ CheckExpectedResults(*report_observer, EXPECT_NONE,
+ expected_successful_report_ids,
+ expected_failed_report_ids);
}
base::SimpleTestClock* clock() { return &clock_; }
@@ -403,6 +384,10 @@ class CertificateReportingServiceTest
std::unique_ptr<CertificateReportingService> service_;
base::SimpleTestClock clock_;
+
+ safe_browsing::SafeBrowsingService* sb_service_;
+ safe_browsing::TestSafeBrowsingServiceFactory sb_service_factory;
+ TestingProfile profile_;
};
TEST_F(CertificateReportingServiceTest, Send) {
« no previous file with comments | « chrome/browser/safe_browsing/certificate_reporting_service_test_utils.cc ('k') | chrome/browser/safe_browsing/ping_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698