| 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 19 matching lines...) Expand all Loading... |
| 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::EventHistogramTester; |
| 40 using certificate_reporting_test_utils::ReportExpectation; | 41 using certificate_reporting_test_utils::ReportExpectation; |
| 41 using certificate_reporting_test_utils::RetryStatus; | 42 using certificate_reporting_test_utils::RetryStatus; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; | 46 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; |
| 46 | 47 |
| 47 void CleanUpOnIOThread() { | 48 void CleanUpOnIOThread() { |
| 48 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 49 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 49 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 50 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 test_helper()->SetUpInterceptor(); | 78 test_helper()->SetUpInterceptor(); |
| 78 | 79 |
| 79 CertificateReportingServiceFactory::GetInstance() | 80 CertificateReportingServiceFactory::GetInstance() |
| 80 ->SetReportEncryptionParamsForTesting( | 81 ->SetReportEncryptionParamsForTesting( |
| 81 test_helper()->server_public_key(), | 82 test_helper()->server_public_key(), |
| 82 test_helper()->server_public_key_version()); | 83 test_helper()->server_public_key_version()); |
| 83 CertificateReportingServiceFactory::GetInstance() | 84 CertificateReportingServiceFactory::GetInstance() |
| 84 ->SetServiceResetCallbackForTesting( | 85 ->SetServiceResetCallbackForTesting( |
| 85 base::Bind(&CertificateReportingServiceObserver::OnServiceReset, | 86 base::Bind(&CertificateReportingServiceObserver::OnServiceReset, |
| 86 base::Unretained(&service_observer_))); | 87 base::Unretained(&service_observer_))); |
| 88 |
| 89 event_histogram_tester_.reset(new EventHistogramTester()); |
| 87 InProcessBrowserTest::SetUpOnMainThread(); | 90 InProcessBrowserTest::SetUpOnMainThread(); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void TearDownOnMainThread() override { | 93 void TearDownOnMainThread() override { |
| 91 test_helper()->ExpectNoRequests(service()); | 94 test_helper()->ExpectNoRequests(service()); |
| 92 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 95 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 93 base::BindOnce(&CleanUpOnIOThread)); | 96 base::BindOnce(&CleanUpOnIOThread)); |
| 94 EXPECT_GE(num_expected_failed_report_, 0) | 97 EXPECT_GE(num_expected_failed_report_, 0) |
| 95 << "Don't forget to set expected failed report count."; | 98 << "Don't forget to set expected failed report count."; |
| 96 // Check the histogram as the last thing. This makes sure no in-flight | 99 // Check the histogram as the last thing. This makes sure no in-flight |
| 97 // report is missed. | 100 // report is missed. |
| 98 if (num_expected_failed_report_ != 0) { | 101 if (num_expected_failed_report_ != 0) { |
| 99 histogram_tester_.ExpectUniqueSample(kFailedReportHistogram, | 102 histogram_tester_.ExpectUniqueSample(kFailedReportHistogram, |
| 100 -net::ERR_SSL_PROTOCOL_ERROR, | 103 -net::ERR_SSL_PROTOCOL_ERROR, |
| 101 num_expected_failed_report_); | 104 num_expected_failed_report_); |
| 102 } else { | 105 } else { |
| 103 histogram_tester_.ExpectTotalCount(kFailedReportHistogram, 0); | 106 histogram_tester_.ExpectTotalCount(kFailedReportHistogram, 0); |
| 104 } | 107 } |
| 108 |
| 109 event_histogram_tester_.reset(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void SetUpCommandLine(base::CommandLine* command_line) override { | 112 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 108 command_line->AppendSwitchASCII( | 113 command_line->AppendSwitchASCII( |
| 109 switches::kForceFieldTrials, | 114 switches::kForceFieldTrials, |
| 110 "ReportCertificateErrors/ShowAndPossiblySend/"); | 115 "ReportCertificateErrors/ShowAndPossiblySend/"); |
| 111 // Setting the sending threshold to 1.0 ensures reporting is enabled. | 116 // Setting the sending threshold to 1.0 ensures reporting is enabled. |
| 112 command_line->AppendSwitchASCII( | 117 command_line->AppendSwitchASCII( |
| 113 variations::switches::kForceFieldTrialParams, | 118 variations::switches::kForceFieldTrialParams, |
| 114 "ReportCertificateErrors.ShowAndPossiblySend:sendingThreshold/1.0"); | 119 "ReportCertificateErrors.ShowAndPossiblySend:sendingThreshold/1.0"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 173 |
| 169 void SetExpectedHistogramCountOnTeardown(int num_expected_failed_report) { | 174 void SetExpectedHistogramCountOnTeardown(int num_expected_failed_report) { |
| 170 num_expected_failed_report_ = num_expected_failed_report; | 175 num_expected_failed_report_ = num_expected_failed_report; |
| 171 } | 176 } |
| 172 | 177 |
| 173 CertificateReportingService* service() const { | 178 CertificateReportingService* service() const { |
| 174 return CertificateReportingServiceFactory::GetForBrowserContext( | 179 return CertificateReportingServiceFactory::GetForBrowserContext( |
| 175 browser()->profile()); | 180 browser()->profile()); |
| 176 } | 181 } |
| 177 | 182 |
| 183 EventHistogramTester* event_histogram_tester() { |
| 184 return event_histogram_tester_.get(); |
| 185 } |
| 186 |
| 178 private: | 187 private: |
| 179 // Checks that the serialized reports in |received_reports| have the same | 188 // Checks that the serialized reports in |received_reports| have the same |
| 180 // hostnames as |expected_hostnames|. | 189 // hostnames as |expected_hostnames|. |
| 181 void CheckReports(const std::set<std::string>& expected_hostnames, | 190 void CheckReports(const std::set<std::string>& expected_hostnames, |
| 182 const std::set<std::string>& received_reports, | 191 const std::set<std::string>& received_reports, |
| 183 const std::string type) { | 192 const std::string type) { |
| 184 std::set<std::string> received_hostnames; | 193 std::set<std::string> received_hostnames; |
| 185 for (const std::string& serialized_report : received_reports) { | 194 for (const std::string& serialized_report : received_reports) { |
| 186 certificate_reporting::ErrorReport report; | 195 certificate_reporting::ErrorReport report; |
| 187 ASSERT_TRUE(report.InitializeFromString(serialized_report)); | 196 ASSERT_TRUE(report.InitializeFromString(serialized_report)); |
| 188 received_hostnames.insert(report.hostname()); | 197 received_hostnames.insert(report.hostname()); |
| 189 } | 198 } |
| 190 EXPECT_EQ(expected_hostnames, received_hostnames) << type | 199 EXPECT_EQ(expected_hostnames, received_hostnames) << type |
| 191 << " comparison failed"; | 200 << " comparison failed"; |
| 192 } | 201 } |
| 193 | 202 |
| 194 net::EmbeddedTestServer https_server_; | 203 net::EmbeddedTestServer https_server_; |
| 195 | 204 |
| 196 int num_expected_failed_report_ = -1; | 205 int num_expected_failed_report_ = -1; |
| 197 | 206 |
| 198 CertificateReportingServiceTestHelper test_helper_; | 207 CertificateReportingServiceTestHelper test_helper_; |
| 199 | 208 |
| 200 CertificateReportingServiceObserver service_observer_; | 209 CertificateReportingServiceObserver service_observer_; |
| 201 | 210 |
| 202 base::HistogramTester histogram_tester_; | 211 base::HistogramTester histogram_tester_; |
| 212 std::unique_ptr<EventHistogramTester> event_histogram_tester_; |
| 203 | 213 |
| 204 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); | 214 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); |
| 205 }; | 215 }; |
| 206 | 216 |
| 207 // Tests that report send attempt should be cancelled when extended | 217 // Tests that report send attempt should be cancelled when extended |
| 208 // reporting is not opted in. | 218 // reporting is not opted in. |
| 209 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 219 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 210 NotOptedIn_ShouldNotSendReports) { | 220 NotOptedIn_ShouldNotSendReports) { |
| 211 SetExpectedHistogramCountOnTeardown(0); | 221 SetExpectedHistogramCountOnTeardown(0); |
| 212 | 222 |
| 213 certificate_reporting_test_utils::SetCertReportingOptIn( | 223 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 214 browser(), | 224 browser(), |
| 215 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 225 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| 216 // Send a report. Test teardown checks for created and in-flight requests. If | 226 // Send a report. Test teardown checks for created and in-flight requests. If |
| 217 // a report was incorrectly sent, the test will fail. | 227 // a report was incorrectly sent, the test will fail. |
| 218 SendReport("no-report"); | 228 SendReport("no-report"); |
| 229 |
| 230 event_histogram_tester()->SetExpectedValues(0, 0, 0, 0); |
| 219 } | 231 } |
| 220 | 232 |
| 221 // Tests that report send attempts are not cancelled when extended reporting is | 233 // Tests that report send attempts are not cancelled when extended reporting is |
| 222 // opted in. Goes to an interstitial page and navigates away to force a report | 234 // opted in. Goes to an interstitial page and navigates away to force a report |
| 223 // send event. | 235 // send event. |
| 224 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 236 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 225 OptedIn_ShouldSendSuccessfulReport) { | 237 OptedIn_ShouldSendSuccessfulReport) { |
| 226 SetExpectedHistogramCountOnTeardown(0); | 238 SetExpectedHistogramCountOnTeardown(0); |
| 227 | 239 |
| 228 certificate_reporting_test_utils::SetCertReportingOptIn( | 240 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 229 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 241 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 230 | 242 |
| 231 // Let reports uploads successfully complete. | 243 // Let reports uploads successfully complete. |
| 232 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 244 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
| 233 ReportSendingResult::REPORTS_SUCCESSFUL); | 245 ReportSendingResult::REPORTS_SUCCESSFUL); |
| 234 | 246 |
| 235 // Reporting is opted in, so the report should succeed. | 247 // Reporting is opted in, so the report should succeed. |
| 236 SendReport("report0"); | 248 SendReport("report0"); |
| 237 test_helper()->WaitForRequestsDestroyed( | 249 test_helper()->WaitForRequestsDestroyed( |
| 238 ReportExpectation::Successful({{"report0", RetryStatus::NOT_RETRIED}})); | 250 ReportExpectation::Successful({{"report0", RetryStatus::NOT_RETRIED}})); |
| 251 |
| 252 // report0 was successfully submitted. |
| 253 event_histogram_tester()->SetExpectedValues( |
| 254 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */); |
| 239 } | 255 } |
| 240 | 256 |
| 241 // Tests that report send attempts are not cancelled when extended reporting is | 257 // Tests that report send attempts are not cancelled when extended reporting is |
| 242 // opted in. Goes to an interstitial page and navigate away to force a report | 258 // opted in. Goes to an interstitial page and navigate away to force a report |
| 243 // send event. Repeats this three times and checks expected number of reports. | 259 // send event. Repeats this three times and checks expected number of reports. |
| 244 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 260 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 245 OptedIn_ShouldQueueFailedReport) { | 261 OptedIn_ShouldQueueFailedReport) { |
| 246 SetExpectedHistogramCountOnTeardown(2); | 262 SetExpectedHistogramCountOnTeardown(2); |
| 247 | 263 |
| 248 certificate_reporting_test_utils::SetCertReportingOptIn( | 264 certificate_reporting_test_utils::SetCertReportingOptIn( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 273 // Send all pending reports. The two previously failed reports should have | 289 // Send all pending reports. The two previously failed reports should have |
| 274 // been queued, and now be sent successfully. | 290 // been queued, and now be sent successfully. |
| 275 SendPendingReports(); | 291 SendPendingReports(); |
| 276 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( | 292 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( |
| 277 {{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}})); | 293 {{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}})); |
| 278 | 294 |
| 279 // Try sending pending reports again. Since there is no pending report, | 295 // Try sending pending reports again. Since there is no pending report, |
| 280 // nothing should be sent this time. If any report is sent, test teardown | 296 // nothing should be sent this time. If any report is sent, test teardown |
| 281 // will catch it. | 297 // will catch it. |
| 282 SendPendingReports(); | 298 SendPendingReports(); |
| 299 |
| 300 // report0 was submitted twice, failed once, succeeded once. |
| 301 // report1 was submitted twice, failed once, succeeded once. |
| 302 // report2 was submitted once, succeeded once. |
| 303 event_histogram_tester()->SetExpectedValues( |
| 304 5 /* submitted */, 2 /* failed */, 3 /* successful */, 0 /* dropped */); |
| 283 } | 305 } |
| 284 | 306 |
| 285 // Opting in then opting out of extended reporting should clear the pending | 307 // Opting in then opting out of extended reporting should clear the pending |
| 286 // report queue. | 308 // report queue. |
| 287 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 309 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 288 OptedIn_ThenOptedOut) { | 310 OptedIn_ThenOptedOut) { |
| 289 SetExpectedHistogramCountOnTeardown(1); | 311 SetExpectedHistogramCountOnTeardown(1); |
| 290 | 312 |
| 291 certificate_reporting_test_utils::SetCertReportingOptIn( | 313 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 292 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 314 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 293 // Let all reports fail. | 315 // Let all reports fail. |
| 294 test_helper()->SetFailureMode( | 316 test_helper()->SetFailureMode( |
| 295 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 317 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 296 | 318 |
| 297 // Send a failed report. | 319 // Send a failed report. |
| 298 SendReport("report0"); | 320 SendReport("report0"); |
| 299 test_helper()->WaitForRequestsDestroyed( | 321 test_helper()->WaitForRequestsDestroyed( |
| 300 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); | 322 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 301 | 323 |
| 302 // Disable reporting. This should clear all pending reports. | 324 // Disable reporting. This should clear all pending reports. |
| 303 ChangeOptInAndWait( | 325 ChangeOptInAndWait( |
| 304 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 326 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| 305 | 327 |
| 306 // Send pending reports. No reports should be observed during test teardown. | 328 // Send pending reports. No reports should be observed during test teardown. |
| 307 SendPendingReports(); | 329 SendPendingReports(); |
| 330 |
| 331 // report0 was submitted once and failed once. |
| 332 event_histogram_tester()->SetExpectedValues( |
| 333 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */); |
| 308 } | 334 } |
| 309 | 335 |
| 310 // Opting out, then in, then out of extended reporting should work as expected. | 336 // Opting out, then in, then out of extended reporting should work as expected. |
| 311 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 337 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 312 OptedOut_ThenOptedIn_ThenOptedOut) { | 338 OptedOut_ThenOptedIn_ThenOptedOut) { |
| 313 SetExpectedHistogramCountOnTeardown(1); | 339 SetExpectedHistogramCountOnTeardown(1); |
| 314 | 340 |
| 315 certificate_reporting_test_utils::SetCertReportingOptIn( | 341 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 316 browser(), | 342 browser(), |
| 317 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 343 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 337 ChangeOptInAndWait( | 363 ChangeOptInAndWait( |
| 338 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 364 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
| 339 | 365 |
| 340 // Report should be cancelled since reporting is opted out. | 366 // Report should be cancelled since reporting is opted out. |
| 341 SendReport("report1"); | 367 SendReport("report1"); |
| 342 test_helper()->ExpectNoRequests(service()); | 368 test_helper()->ExpectNoRequests(service()); |
| 343 | 369 |
| 344 // Send pending reports. Nothing should be sent since there aren't any | 370 // Send pending reports. Nothing should be sent since there aren't any |
| 345 // pending reports. If any report is sent, test teardown will catch it. | 371 // pending reports. If any report is sent, test teardown will catch it. |
| 346 SendPendingReports(); | 372 SendPendingReports(); |
| 373 |
| 374 // report0 was submitted once and failed once. |
| 375 // report1 was never submitted. |
| 376 event_histogram_tester()->SetExpectedValues( |
| 377 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */); |
| 347 } | 378 } |
| 348 | 379 |
| 349 // Disabling SafeBrowsing should clear pending reports queue in | 380 // Disabling SafeBrowsing should clear pending reports queue in |
| 350 // CertificateReportingService. | 381 // CertificateReportingService. |
| 351 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 382 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 352 DisableSafebrowsing) { | 383 DisableSafebrowsing) { |
| 353 SetExpectedHistogramCountOnTeardown(2); | 384 SetExpectedHistogramCountOnTeardown(2); |
| 354 | 385 |
| 355 certificate_reporting_test_utils::SetCertReportingOptIn( | 386 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 356 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 387 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 357 // Let all reports fail. | 388 // Let all reports fail. |
| 358 test_helper()->SetFailureMode( | 389 test_helper()->SetFailureMode( |
| 359 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 390 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
| 360 | 391 |
| 361 // Send a delayed report. | 392 // Send a report. |
| 362 SendReport("report0"); | 393 SendReport("report0"); |
| 363 test_helper()->WaitForRequestsDestroyed( | 394 test_helper()->WaitForRequestsDestroyed( |
| 364 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); | 395 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 365 | 396 |
| 366 // Disable SafeBrowsing. This should clear all pending reports. | 397 // Disable SafeBrowsing. This should clear all pending reports. |
| 367 ToggleSafeBrowsingAndWaitForServiceReset(false); | 398 ToggleSafeBrowsingAndWaitForServiceReset(false); |
| 368 | 399 |
| 369 // Send pending reports. No reports should be observed. | 400 // Send pending reports. No reports should be observed. |
| 370 SendPendingReports(); | 401 SendPendingReports(); |
| 371 test_helper()->ExpectNoRequests(service()); | 402 test_helper()->ExpectNoRequests(service()); |
| 372 | 403 |
| 373 // Re-enable SafeBrowsing and trigger another report which will be queued. | 404 // Re-enable SafeBrowsing and trigger another report which will be queued. |
| 374 ToggleSafeBrowsingAndWaitForServiceReset(true); | 405 ToggleSafeBrowsingAndWaitForServiceReset(true); |
| 375 SendReport("report1"); | 406 SendReport("report1"); |
| 376 test_helper()->WaitForRequestsDestroyed( | 407 test_helper()->WaitForRequestsDestroyed( |
| 377 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); | 408 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 378 | 409 |
| 379 // Queued report should now be successfully sent. | 410 // Queued report should now be successfully sent. |
| 380 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 411 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
| 381 ReportSendingResult::REPORTS_SUCCESSFUL); | 412 ReportSendingResult::REPORTS_SUCCESSFUL); |
| 382 SendPendingReports(); | 413 SendPendingReports(); |
| 383 test_helper()->WaitForRequestsDestroyed( | 414 test_helper()->WaitForRequestsDestroyed( |
| 384 ReportExpectation::Successful({{"report1", RetryStatus::RETRIED}})); | 415 ReportExpectation::Successful({{"report1", RetryStatus::RETRIED}})); |
| 416 |
| 417 // report0 was submitted once, failed once, then cleared. |
| 418 // report1 was submitted twice, failed once, succeeded once. |
| 419 event_histogram_tester()->SetExpectedValues( |
| 420 3 /* submitted */, 2 /* failed */, 1 /* successful */, 0 /* dropped */); |
| 385 } | 421 } |
| 386 | 422 |
| 387 // CertificateReportingService should ignore reports older than the report TTL. | 423 // CertificateReportingService should ignore reports older than the report TTL. |
| 388 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 424 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 389 DontSendOldReports) { | 425 DontSendOldReports) { |
| 390 SetExpectedHistogramCountOnTeardown(5); | 426 SetExpectedHistogramCountOnTeardown(5); |
| 391 | 427 |
| 392 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 428 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
| 393 base::Time reference_time = base::Time::Now(); | 429 base::Time reference_time = base::Time::Now(); |
| 394 clock->SetNow(reference_time); | 430 clock->SetNow(reference_time); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 test_helper()->WaitForRequestsDestroyed( | 475 test_helper()->WaitForRequestsDestroyed( |
| 440 ReportExpectation::Failed({{"report2", RetryStatus::RETRIED}})); | 476 ReportExpectation::Failed({{"report2", RetryStatus::RETRIED}})); |
| 441 | 477 |
| 442 // Advance the clock 20 hours again so that report2 is 25 hours old and is | 478 // Advance the clock 20 hours again so that report2 is 25 hours old and is |
| 443 // older than max age (24 hours). | 479 // older than max age (24 hours). |
| 444 clock->Advance(base::TimeDelta::FromHours(20)); | 480 clock->Advance(base::TimeDelta::FromHours(20)); |
| 445 | 481 |
| 446 // Send pending reports. report2 should be discarded since it's too old. No | 482 // Send pending reports. report2 should be discarded since it's too old. No |
| 447 // other reports remain. If any report is sent, test teardown will catch it. | 483 // other reports remain. If any report is sent, test teardown will catch it. |
| 448 SendPendingReports(); | 484 SendPendingReports(); |
| 485 |
| 486 // report0 was submitted once, failed once, dropped once. |
| 487 // report1 was submitted twice, failed twice, dropped once. |
| 488 // report2 was submitted twice, failed twice, dropped once. |
| 489 event_histogram_tester()->SetExpectedValues( |
| 490 5 /* submitted */, 5 /* failed */, 0 /* successful */, 3 /* dropped */); |
| 449 } | 491 } |
| 450 | 492 |
| 451 // CertificateReportingService should drop old reports from its pending report | 493 // CertificateReportingService should drop old reports from its pending report |
| 452 // queue, if the queue is full. | 494 // queue, if the queue is full. |
| 453 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 495 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 454 DropOldReportsFromQueue) { | 496 DropOldReportsFromQueue) { |
| 455 SetExpectedHistogramCountOnTeardown(7); | 497 SetExpectedHistogramCountOnTeardown(7); |
| 456 | 498 |
| 457 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 499 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
| 458 base::Time reference_time = base::Time::Now(); | 500 base::Time reference_time = base::Time::Now(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // report1 is 25 hours old. | 555 // report1 is 25 hours old. |
| 514 // report2 is 20 hours old. | 556 // report2 is 20 hours old. |
| 515 // report3 is 15 hours old. | 557 // report3 is 15 hours old. |
| 516 clock->Advance(base::TimeDelta::FromHours(15)); | 558 clock->Advance(base::TimeDelta::FromHours(15)); |
| 517 | 559 |
| 518 // Send pending reports. Only reports 2 and 3 should be sent, report 1 | 560 // Send pending reports. Only reports 2 and 3 should be sent, report 1 |
| 519 // should be ignored because it's too old. | 561 // should be ignored because it's too old. |
| 520 SendPendingReports(); | 562 SendPendingReports(); |
| 521 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( | 563 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( |
| 522 {{"report2", RetryStatus::RETRIED}, {"report3", RetryStatus::RETRIED}})); | 564 {{"report2", RetryStatus::RETRIED}, {"report3", RetryStatus::RETRIED}})); |
| 565 |
| 566 // report0 was submitted once, failed once, dropped once. |
| 567 // report1 was submitted twice, failed twice, dropped once. |
| 568 // report2 was submitted thrice, failed twice, succeeded once. |
| 569 // report3 was submitted thrice, failed twice, succeeded once. |
| 570 event_histogram_tester()->SetExpectedValues( |
| 571 9 /* submitted */, 7 /* failed */, 2 /* successful */, 2 /* dropped */); |
| 523 } | 572 } |
| 524 | 573 |
| 525 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 574 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 526 Delayed_Resumed) { | 575 Delayed_Resumed) { |
| 527 SetExpectedHistogramCountOnTeardown(0); | 576 SetExpectedHistogramCountOnTeardown(0); |
| 528 | 577 |
| 529 certificate_reporting_test_utils::SetCertReportingOptIn( | 578 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 530 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 579 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 531 // Let all reports hang. | 580 // Let all reports hang. |
| 532 test_helper()->SetFailureMode( | 581 test_helper()->SetFailureMode( |
| 533 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 582 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| 534 | 583 |
| 535 // Trigger a report that hangs. | 584 // Trigger a report that hangs. |
| 536 SendReport("report0"); | 585 SendReport("report0"); |
| 537 test_helper()->WaitForRequestsCreated( | 586 test_helper()->WaitForRequestsCreated( |
| 538 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 587 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 539 | 588 |
| 540 // Resume the report upload. The report upload should successfully complete. | 589 // Resume the report upload. The report upload should successfully complete. |
| 541 // The interceptor only observes request creations and not response | 590 // The interceptor only observes request creations and not response |
| 542 // completions, so there is nothing to observe. | 591 // completions, so there is nothing to observe. |
| 543 test_helper()->ResumeDelayedRequest(); | 592 test_helper()->ResumeDelayedRequest(); |
| 544 test_helper()->WaitForRequestsDestroyed( | 593 test_helper()->WaitForRequestsDestroyed( |
| 545 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 594 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 595 |
| 596 // report0 was submitted once and succeeded once. |
| 597 event_histogram_tester()->SetExpectedValues( |
| 598 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */); |
| 546 } | 599 } |
| 547 | 600 |
| 548 // Same as above, but the service is shut down before resuming the delayed | 601 // Same as above, but the service is shut down before resuming the delayed |
| 549 // request. Should not crash. | 602 // request. Should not crash. |
| 550 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 603 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
| 551 Delayed_Resumed_ServiceShutdown) { | 604 Delayed_Resumed_ServiceShutdown) { |
| 552 SetExpectedHistogramCountOnTeardown(0); | 605 SetExpectedHistogramCountOnTeardown(0); |
| 553 | 606 |
| 554 certificate_reporting_test_utils::SetCertReportingOptIn( | 607 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 555 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 608 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 556 // Let all reports hang. | 609 // Let all reports hang. |
| 557 test_helper()->SetFailureMode( | 610 test_helper()->SetFailureMode( |
| 558 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 611 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
| 559 | 612 |
| 560 // Trigger a report that hangs. | 613 // Trigger a report that hangs. |
| 561 SendReport("report0"); | 614 SendReport("report0"); |
| 562 test_helper()->WaitForRequestsCreated( | 615 test_helper()->WaitForRequestsCreated( |
| 563 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 616 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 564 | 617 |
| 565 // Shutdown the service and resume the report upload. Shouldn't crash. | 618 // Shutdown the service and resume the report upload. Shouldn't crash. |
| 566 service()->Shutdown(); | 619 service()->Shutdown(); |
| 567 test_helper()->ResumeDelayedRequest(); | 620 test_helper()->ResumeDelayedRequest(); |
| 568 test_helper()->WaitForRequestsDestroyed( | 621 test_helper()->WaitForRequestsDestroyed( |
| 569 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 622 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
| 623 |
| 624 // report0 was submitted once and never completed since the service shut down. |
| 625 event_histogram_tester()->SetExpectedValues( |
| 626 1 /* submitted */, 0 /* failed */, 0 /* successful */, 0 /* dropped */); |
| 570 } | 627 } |
| 571 | 628 |
| 572 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting | 629 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting |
| 573 // service should clear its in-flight reports list. | 630 // service should clear its in-flight reports list. |
| 574 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { | 631 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { |
| 575 SetExpectedHistogramCountOnTeardown(0); | 632 SetExpectedHistogramCountOnTeardown(0); |
| 576 | 633 |
| 577 certificate_reporting_test_utils::SetCertReportingOptIn( | 634 certificate_reporting_test_utils::SetCertReportingOptIn( |
| 578 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 635 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
| 579 // Let all reports hang. | 636 // Let all reports hang. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 600 | 657 |
| 601 // Trigger a report that hangs. | 658 // Trigger a report that hangs. |
| 602 SendReport("report1"); | 659 SendReport("report1"); |
| 603 test_helper()->WaitForRequestsCreated( | 660 test_helper()->WaitForRequestsCreated( |
| 604 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); | 661 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 605 | 662 |
| 606 // Resume the delayed report and wait for it to complete. | 663 // Resume the delayed report and wait for it to complete. |
| 607 test_helper()->ResumeDelayedRequest(); | 664 test_helper()->ResumeDelayedRequest(); |
| 608 test_helper()->WaitForRequestsDestroyed( | 665 test_helper()->WaitForRequestsDestroyed( |
| 609 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); | 666 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); |
| 667 |
| 668 // report0 was submitted once and delayed, then cleared. |
| 669 // report1 was submitted once and delayed, then succeeded. |
| 670 event_histogram_tester()->SetExpectedValues( |
| 671 2 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */); |
| 610 } | 672 } |
| 611 | 673 |
| 612 } // namespace safe_browsing | 674 } // namespace safe_browsing |
| OLD | NEW |