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 // 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_; |
203 | 217 |
204 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); | 218 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); |
205 }; | 219 }; |
206 | 220 |
207 // Tests that report send attempt should be cancelled when extended | 221 // Tests that report send attempt should be cancelled when extended |
208 // reporting is not opted in. | 222 // reporting is not opted in. |
209 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 223 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
210 NotOptedIn_ShouldNotSendReports) { | 224 NotOptedIn_ShouldNotSendReports) { |
211 SetExpectedHistogramCountOnTeardown(0); | 225 SetExpectedHistogramCountOnTeardown(0); |
212 | 226 |
213 certificate_reporting_test_utils::SetCertReportingOptIn( | 227 certificate_reporting_test_utils::SetCertReportingOptIn( |
214 browser(), | 228 browser(), |
215 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 229 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
216 // Send a report. Test teardown checks for created and in-flight requests. If | 230 // Send a report. Test teardown checks for created and in-flight requests. If |
217 // a report was incorrectly sent, the test will fail. | 231 // a report was incorrectly sent, the test will fail. |
218 SendReport("no-report"); | 232 SendReport("no-report"); |
| 233 |
| 234 event_histogram_tester()->SetExpectedValues(0, 0, 0, 0); |
219 } | 235 } |
220 | 236 |
221 // Tests that report send attempts are not cancelled when extended reporting is | 237 // 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 | 238 // opted in. Goes to an interstitial page and navigates away to force a report |
223 // send event. | 239 // send event. |
224 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 240 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
225 OptedIn_ShouldSendSuccessfulReport) { | 241 OptedIn_ShouldSendSuccessfulReport) { |
226 SetExpectedHistogramCountOnTeardown(0); | 242 SetExpectedHistogramCountOnTeardown(0); |
227 | 243 |
228 certificate_reporting_test_utils::SetCertReportingOptIn( | 244 certificate_reporting_test_utils::SetCertReportingOptIn( |
229 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 245 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
230 | 246 |
231 // Let reports uploads successfully complete. | 247 // Let reports uploads successfully complete. |
232 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 248 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
233 ReportSendingResult::REPORTS_SUCCESSFUL); | 249 ReportSendingResult::REPORTS_SUCCESSFUL); |
234 | 250 |
235 // Reporting is opted in, so the report should succeed. | 251 // Reporting is opted in, so the report should succeed. |
236 SendReport("report0"); | 252 SendReport("report0"); |
237 test_helper()->WaitForRequestsDestroyed( | 253 test_helper()->WaitForRequestsDestroyed( |
238 ReportExpectation::Successful({{"report0", RetryStatus::NOT_RETRIED}})); | 254 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 */); |
239 } | 259 } |
240 | 260 |
241 // Tests that report send attempts are not cancelled when extended reporting is | 261 // 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 | 262 // 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. | 263 // send event. Repeats this three times and checks expected number of reports. |
244 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 264 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
245 OptedIn_ShouldQueueFailedReport) { | 265 OptedIn_ShouldQueueFailedReport) { |
246 SetExpectedHistogramCountOnTeardown(2); | 266 SetExpectedHistogramCountOnTeardown(2); |
247 | 267 |
248 certificate_reporting_test_utils::SetCertReportingOptIn( | 268 certificate_reporting_test_utils::SetCertReportingOptIn( |
(...skipping 24 matching lines...) Expand all Loading... |
273 // Send all pending reports. The two previously failed reports should have | 293 // Send all pending reports. The two previously failed reports should have |
274 // been queued, and now be sent successfully. | 294 // been queued, and now be sent successfully. |
275 SendPendingReports(); | 295 SendPendingReports(); |
276 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( | 296 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( |
277 {{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}})); | 297 {{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}})); |
278 | 298 |
279 // Try sending pending reports again. Since there is no pending report, | 299 // 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 | 300 // nothing should be sent this time. If any report is sent, test teardown |
281 // will catch it. | 301 // will catch it. |
282 SendPendingReports(); | 302 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 */); |
283 } | 309 } |
284 | 310 |
285 // Opting in then opting out of extended reporting should clear the pending | 311 // Opting in then opting out of extended reporting should clear the pending |
286 // report queue. | 312 // report queue. |
287 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 313 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
288 OptedIn_ThenOptedOut) { | 314 OptedIn_ThenOptedOut) { |
289 SetExpectedHistogramCountOnTeardown(1); | 315 SetExpectedHistogramCountOnTeardown(1); |
290 | 316 |
291 certificate_reporting_test_utils::SetCertReportingOptIn( | 317 certificate_reporting_test_utils::SetCertReportingOptIn( |
292 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 318 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
293 // Let all reports fail. | 319 // Let all reports fail. |
294 test_helper()->SetFailureMode( | 320 test_helper()->SetFailureMode( |
295 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 321 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
296 | 322 |
297 // Send a failed report. | 323 // Send a failed report. |
298 SendReport("report0"); | 324 SendReport("report0"); |
299 test_helper()->WaitForRequestsDestroyed( | 325 test_helper()->WaitForRequestsDestroyed( |
300 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); | 326 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
301 | 327 |
302 // Disable reporting. This should clear all pending reports. | 328 // Disable reporting. This should clear all pending reports. |
303 ChangeOptInAndWait( | 329 ChangeOptInAndWait( |
304 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 330 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
305 | 331 |
306 // Send pending reports. No reports should be observed during test teardown. | 332 // Send pending reports. No reports should be observed during test teardown. |
307 SendPendingReports(); | 333 SendPendingReports(); |
| 334 |
| 335 // report0 was submitted once and failed once. |
| 336 event_histogram_tester()->SetExpectedValues( |
| 337 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */); |
308 } | 338 } |
309 | 339 |
310 // Opting out, then in, then out of extended reporting should work as expected. | 340 // Opting out, then in, then out of extended reporting should work as expected. |
311 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 341 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
312 OptedOut_ThenOptedIn_ThenOptedOut) { | 342 OptedOut_ThenOptedIn_ThenOptedOut) { |
313 SetExpectedHistogramCountOnTeardown(1); | 343 SetExpectedHistogramCountOnTeardown(1); |
314 | 344 |
315 certificate_reporting_test_utils::SetCertReportingOptIn( | 345 certificate_reporting_test_utils::SetCertReportingOptIn( |
316 browser(), | 346 browser(), |
317 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 347 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
(...skipping 19 matching lines...) Expand all Loading... |
337 ChangeOptInAndWait( | 367 ChangeOptInAndWait( |
338 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 368 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
339 | 369 |
340 // Report should be cancelled since reporting is opted out. | 370 // Report should be cancelled since reporting is opted out. |
341 SendReport("report1"); | 371 SendReport("report1"); |
342 test_helper()->ExpectNoRequests(service()); | 372 test_helper()->ExpectNoRequests(service()); |
343 | 373 |
344 // Send pending reports. Nothing should be sent since there aren't any | 374 // 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. | 375 // pending reports. If any report is sent, test teardown will catch it. |
346 SendPendingReports(); | 376 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 */); |
347 } | 382 } |
348 | 383 |
349 // Disabling SafeBrowsing should clear pending reports queue in | 384 // Disabling SafeBrowsing should clear pending reports queue in |
350 // CertificateReportingService. | 385 // CertificateReportingService. |
351 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 386 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
352 DisableSafebrowsing) { | 387 DisableSafebrowsing) { |
353 SetExpectedHistogramCountOnTeardown(2); | 388 SetExpectedHistogramCountOnTeardown(2); |
354 | 389 |
355 certificate_reporting_test_utils::SetCertReportingOptIn( | 390 certificate_reporting_test_utils::SetCertReportingOptIn( |
356 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 391 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
357 // Let all reports fail. | 392 // Let all reports fail. |
358 test_helper()->SetFailureMode( | 393 test_helper()->SetFailureMode( |
359 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 394 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
360 | 395 |
361 // Send a delayed report. | 396 // Send a report. |
362 SendReport("report0"); | 397 SendReport("report0"); |
363 test_helper()->WaitForRequestsDestroyed( | 398 test_helper()->WaitForRequestsDestroyed( |
364 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); | 399 ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}})); |
365 | 400 |
366 // Disable SafeBrowsing. This should clear all pending reports. | 401 // Disable SafeBrowsing. This should clear all pending reports. |
367 ToggleSafeBrowsingAndWaitForServiceReset(false); | 402 ToggleSafeBrowsingAndWaitForServiceReset(false); |
368 | 403 |
369 // Send pending reports. No reports should be observed. | 404 // Send pending reports. No reports should be observed. |
370 SendPendingReports(); | 405 SendPendingReports(); |
371 test_helper()->ExpectNoRequests(service()); | 406 test_helper()->ExpectNoRequests(service()); |
372 | 407 |
373 // Re-enable SafeBrowsing and trigger another report which will be queued. | 408 // Re-enable SafeBrowsing and trigger another report which will be queued. |
374 ToggleSafeBrowsingAndWaitForServiceReset(true); | 409 ToggleSafeBrowsingAndWaitForServiceReset(true); |
375 SendReport("report1"); | 410 SendReport("report1"); |
376 test_helper()->WaitForRequestsDestroyed( | 411 test_helper()->WaitForRequestsDestroyed( |
377 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); | 412 ReportExpectation::Failed({{"report1", RetryStatus::NOT_RETRIED}})); |
378 | 413 |
379 // Queued report should now be successfully sent. | 414 // Queued report should now be successfully sent. |
380 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 415 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
381 ReportSendingResult::REPORTS_SUCCESSFUL); | 416 ReportSendingResult::REPORTS_SUCCESSFUL); |
382 SendPendingReports(); | 417 SendPendingReports(); |
383 test_helper()->WaitForRequestsDestroyed( | 418 test_helper()->WaitForRequestsDestroyed( |
384 ReportExpectation::Successful({{"report1", RetryStatus::RETRIED}})); | 419 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 */); |
385 } | 425 } |
386 | 426 |
387 // CertificateReportingService should ignore reports older than the report TTL. | 427 // CertificateReportingService should ignore reports older than the report TTL. |
388 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 428 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
389 DontSendOldReports) { | 429 DontSendOldReports) { |
390 SetExpectedHistogramCountOnTeardown(5); | 430 SetExpectedHistogramCountOnTeardown(5); |
391 | 431 |
392 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 432 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
393 base::Time reference_time = base::Time::Now(); | 433 base::Time reference_time = base::Time::Now(); |
394 clock->SetNow(reference_time); | 434 clock->SetNow(reference_time); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 test_helper()->WaitForRequestsDestroyed( | 479 test_helper()->WaitForRequestsDestroyed( |
440 ReportExpectation::Failed({{"report2", RetryStatus::RETRIED}})); | 480 ReportExpectation::Failed({{"report2", RetryStatus::RETRIED}})); |
441 | 481 |
442 // Advance the clock 20 hours again so that report2 is 25 hours old and is | 482 // Advance the clock 20 hours again so that report2 is 25 hours old and is |
443 // older than max age (24 hours). | 483 // older than max age (24 hours). |
444 clock->Advance(base::TimeDelta::FromHours(20)); | 484 clock->Advance(base::TimeDelta::FromHours(20)); |
445 | 485 |
446 // Send pending reports. report2 should be discarded since it's too old. No | 486 // 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. | 487 // other reports remain. If any report is sent, test teardown will catch it. |
448 SendPendingReports(); | 488 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 */); |
449 } | 495 } |
450 | 496 |
451 // CertificateReportingService should drop old reports from its pending report | 497 // CertificateReportingService should drop old reports from its pending report |
452 // queue, if the queue is full. | 498 // queue, if the queue is full. |
453 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 499 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
454 DropOldReportsFromQueue) { | 500 DropOldReportsFromQueue) { |
455 SetExpectedHistogramCountOnTeardown(7); | 501 SetExpectedHistogramCountOnTeardown(7); |
456 | 502 |
457 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 503 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
458 base::Time reference_time = base::Time::Now(); | 504 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. | 559 // report1 is 25 hours old. |
514 // report2 is 20 hours old. | 560 // report2 is 20 hours old. |
515 // report3 is 15 hours old. | 561 // report3 is 15 hours old. |
516 clock->Advance(base::TimeDelta::FromHours(15)); | 562 clock->Advance(base::TimeDelta::FromHours(15)); |
517 | 563 |
518 // Send pending reports. Only reports 2 and 3 should be sent, report 1 | 564 // Send pending reports. Only reports 2 and 3 should be sent, report 1 |
519 // should be ignored because it's too old. | 565 // should be ignored because it's too old. |
520 SendPendingReports(); | 566 SendPendingReports(); |
521 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( | 567 test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful( |
522 {{"report2", RetryStatus::RETRIED}, {"report3", RetryStatus::RETRIED}})); | 568 {{"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 */); |
523 } | 576 } |
524 | 577 |
525 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 578 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
526 Delayed_Resumed) { | 579 Delayed_Resumed) { |
527 SetExpectedHistogramCountOnTeardown(0); | 580 SetExpectedHistogramCountOnTeardown(0); |
528 | 581 |
529 certificate_reporting_test_utils::SetCertReportingOptIn( | 582 certificate_reporting_test_utils::SetCertReportingOptIn( |
530 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 583 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
531 // Let all reports hang. | 584 // Let all reports hang. |
532 test_helper()->SetFailureMode( | 585 test_helper()->SetFailureMode( |
533 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 586 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
534 | 587 |
535 // Trigger a report that hangs. | 588 // Trigger a report that hangs. |
536 SendReport("report0"); | 589 SendReport("report0"); |
537 test_helper()->WaitForRequestsCreated( | 590 test_helper()->WaitForRequestsCreated( |
538 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 591 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
539 | 592 |
540 // Resume the report upload. The report upload should successfully complete. | 593 // Resume the report upload. The report upload should successfully complete. |
541 // The interceptor only observes request creations and not response | 594 // The interceptor only observes request creations and not response |
542 // completions, so there is nothing to observe. | 595 // completions, so there is nothing to observe. |
543 test_helper()->ResumeDelayedRequest(); | 596 test_helper()->ResumeDelayedRequest(); |
544 test_helper()->WaitForRequestsDestroyed( | 597 test_helper()->WaitForRequestsDestroyed( |
545 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 598 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 */); |
546 } | 603 } |
547 | 604 |
548 // Same as above, but the service is shut down before resuming the delayed | 605 // Same as above, but the service is shut down before resuming the delayed |
549 // request. Should not crash. | 606 // request. Should not crash. |
550 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 607 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
551 Delayed_Resumed_ServiceShutdown) { | 608 Delayed_Resumed_ServiceShutdown) { |
552 SetExpectedHistogramCountOnTeardown(0); | 609 SetExpectedHistogramCountOnTeardown(0); |
553 | 610 |
554 certificate_reporting_test_utils::SetCertReportingOptIn( | 611 certificate_reporting_test_utils::SetCertReportingOptIn( |
555 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 612 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
556 // Let all reports hang. | 613 // Let all reports hang. |
557 test_helper()->SetFailureMode( | 614 test_helper()->SetFailureMode( |
558 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 615 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
559 | 616 |
560 // Trigger a report that hangs. | 617 // Trigger a report that hangs. |
561 SendReport("report0"); | 618 SendReport("report0"); |
562 test_helper()->WaitForRequestsCreated( | 619 test_helper()->WaitForRequestsCreated( |
563 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 620 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); |
564 | 621 |
565 // Shutdown the service and resume the report upload. Shouldn't crash. | 622 // Shutdown the service and resume the report upload. Shouldn't crash. |
566 service()->Shutdown(); | 623 service()->Shutdown(); |
567 test_helper()->ResumeDelayedRequest(); | 624 test_helper()->ResumeDelayedRequest(); |
568 test_helper()->WaitForRequestsDestroyed( | 625 test_helper()->WaitForRequestsDestroyed( |
569 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}})); | 626 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 */); |
570 } | 631 } |
571 | 632 |
572 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting | 633 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting |
573 // service should clear its in-flight reports list. | 634 // service should clear its in-flight reports list. |
574 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { | 635 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { |
575 SetExpectedHistogramCountOnTeardown(0); | 636 SetExpectedHistogramCountOnTeardown(0); |
576 | 637 |
577 certificate_reporting_test_utils::SetCertReportingOptIn( | 638 certificate_reporting_test_utils::SetCertReportingOptIn( |
578 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 639 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
579 // Let all reports hang. | 640 // Let all reports hang. |
(...skipping 20 matching lines...) Expand all Loading... |
600 | 661 |
601 // Trigger a report that hangs. | 662 // Trigger a report that hangs. |
602 SendReport("report1"); | 663 SendReport("report1"); |
603 test_helper()->WaitForRequestsCreated( | 664 test_helper()->WaitForRequestsCreated( |
604 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); | 665 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); |
605 | 666 |
606 // Resume the delayed report and wait for it to complete. | 667 // Resume the delayed report and wait for it to complete. |
607 test_helper()->ResumeDelayedRequest(); | 668 test_helper()->ResumeDelayedRequest(); |
608 test_helper()->WaitForRequestsDestroyed( | 669 test_helper()->WaitForRequestsDestroyed( |
609 ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}})); | 670 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 */); |
610 } | 676 } |
611 | 677 |
612 } // namespace safe_browsing | 678 } // namespace safe_browsing |
OLD | NEW |