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