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

Side by Side Diff: chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc

Issue 2503243003: Wire up CertificateReportingService to handle report uploads (Closed)
Patch Set: Rebase onto crrev/2543523002 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/safe_browsing/certificate_reporting_service.h"
6
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/macros.h"
10 #include "base/test/simple_test_clock.h"
11 #include "base/time/clock.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
15 #include "chrome/browser/safe_browsing/certificate_reporting_service_test_utils. h"
16 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h"
22 #include "components/prefs/pref_service.h"
23 #include "components/variations/variations_switches.h"
24 #include "content/public/browser/web_contents.h"
25 #include "content/public/test/browser_test_utils.h"
26 #include "content/public/test/test_utils.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "net/url_request/report_sender.h"
29 #include "net/url_request/url_request_context_getter.h"
30 #include "net/url_request/url_request_filter.h"
31 #include "net/url_request/url_request_test_util.h"
32
33 namespace {
34
35 void CleanUpOnIOThread() {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
37 net::URLRequestFilter::GetInstance()->ClearHandlers();
38 }
39
40 } // namespace
41
42 namespace safe_browsing {
43
44 class CertificateReportingServiceBrowserTest
45 : public InProcessBrowserTest,
46 public certificate_reporting_test_utils::
47 CertificateReportingServiceTestBase {
48 public:
49 CertificateReportingServiceBrowserTest()
50 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
51
52 void SetUpOnMainThread() override {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 SetUpInterceptor();
55
56 https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME);
57 https_server_.ServeFilesFromSourceDirectory("chrome/test/data");
58 ASSERT_TRUE(https_server_.Start());
59
60 InProcessBrowserTest::SetUpOnMainThread();
61 }
62
63 void TearDownOnMainThread() override {
64 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
65 base::Bind(&CleanUpOnIOThread));
66 }
67
68 void SetUpCommandLine(base::CommandLine* command_line) override {
69 command_line->AppendSwitchASCII(
70 switches::kForceFieldTrials,
71 "ReportCertificateErrors/ShowAndPossiblySend/");
72 // Setting the sending threshold to 1.0 ensures reporting is enabled.
73 command_line->AppendSwitchASCII(
74 variations::switches::kForceFieldTrialParams,
75 "ReportCertificateErrors.ShowAndPossiblySend:sendingThreshold/1.0");
76 }
77
78 protected:
79 CertificateReportingService* reporting_service() const {
80 return CertificateReportingServiceFactory::GetForBrowserContext(
81 browser()->profile());
82 }
83
84 // Navigates to an interstitial page and away from it to trigger a report and
85 // checks expected events
86 void SendReport(ObservedReportEvent expected_observed_event,
87 const std::set<int>& expected_successful_report_ids,
88 const std::set<int>& expected_failed_report_ids) {
89 // Navigate to a page with SSL error.
90 TabStripModel* tab_strip_model = browser()->tab_strip_model();
91 content::WebContents* contents = tab_strip_model->GetActiveWebContents();
92 const GURL kCertErrorURL = https_server_.GetURL("/");
93 ui_test_utils::NavigateToURL(browser(), kCertErrorURL);
94 content::WaitForInterstitialAttach(contents);
95
96 // Navigate away from the interstitial to trigger report upload and observe
97 // events: 1 event for send completion or cancellation, the rest for
98 // observed reports after send completion.
99 certificate_reporting_test_utils::ReportEventObserver* report_observer =
100 NewEventObserver(1u + expected_successful_report_ids.size() +
101 expected_failed_report_ids.size());
102 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
103 content::WaitForInterstitialDetach(contents);
104 report_observer->WaitForEvents();
105
106 EXPECT_NE(EXPECT_SERVICE_RESET, expected_observed_event);
107 CheckExpectedResults(*report_observer, expected_observed_event,
108 expected_successful_report_ids,
109 expected_failed_report_ids);
110 }
111
112 // Sends pending reports and checks expected events.
113 void SendPendingReports(ObservedReportEvent expected_observed_event,
114 const std::set<int>& expected_successful_report_ids,
115 const std::set<int>& expected_failed_report_ids) {
116 // Observe events: 1 event for send completion or cancellation,
117 // the rest for observed reports after send completion.
118 certificate_reporting_test_utils::ReportEventObserver* report_observer =
119 NewEventObserver(1u + expected_successful_report_ids.size() +
120 expected_failed_report_ids.size());
121 reporting_service()->SendPending();
122 report_observer->WaitForEvents();
123
124 EXPECT_NE(EXPECT_SERVICE_RESET, expected_observed_event);
125 CheckExpectedResults(*report_observer, expected_observed_event,
126 expected_successful_report_ids,
127 expected_failed_report_ids);
128 }
129
130 // Resumes delayed requests and checks expected events.
131 void ResumeDelayedRequests(
132 size_t num_expected_events,
133 const std::set<int>& expected_successful_report_ids,
134 const std::set<int>& expected_failed_report_ids) {
135 certificate_reporting_test_utils::ReportEventObserver* report_observer =
136 NewEventObserver(num_expected_events);
137 ResumeDelayedRequest();
138 report_observer->WaitForEvents();
139
140 CheckExpectedResults(*report_observer, EXPECT_NONE,
141 expected_successful_report_ids,
142 expected_failed_report_ids);
143 }
144
145 // Changes opt-in status and waits for the cert reporting service to reset.
146 // Can only be used after the service is initialized. When changing the
147 // value at the beginning of a test,
148 // certificate_reporting_test_utils::SetCertReportingOptIn should be used
149 // instead since the service is only created upon first SSL error.
150 void ChangeOptInAndWaitForServiceReset(
151 certificate_reporting_test_utils::OptIn opt_in) {
152 certificate_reporting_test_utils::ReportEventObserver* report_observer =
153 NewEventObserver(1);
154 certificate_reporting_test_utils::SetCertReportingOptIn(browser(), opt_in);
155 report_observer->WaitForEvents();
156
157 CheckExpectedResults(*report_observer, EXPECT_SERVICE_RESET,
158 std::set<int>(), std::set<int>());
159 }
160
161 // Same as ChangeOptInAndWaitForServiceReset, but enables/disables
162 // SafeBrowsing instead.
163 void ToggleSafeBrowsingAndWaitForServiceReset(bool safebrowsing_enabled) {
164 certificate_reporting_test_utils::ReportEventObserver* report_observer =
165 new certificate_reporting_test_utils::ReportEventObserver(1);
166 reporting_service()->SetEventObserverForTesting(
167 std::unique_ptr<CertificateReportingService::EventObserver>(
168 report_observer));
169 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
170 safebrowsing_enabled);
171 report_observer->WaitForEvents();
172
173 CheckExpectedResults(*report_observer, EXPECT_SERVICE_RESET,
174 std::set<int>(), std::set<int>());
175 }
176
177 private:
178 // Creates and sets a new event observer for the reporting service and
179 // returns it.
180 certificate_reporting_test_utils::ReportEventObserver* NewEventObserver(
181 int num_events_to_wait_for) {
182 certificate_reporting_test_utils::ReportEventObserver* observer =
183 new certificate_reporting_test_utils::ReportEventObserver(
184 num_events_to_wait_for);
185 reporting_service()->SetEventObserverForTesting(
186 std::unique_ptr<CertificateReportingService::EventObserver>(observer));
187 return observer;
188 }
189
190 net::EmbeddedTestServer https_server_;
191
192 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest);
193 };
194
195 // Tests that report send attempt should be cancelled when extended
196 // reporting is not opted in.
197 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
198 NotOptedIn_ShouldNotSendReports) {
199 certificate_reporting_test_utils::SetCertReportingOptIn(
200 browser(),
201 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
202 // Will wait for a single "attempt cancelled" event. No reports will be sent.
203 SendReport(EXPECT_SEND_ATTEMPT_CANCELLED,
204 std::set<int>() /* expected_successful_report_ids */,
205 std::set<int>() /* expected_failed_report_ids */);
206 }
207
208 // Tests that report send attempts are not cancelled when extended reporting is
209 // opted in. Goes to an interstitial page and navigates away to force a report
210 // send event.
211 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
212 OptedIn_ShouldSendSuccessfulReport) {
213 certificate_reporting_test_utils::SetCertReportingOptIn(
214 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
215
216 // Let reports uploads successfully complete.
217 SetFailureMode(certificate_reporting_test_utils::ReportSendingResult::
218 REPORTS_SUCCESSFUL);
219
220 // Send a report. Reporting is opted in, so the report sending attempt
221 // should not be cancelled and a report with id = 0 will be successfully sent.
222 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
223 std::set<int>{0} /* expected_successful_report_ids */,
224 std::set<int>() /* expected_failed_report_ids */);
225 }
226
227 // Tests that report send attempts are not cancelled when extended reporting is
228 // opted in. Goes to an interstitial page and navigate away to force a report
229 // send event. Repeats this three times and checks expected number of reports.
230 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
231 OptedIn_ShouldQueueFailedReport) {
232 certificate_reporting_test_utils::SetCertReportingOptIn(
233 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
234 // Let all reports fail.
235 SetFailureMode(
236 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
237
238 // Send a report. A report with id = 0 should be sent but sending fails.
239 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
240 std::set<int>() /* expected_successful_report_ids */,
241 std::set<int>{0} /* expected_failed_report_ids */);
242
243 // Another report with id = 1 should be sent but sending fails.
244 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
245 std::set<int>() /* expected_successful_report_ids */,
246 std::set<int>{1} /* expected_failed_report_ids */);
247
248 // Let all report uploads complete successfully now.
249 SetFailureMode(certificate_reporting_test_utils::ReportSendingResult::
250 REPORTS_SUCCESSFUL);
251
252 // Third time's the charm. Send another report. This time the report with
253 // id = 2 should be successfully sent.
254 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
255 std::set<int>{2} /* expected_successful_report_ids */,
256 std::set<int>() /* expected_failed_report_ids */);
257
258 // Send all pending reports. Sending pending reports counts as a single
259 // completed attempt. Two previously failed reports with ids 0 and 1 should
260 // have been queued, and now be sent successfully.
261 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
262 std::set<int>{0, 1} /* expected_successful_report_ids */,
263 std::set<int>() /* expected_failed_report_ids */);
264
265 // Try sending pending reports again. Since there is no pending report,
266 // nothing should be sent this time.
267 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
268 std::set<int>() /* expected_successful_report_ids */,
269 std::set<int>() /* expected_failed_report_ids */);
270 }
271
272 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
273 OptedIn_ThenOptedOut) {
274 certificate_reporting_test_utils::SetCertReportingOptIn(
275 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
276 // Let all reports fail.
277 SetFailureMode(
278 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
279
280 // Send a report. A report with id = 0 should be sent but sending fails.
281 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
282 std::set<int>() /* expected_successful_report_ids */,
283 std::set<int>{0} /* expected_failed_report_ids */);
284
285 // Disable reporting. This should reset the reporting service and
286 // clear all pending reports. Also clear reports observed by the url request
287 // interceptor.
288 ChangeOptInAndWaitForServiceReset(
289 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
290
291 // Send pending reports. A send pending event counts as a single attempt
292 // and it should be cancelled. No reports should be observed.
293 SendPendingReports(EXPECT_SEND_ATTEMPT_CANCELLED,
294 std::set<int>() /* expected_successful_report_ids */,
295 std::set<int>() /* expected_failed_report_ids */);
296 }
297
298 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
299 OptedOut_ThenOptedIn_ThenOptedOut) {
300 certificate_reporting_test_utils::SetCertReportingOptIn(
301 browser(),
302 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
303 // Let all reports fail.
304 SetFailureMode(
305 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
306
307 // Send attempt should be cancelled since reporting is opted out.
308 SendReport(EXPECT_SEND_ATTEMPT_CANCELLED,
309 std::set<int>() /* expected_successful_report_ids */,
310 std::set<int>() /* expected_failed_report_ids */);
311
312 // Enable reporting.
313 ChangeOptInAndWaitForServiceReset(
314 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
315
316 // A failed report should be observed.
317 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
318 std::set<int>() /* expected_successful_report_ids */,
319 std::set<int>{0} /* expected_failed_report_ids */);
320
321 // Disable reporting. This should reset the reporting service and
322 // clear all pending reports.
323 ChangeOptInAndWaitForServiceReset(
324 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN);
325
326 // The attempt should be cancelled since reporting is opted out.
327 SendReport(EXPECT_SEND_ATTEMPT_CANCELLED,
328 std::set<int>() /* expected_successful_report_ids */,
329 std::set<int>() /* expected_failed_report_ids */);
330
331 // Send pending reports. Nothing should be sent since there aren't any
332 // pending reports.
333 SendPendingReports(EXPECT_SEND_ATTEMPT_CANCELLED,
334 std::set<int>() /* expected_successful_report_ids */,
335 std::set<int>() /* expected_failed_report_ids */);
336 }
337
338 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
339 DisableSafebrowsing) {
340 certificate_reporting_test_utils::SetCertReportingOptIn(
341 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
342 // Let all reports fail.
343 SetFailureMode(
344 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
345
346 // Send a report. A report with id = 0 should be sent but sending fails.
347 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
348 std::set<int>() /* expected_successful_report_ids */,
349 std::set<int>{0} /* expected_failed_report_ids */);
350
351 // Disable SafeBrowsing. This should reset the reporting service and
352 // clear all pending reports. Also clear reports observed by the url request
353 // interceptor.
354 ToggleSafeBrowsingAndWaitForServiceReset(false);
355
356 // Send pending reports. A send pending event counts as a single attempt
357 // and it should be cancelled. No reports should be observed.
358 SendPendingReports(EXPECT_SEND_ATTEMPT_CANCELLED,
359 std::set<int>() /* expected_successful_report_ids */,
360 std::set<int>() /* expected_failed_report_ids */);
361
362 // Re-enable SafeBrowsing and trigger a report.
363 ToggleSafeBrowsingAndWaitForServiceReset(true);
364
365 // Navigate to and away from an interstitial to make sure a report send
366 // attempt is made. A report with id = 0 should be sent but sending fails.
367 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
368 std::set<int>() /* expected_successful_report_ids */,
369 std::set<int>{0} /* expected_failed_report_ids */);
370
371 // Reports should now be successfully sent.
372 SetFailureMode(certificate_reporting_test_utils::ReportSendingResult::
373 REPORTS_SUCCESSFUL);
374 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
375 std::set<int>{0} /* expected_successful_report_ids */,
376 std::set<int>() /* expected_failed_report_ids */);
377 }
378
379 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
380 DontSendOldReports) {
381 base::SimpleTestClock* clock = new base::SimpleTestClock();
382 base::Time reference_time = base::Time::Now();
383 clock->SetNow(reference_time);
384 reporting_service()->SetClockForTesting(clock);
385 // The service should ignore reports older than 24 hours.
386 reporting_service()->SetMaxReportAgeForTesting(
387 base::TimeDelta::FromHours(24));
388 certificate_reporting_test_utils::SetCertReportingOptIn(
389 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
390 // Let all reports fail.
391 SetFailureMode(
392 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
393
394 // Send a report.
395 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
396 std::set<int>() /* expected_successful_report_ids */,
397 std::set<int>{0} /* expected_failed_report_ids */);
398
399 // Advance the clock a bit and trigger another report.
400 // A report with id = 0 should be sent but sending fails.
401 clock->Advance(base::TimeDelta::FromHours(5));
402 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
403 std::set<int>() /* expected_successful_report_ids */,
404 std::set<int>{1} /* expected_failed_report_ids */);
405
406 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference
407 // time. This makes the first report with id = 0 older than max age (24
408 // hours). The second report is now 20 hours.
409 clock->Advance(base::TimeDelta::FromHours(20));
410 // Send pending reports. First report (id = 0) should be discarded since
411 // it's too old. Second report (id = 1) should be queued again.
412 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
413 std::set<int>() /* expected_successful_report_ids */,
414 std::set<int>{1} /* expected_failed_report_ids */);
415
416 // Trigger another failed report.
417 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
418 std::set<int>() /* expected_successful_report_ids */,
419 std::set<int>{2} /* expected_failed_report_ids */);
420
421 // Advance the clock 5 hours. The report with id = 1 will now be 25 hours old.
422 clock->Advance(base::TimeDelta::FromHours(5));
423 // Send pending reports. Report with id = 1 should be discarded since
424 // it's too old. Report with id = 2 should be queued again.
425 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
426 std::set<int>() /* expected_successful_report_ids */,
427 std::set<int>{2} /* expected_failed_report_ids */);
428
429 // Advance the clock 20 hours again so that the report with id = 2 is 25
430 // hours old and is older than max age (24 hours)
431 clock->Advance(base::TimeDelta::FromHours(20));
432 // Send pending reports. Report with id = 2 should be discarded since
433 // it's too old. No other reports remain.
434 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
435 std::set<int>() /* expected_successful_report_ids */,
436 std::set<int>() /* expected_failed_report_ids */);
437 }
438
439 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
440 DiscardOldReports) {
441 base::SimpleTestClock* clock = new base::SimpleTestClock();
442 base::Time reference_time = base::Time::Now();
443 clock->SetNow(reference_time);
444 reporting_service()->SetClockForTesting(clock);
445
446 certificate_reporting_test_utils::SetCertReportingOptIn(
447 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
448 // The service should queue a maximum of 3 reports and ignore reports older
449 // than 24 hours.
450 reporting_service()->SetMaxQueuedReportCountForTesting(3);
451 reporting_service()->SetMaxReportAgeForTesting(
452 base::TimeDelta::FromHours(24));
453 // Let all reports fail.
454 SetFailureMode(
455 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
456
457 // Trigger a failed report.
458 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
459 std::set<int>() /* expected_successful_report_ids */,
460 std::set<int>{0} /* expected_failed_report_ids */);
461
462 // Trigger three more reports within two hours of each other. After this:
463 // Report with id = 0 is 0 hours after reference time.
464 // Report with id = 1 is 5 hours after reference time.
465 // Report with id = 2 is 10 hours after reference time.
466 // Report with id = 3 is 15 hours after reference time.
467 for (size_t report_id = 1; report_id <= 3; report_id++) {
468 clock->Advance(base::TimeDelta::FromHours(5));
469 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
470 std::set<int>(), /* expected_successful_report_ids */
471 std::set<int>{report_id} /* expected_failed_report_ids */);
472 }
473
474 // Send pending reports. Four reports were generated above, but the service
475 // only queues three reports, so the very first one should be dropped since
476 // it's the oldest.
477 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
478 std::set<int>() /* expected_successful_report_ids */,
479 std::set<int>{1, 2, 3} /* expected_failed_report_ids */);
480
481 // Let all reports succeed.
482 SetFailureMode(
483 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
484
485 // Advance clock to 15 hours. The current time is now 30 hours after
486 // reference time. The ages of reports are now as follows:
487 // Report with id = 1 is 25 hours old.
488 // Report with id = 2 is 20 hours old.
489 // Report with id = 3 is 15 hours old.
490 clock->Advance(base::TimeDelta::FromHours(15));
491 // Send pending reports. Only reports 2 and 3 should be sent, report 1
492 // should be ignored because it's too old.
493 SendPendingReports(EXPECT_SEND_ATTEMPT_COMPLETED,
494 std::set<int>() /* expected_successful_report_ids */,
495 std::set<int>{2, 3} /* expected_failed_report_ids */);
496 }
497
498 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
499 Delayed_NotResumed_ShouldNotCrash) {
500 certificate_reporting_test_utils::SetCertReportingOptIn(
501 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
502 // Let all reports fail.
503 SetFailureMode(
504 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
505
506 // Navigate to and away from an interstitial to trigger a report. The report
507 // is triggered but hangs, so no error or success callbacks should be called.
508 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
509 std::set<int>() /* expected_successful_report_ids */,
510 std::set<int>() /* expected_failed_report_ids */);
511 }
512
513 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
514 Delayed_Resumed) {
515 certificate_reporting_test_utils::SetCertReportingOptIn(
516 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
517 // Let all reports fail.
518 SetFailureMode(
519 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
520
521 // Navigate to and away from an interstitial to trigger a report. The
522 // report is triggered but hangs, so no error or success callbacks should be
523 // called.
524 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
525 std::set<int>() /* expected_successful_report_ids */,
526 std::set<int>() /* expected_failed_report_ids */);
527
528 // Resume the report upload and run the callbacks. The report should be
529 // successfully sent.
530 ResumeDelayedRequests(1 /* num_expected_events */,
531 std::set<int>{0} /* expected_successful_report_ids */,
532 std::set<int>() /* expected_failed_report_ids */);
533 }
534
535 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) {
536 certificate_reporting_test_utils::SetCertReportingOptIn(
537 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN);
538 // Let all reports fail.
539 SetFailureMode(
540 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY);
541
542 // Navigate to and away from an interstitial to trigger a report. The
543 // report
544 // is triggered but hangs, so no error or success callbacks should be
545 // called.
546 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
547 std::set<int>() /* expected_successful_report_ids */,
548 std::set<int>() /* expected_failed_report_ids */);
549
550 // Disable SafeBrowsing. This should reset the reporting service and
551 // clear all pending reports.
552 ToggleSafeBrowsingAndWaitForServiceReset(false);
553
554 // Resume delayed report. No response should be observed since the service
555 // should have reset and all pending reports should be cleared.
556 ResumeDelayedRequests(0u /* num_expected_events */,
557 std::set<int>() /* expected_successful_report_ids */,
558 std::set<int>() /* expected_failed_report_ids */);
559
560 ToggleSafeBrowsingAndWaitForServiceReset(true);
561
562 // Navigate to and away from an interstitial to trigger a report. The report
563 // is triggered but hangs, so no error or success callbacks should be called.
564 SendReport(EXPECT_SEND_ATTEMPT_COMPLETED,
565 std::set<int>() /* expected_successful_report_ids */,
566 std::set<int>() /* expected_failed_report_ids */);
567
568 // Resume delayed report. The report should be observed.
569 ResumeDelayedRequests(1u /* num_expected_events */,
570 std::set<int>{0} /* expected_successful_report_ids */,
571 std::set<int>() /* expected_failed_report_ids */);
572 }
573
574 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698