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 18 matching lines...) Expand all Loading... |
29 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
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::ReportExpectation; | 40 using certificate_reporting_test_utils::ReportExpectation; |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; | 44 const char* kFailedReportHistogram = "SSL.CertificateErrorReportFailure"; |
44 | 45 |
45 void CleanUpOnIOThread() { | 46 void CleanUpOnIOThread() { |
46 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 47 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
47 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 48 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
48 } | 49 } |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 namespace safe_browsing { | 53 namespace safe_browsing { |
53 | 54 |
54 // These tests check the whole mechanism to send and queue invalid certificate | 55 // These tests check the whole mechanism to send and queue invalid certificate |
55 // reports. Each test triggers reports by visiting broken SSL pages. The reports | 56 // reports. Each test triggers reports by visiting broken SSL pages. The reports |
56 // succeed, fail or hang indefinitely. The test waits for the URL requests | 57 // succeed, fail or hang indefinitely: |
57 // corresponding to the reports to to be created via the URL request | 58 // - If a report is expected to fail or succeed, the test waits for the |
58 // interceptor. When reports are expected to succeed or fail, test teardown | 59 // corresponding URL request jobs to be destroyed. |
59 // checks that there are no in-flight or pending reports in the | 60 // - If a report is expected to hang, the test waits for the corresponding URL |
60 // CertificateReportingService queue. When a report is to be delayed, a single | 61 // request job to be created. Only after resuming the hung request job the |
61 // in-flight report is expected in CertificateReportingService. Since the actual | 62 // test waits for the request to be destroyed. |
62 // URL requests for reports are sent from the IO thread, the tests wait for the | |
63 // IO thread to finish before checking the expected report counts. | |
64 // | |
65 // Note that these browser tests differ from the unit tests in how they check | |
66 // expected reports: Unit tests create a network delegate and observe the | |
67 // destruction of the URL requests, whereas browser tests wait for the URL | |
68 // requests to be created instead. | |
69 class CertificateReportingServiceBrowserTest : public InProcessBrowserTest { | 63 class CertificateReportingServiceBrowserTest : public InProcessBrowserTest { |
70 public: | 64 public: |
71 CertificateReportingServiceBrowserTest() | 65 CertificateReportingServiceBrowserTest() |
72 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS), | 66 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} |
73 expect_delayed_report_on_teardown_(false) {} | |
74 | 67 |
75 void SetUpOnMainThread() override { | 68 void SetUpOnMainThread() override { |
76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
77 host_resolver()->AddRule("*", "127.0.0.1"); | 70 host_resolver()->AddRule("*", "127.0.0.1"); |
78 | 71 |
79 https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 72 https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
80 https_server_.ServeFilesFromSourceDirectory("chrome/test/data"); | 73 https_server_.ServeFilesFromSourceDirectory("chrome/test/data"); |
81 ASSERT_TRUE(https_server_.Start()); | 74 ASSERT_TRUE(https_server_.Start()); |
82 | 75 |
83 test_helper_.SetUpInterceptor(); | 76 test_helper()->SetUpInterceptor(); |
84 | 77 |
85 CertificateReportingServiceFactory::GetInstance() | 78 CertificateReportingServiceFactory::GetInstance() |
86 ->SetReportEncryptionParamsForTesting( | 79 ->SetReportEncryptionParamsForTesting( |
87 test_helper_.server_public_key(), | 80 test_helper()->server_public_key(), |
88 test_helper_.server_public_key_version()); | 81 test_helper()->server_public_key_version()); |
| 82 CertificateReportingServiceFactory::GetInstance() |
| 83 ->SetServiceResetCallbackForTesting( |
| 84 base::Bind(&CertificateReportingServiceObserver::OnServiceReset, |
| 85 base::Unretained(&service_observer_))); |
89 InProcessBrowserTest::SetUpOnMainThread(); | 86 InProcessBrowserTest::SetUpOnMainThread(); |
90 } | 87 } |
91 | 88 |
92 void TearDownOnMainThread() override { | 89 void TearDownOnMainThread() override { |
93 CheckExpectedReportCounts(expect_delayed_report_on_teardown_); | 90 test_helper()->ExpectNoRequests(service()); |
94 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 91 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
95 base::Bind(&CleanUpOnIOThread)); | 92 base::Bind(&CleanUpOnIOThread)); |
| 93 EXPECT_GE(num_expected_failed_report_, 0) |
| 94 << "Don't forget to set expected failed report count."; |
96 // Check the histogram as the last thing. This makes sure no in-flight | 95 // Check the histogram as the last thing. This makes sure no in-flight |
97 // report is missed. | 96 // report is missed. |
98 if (num_expected_failed_report_ != 0) { | 97 if (num_expected_failed_report_ != 0) { |
99 histogram_tester_.ExpectUniqueSample(kFailedReportHistogram, | 98 histogram_tester_.ExpectUniqueSample(kFailedReportHistogram, |
100 -net::ERR_SSL_PROTOCOL_ERROR, | 99 -net::ERR_SSL_PROTOCOL_ERROR, |
101 num_expected_failed_report_); | 100 num_expected_failed_report_); |
102 } else { | 101 } else { |
103 histogram_tester_.ExpectTotalCount(kFailedReportHistogram, 0); | 102 histogram_tester_.ExpectTotalCount(kFailedReportHistogram, 0); |
104 } | 103 } |
105 } | 104 } |
(...skipping 25 matching lines...) Expand all Loading... |
131 | 130 |
132 // Navigate to the page with SSL error. | 131 // Navigate to the page with SSL error. |
133 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 132 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
134 content::WebContents* contents = tab_strip_model->GetActiveWebContents(); | 133 content::WebContents* contents = tab_strip_model->GetActiveWebContents(); |
135 ui_test_utils::NavigateToURL(browser(), kCertErrorURL); | 134 ui_test_utils::NavigateToURL(browser(), kCertErrorURL); |
136 content::WaitForInterstitialAttach(contents); | 135 content::WaitForInterstitialAttach(contents); |
137 | 136 |
138 // Navigate away from the interstitial to trigger report upload. | 137 // Navigate away from the interstitial to trigger report upload. |
139 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 138 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
140 content::WaitForInterstitialDetach(contents); | 139 content::WaitForInterstitialDetach(contents); |
141 WaitForIOThread(); | |
142 } | 140 } |
143 | 141 |
144 void SendPendingReports() { service()->SendPending(); } | 142 void SendPendingReports() { service()->SendPending(); } |
145 | 143 |
146 // Checks that there are no outstanding reports. | |
147 // If |expect_delayed_report_on_teardown| is true, expects a single delayed | |
148 // report. | |
149 void CheckNoReports() { CheckExpectedReportCounts(false); } | |
150 | |
151 // Changes opt-in status and waits for the cert reporting service to reset. | 144 // Changes opt-in status and waits for the cert reporting service to reset. |
152 // Can only be used after the service is initialized. When changing the | 145 // Can only be used after the service is initialized. When changing the |
153 // value at the beginning of a test, | 146 // value at the beginning of a test, |
154 // certificate_reporting_test_utils::SetCertReportingOptIn should be used | 147 // certificate_reporting_test_utils::SetCertReportingOptIn should be used |
155 // instead since the service is only created upon first SSL error. | 148 // instead since the service is only created upon first SSL error. |
156 // Changing the opt-in status synchronously fires | 149 // Changing the opt-in status synchronously fires |
157 // CertificateReportingService::PreferenceObserver::OnPreferenceChanged which | 150 // CertificateReportingService::PreferenceObserver::OnPreferenceChanged which |
158 // will call CertificateReportingService::SetEnabled() which in turn posts | 151 // will call CertificateReportingService::SetEnabled() which in turn posts |
159 // a task to the IO thread to reset the service. Waiting for the IO thread | 152 // a task to the IO thread to reset the service. Waiting for the IO thread |
160 // ensures that the service is reset before returning from this method. | 153 // ensures that the service is reset before returning from this method. |
161 void ChangeOptInAndWait(certificate_reporting_test_utils::OptIn opt_in) { | 154 void ChangeOptInAndWait(certificate_reporting_test_utils::OptIn opt_in) { |
| 155 service_observer_.Clear(); |
162 certificate_reporting_test_utils::SetCertReportingOptIn(browser(), opt_in); | 156 certificate_reporting_test_utils::SetCertReportingOptIn(browser(), opt_in); |
163 WaitForIOThread(); | 157 service_observer_.WaitForReset(); |
164 } | 158 } |
165 | 159 |
166 // Same as ChangeOptInAndWait, but enables/disables SafeBrowsing instead. | 160 // Same as ChangeOptInAndWait, but enables/disables SafeBrowsing instead. |
167 void ToggleSafeBrowsingAndWaitForServiceReset(bool safebrowsing_enabled) { | 161 void ToggleSafeBrowsingAndWaitForServiceReset(bool safebrowsing_enabled) { |
| 162 service_observer_.Clear(); |
168 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 163 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
169 safebrowsing_enabled); | 164 safebrowsing_enabled); |
170 WaitForIOThread(); | 165 service_observer_.WaitForReset(); |
171 } | 166 } |
172 | 167 |
173 void ShutdownServiceAndWait() { | 168 void SetExpectedHistogramCountOnTeardown(int num_expected_failed_report) { |
174 service()->Shutdown(); | |
175 WaitForIOThread(); | |
176 } | |
177 | |
178 // Waits for a number of URL requests to be created for the reports in | |
179 // |expectation| and checks that the reports in |expectation| matches the | |
180 // reports observed by URL request interceptor. | |
181 void WaitForReports(const ReportExpectation& expectation) { | |
182 test_helper_.interceptor()->WaitForReports(expectation.num_reports()); | |
183 std::set<std::string> expected_hostnames; | |
184 CheckReports(expectation.successful_reports, | |
185 test_helper_.interceptor()->successful_reports()); | |
186 CheckReports(expectation.failed_reports, | |
187 test_helper_.interceptor()->failed_reports()); | |
188 CheckReports(expectation.delayed_reports, | |
189 test_helper_.interceptor()->delayed_reports()); | |
190 test_helper_.interceptor()->ClearObservedReports(); | |
191 } | |
192 | |
193 // Resumes the delayed request and waits for the resume task to complete which | |
194 // in turn means the response starts. | |
195 void ResumeDelayedRequestAndWait() { | |
196 base::RunLoop run_loop; | |
197 test_helper_.ResumeDelayedRequest(run_loop.QuitClosure()); | |
198 run_loop.Run(); | |
199 } | |
200 | |
201 // Tells the test to expect a delayed report during test teardown. If not set, | |
202 // the tests expect no in-flight reports during teardown. | |
203 void SetExpectDelayedReportOnTeardown() { | |
204 expect_delayed_report_on_teardown_ = true; | |
205 } | |
206 | |
207 void SetExpectedHistogramCountOnTeardown( | |
208 unsigned int num_expected_failed_report) { | |
209 num_expected_failed_report_ = num_expected_failed_report; | 169 num_expected_failed_report_ = num_expected_failed_report; |
210 } | 170 } |
211 | 171 |
212 private: | |
213 CertificateReportingService* service() const { | 172 CertificateReportingService* service() const { |
214 return CertificateReportingServiceFactory::GetForBrowserContext( | 173 return CertificateReportingServiceFactory::GetForBrowserContext( |
215 browser()->profile()); | 174 browser()->profile()); |
216 } | 175 } |
217 | 176 |
218 // Waits for pending tasks on the IO thread to complete. | 177 private: |
219 void WaitForIOThread() { | |
220 scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper( | |
221 content::BrowserThread::GetTaskRunnerForThread( | |
222 content::BrowserThread::IO) | |
223 .get())); | |
224 ASSERT_TRUE(io_helper->Run()); | |
225 } | |
226 | |
227 // Checks that the serialized reports in |received_reports| have the same | 178 // Checks that the serialized reports in |received_reports| have the same |
228 // hostnames as |expected_hostnames|. | 179 // hostnames as |expected_hostnames|. |
229 void CheckReports(const std::set<std::string>& expected_hostnames, | 180 void CheckReports(const std::set<std::string>& expected_hostnames, |
230 const std::set<std::string>& received_reports) { | 181 const std::set<std::string>& received_reports, |
| 182 const std::string type) { |
231 std::set<std::string> received_hostnames; | 183 std::set<std::string> received_hostnames; |
232 for (const std::string& serialized_report : received_reports) { | 184 for (const std::string& serialized_report : received_reports) { |
233 certificate_reporting::ErrorReport report; | 185 certificate_reporting::ErrorReport report; |
234 ASSERT_TRUE(report.InitializeFromString(serialized_report)); | 186 ASSERT_TRUE(report.InitializeFromString(serialized_report)); |
235 received_hostnames.insert(report.hostname()); | 187 received_hostnames.insert(report.hostname()); |
236 } | 188 } |
237 EXPECT_EQ(expected_hostnames, received_hostnames); | 189 EXPECT_EQ(expected_hostnames, received_hostnames) << type |
238 } | 190 << " comparison failed"; |
239 | |
240 // Checks that there are no remaining successful and failed reports observed | |
241 // by the interceptor. If |expect_delayed_report| is true, expects a single | |
242 // delayed report. Otherwise, expects no delayed reports. | |
243 void CheckExpectedReportCounts(bool expect_delayed_report) { | |
244 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
245 // Wait for the IO thread to ensure that any report-sending tasks previously | |
246 // posted to the IO thread hav run (and thus been observed by the | |
247 // interceptor). | |
248 WaitForIOThread(); | |
249 EXPECT_TRUE(test_helper_.interceptor()->successful_reports().empty()); | |
250 EXPECT_TRUE(test_helper_.interceptor()->failed_reports().empty()); | |
251 | |
252 if (expect_delayed_report) | |
253 EXPECT_EQ(1u, test_helper_.interceptor()->delayed_reports().size()); | |
254 else | |
255 EXPECT_TRUE(test_helper_.interceptor()->delayed_reports().empty()); | |
256 | |
257 if (service()->GetReporterForTesting()) { | |
258 // Reporter can be null if reporting is disabled. | |
259 size_t num_inflight_reports = expect_delayed_report ? 1u : 0u; | |
260 EXPECT_EQ(num_inflight_reports, | |
261 service() | |
262 ->GetReporterForTesting() | |
263 ->inflight_report_count_for_testing()); | |
264 } | |
265 } | 191 } |
266 | 192 |
267 net::EmbeddedTestServer https_server_; | 193 net::EmbeddedTestServer https_server_; |
268 // If true, the test will expect to see a delayed report during test teardown. | |
269 bool expect_delayed_report_on_teardown_ = false; | |
270 | 194 |
271 unsigned int num_expected_failed_report_ = 0; | 195 int num_expected_failed_report_ = -1; |
272 | 196 |
273 CertificateReportingServiceTestHelper test_helper_; | 197 CertificateReportingServiceTestHelper test_helper_; |
274 | 198 |
| 199 CertificateReportingServiceObserver service_observer_; |
| 200 |
275 base::HistogramTester histogram_tester_; | 201 base::HistogramTester histogram_tester_; |
276 | 202 |
277 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); | 203 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest); |
278 }; | 204 }; |
279 | 205 |
280 // Tests that report send attempt should be cancelled when extended | 206 // Tests that report send attempt should be cancelled when extended |
281 // reporting is not opted in. | 207 // reporting is not opted in. |
282 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 208 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
283 NotOptedIn_ShouldNotSendReports) { | 209 NotOptedIn_ShouldNotSendReports) { |
284 SetExpectedHistogramCountOnTeardown(0); | 210 SetExpectedHistogramCountOnTeardown(0); |
(...skipping 15 matching lines...) Expand all Loading... |
300 | 226 |
301 certificate_reporting_test_utils::SetCertReportingOptIn( | 227 certificate_reporting_test_utils::SetCertReportingOptIn( |
302 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 228 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
303 | 229 |
304 // Let reports uploads successfully complete. | 230 // Let reports uploads successfully complete. |
305 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 231 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
306 ReportSendingResult::REPORTS_SUCCESSFUL); | 232 ReportSendingResult::REPORTS_SUCCESSFUL); |
307 | 233 |
308 // Reporting is opted in, so the report should succeed. | 234 // Reporting is opted in, so the report should succeed. |
309 SendReport("report0"); | 235 SendReport("report0"); |
310 WaitForReports(ReportExpectation::Successful({"report0"})); | 236 test_helper()->WaitForRequestsDestroyed( |
| 237 ReportExpectation::Successful({"report0"})); |
311 } | 238 } |
312 | 239 |
313 // Tests that report send attempts are not cancelled when extended reporting is | 240 // Tests that report send attempts are not cancelled when extended reporting is |
314 // opted in. Goes to an interstitial page and navigate away to force a report | 241 // opted in. Goes to an interstitial page and navigate away to force a report |
315 // send event. Repeats this three times and checks expected number of reports. | 242 // send event. Repeats this three times and checks expected number of reports. |
316 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 243 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
317 OptedIn_ShouldQueueFailedReport) { | 244 OptedIn_ShouldQueueFailedReport) { |
318 SetExpectedHistogramCountOnTeardown(2); | 245 SetExpectedHistogramCountOnTeardown(2); |
319 | 246 |
320 certificate_reporting_test_utils::SetCertReportingOptIn( | 247 certificate_reporting_test_utils::SetCertReportingOptIn( |
321 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 248 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
322 // Let all reports fail. | 249 // Let all reports fail. |
323 test_helper()->SetFailureMode( | 250 test_helper()->SetFailureMode( |
324 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 251 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
325 | 252 |
326 // Send a failed report. | 253 // Send a failed report. |
327 SendReport("report0"); | 254 SendReport("report0"); |
328 WaitForReports(ReportExpectation::Failed({"report0"})); | 255 test_helper()->WaitForRequestsDestroyed( |
| 256 ReportExpectation::Failed({"report0"})); |
329 | 257 |
330 // Send another failed report. | 258 // Send another failed report. |
331 SendReport("report1"); | 259 SendReport("report1"); |
332 WaitForReports(ReportExpectation::Failed({"report1"})); | 260 test_helper()->WaitForRequestsDestroyed( |
| 261 ReportExpectation::Failed({"report1"})); |
333 | 262 |
334 // Let all report uploads complete successfully now. | 263 // Let all report uploads complete successfully now. |
335 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 264 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
336 ReportSendingResult::REPORTS_SUCCESSFUL); | 265 ReportSendingResult::REPORTS_SUCCESSFUL); |
337 | 266 |
338 // Send another report. This time the report should be successfully sent. | 267 // Send another report. This time the report should be successfully sent. |
339 SendReport("report2"); | 268 SendReport("report2"); |
340 WaitForReports(ReportExpectation::Successful({"report2"})); | 269 test_helper()->WaitForRequestsDestroyed( |
| 270 ReportExpectation::Successful({"report2"})); |
341 | 271 |
342 // Send all pending reports. The two previously failed reports should have | 272 // Send all pending reports. The two previously failed reports should have |
343 // been queued, and now be sent successfully. | 273 // been queued, and now be sent successfully. |
344 SendPendingReports(); | 274 SendPendingReports(); |
345 WaitForReports(ReportExpectation::Successful({"report0", "report1"})); | 275 test_helper()->WaitForRequestsDestroyed( |
| 276 ReportExpectation::Successful({"report0", "report1"})); |
346 | 277 |
347 // Try sending pending reports again. Since there is no pending report, | 278 // Try sending pending reports again. Since there is no pending report, |
348 // nothing should be sent this time. If any report is sent, test teardown | 279 // nothing should be sent this time. If any report is sent, test teardown |
349 // will catch it. | 280 // will catch it. |
350 SendPendingReports(); | 281 SendPendingReports(); |
351 } | 282 } |
352 | 283 |
353 // Opting in then opting out of extended reporting should clear the pending | 284 // Opting in then opting out of extended reporting should clear the pending |
354 // report queue. | 285 // report queue. |
355 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 286 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
356 OptedIn_ThenOptedOut) { | 287 OptedIn_ThenOptedOut) { |
357 SetExpectedHistogramCountOnTeardown(1); | 288 SetExpectedHistogramCountOnTeardown(1); |
358 | 289 |
359 certificate_reporting_test_utils::SetCertReportingOptIn( | 290 certificate_reporting_test_utils::SetCertReportingOptIn( |
360 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 291 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
361 // Let all reports fail. | 292 // Let all reports fail. |
362 test_helper()->SetFailureMode( | 293 test_helper()->SetFailureMode( |
363 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 294 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
364 | 295 |
365 // Send a failed report. | 296 // Send a failed report. |
366 SendReport("report0"); | 297 SendReport("report0"); |
367 WaitForReports(ReportExpectation::Failed({"report0"})); | 298 test_helper()->WaitForRequestsDestroyed( |
| 299 ReportExpectation::Failed({"report0"})); |
368 | 300 |
369 // Disable reporting. This should clear all pending reports. | 301 // Disable reporting. This should clear all pending reports. |
370 ChangeOptInAndWait( | 302 ChangeOptInAndWait( |
371 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 303 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
372 | 304 |
373 // Send pending reports. No reports should be observed during test teardown. | 305 // Send pending reports. No reports should be observed during test teardown. |
374 SendPendingReports(); | 306 SendPendingReports(); |
375 } | 307 } |
376 | 308 |
377 // Opting out, then in, then out of extended reporting should work as expected. | 309 // Opting out, then in, then out of extended reporting should work as expected. |
378 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 310 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
379 OptedOut_ThenOptedIn_ThenOptedOut) { | 311 OptedOut_ThenOptedIn_ThenOptedOut) { |
380 SetExpectedHistogramCountOnTeardown(1); | 312 SetExpectedHistogramCountOnTeardown(1); |
381 | 313 |
382 certificate_reporting_test_utils::SetCertReportingOptIn( | 314 certificate_reporting_test_utils::SetCertReportingOptIn( |
383 browser(), | 315 browser(), |
384 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 316 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
385 // Let all reports fail. | 317 // Let all reports fail. |
386 test_helper()->SetFailureMode( | 318 test_helper()->SetFailureMode( |
387 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 319 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
388 | 320 |
389 // Send attempt should be cancelled since reporting is opted out. | 321 // Send attempt should be cancelled since reporting is opted out. |
390 SendReport("no-report"); | 322 SendReport("no-report"); |
391 CheckNoReports(); | 323 test_helper()->ExpectNoRequests(service()); |
392 | 324 |
393 // Enable reporting. | 325 // Enable reporting. |
394 ChangeOptInAndWait( | 326 ChangeOptInAndWait( |
395 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 327 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
396 | 328 |
397 // A failed report should be observed. | 329 // A failed report should be observed. |
398 SendReport("report0"); | 330 SendReport("report0"); |
399 WaitForReports(ReportExpectation::Failed({"report0"})); | 331 test_helper()->WaitForRequestsDestroyed( |
| 332 ReportExpectation::Failed({"report0"})); |
400 | 333 |
401 // Disable reporting. This should reset the reporting service and | 334 // Disable reporting. This should reset the reporting service and |
402 // clear all pending reports. | 335 // clear all pending reports. |
403 ChangeOptInAndWait( | 336 ChangeOptInAndWait( |
404 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); | 337 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN); |
405 | 338 |
406 // Report should be cancelled since reporting is opted out. | 339 // Report should be cancelled since reporting is opted out. |
407 SendReport("report1"); | 340 SendReport("report1"); |
408 CheckNoReports(); | 341 test_helper()->ExpectNoRequests(service()); |
409 | 342 |
410 // Send pending reports. Nothing should be sent since there aren't any | 343 // Send pending reports. Nothing should be sent since there aren't any |
411 // pending reports. If any report is sent, test teardown will catch it. | 344 // pending reports. If any report is sent, test teardown will catch it. |
412 SendPendingReports(); | 345 SendPendingReports(); |
413 } | 346 } |
414 | 347 |
415 // Disabling SafeBrowsing should clear pending reports queue in | 348 // Disabling SafeBrowsing should clear pending reports queue in |
416 // CertificateReportingService. | 349 // CertificateReportingService. |
417 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 350 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
418 DisableSafebrowsing) { | 351 DisableSafebrowsing) { |
419 SetExpectedHistogramCountOnTeardown(2); | 352 SetExpectedHistogramCountOnTeardown(2); |
420 | 353 |
421 certificate_reporting_test_utils::SetCertReportingOptIn( | 354 certificate_reporting_test_utils::SetCertReportingOptIn( |
422 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 355 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
423 // Let all reports fail. | 356 // Let all reports fail. |
424 test_helper()->SetFailureMode( | 357 test_helper()->SetFailureMode( |
425 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 358 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
426 | 359 |
427 // Send a failed report. | 360 // Send a delayed report. |
428 SendReport("report0"); | 361 SendReport("report0"); |
429 WaitForReports(ReportExpectation::Failed({"report0"})); | 362 test_helper()->WaitForRequestsDestroyed( |
| 363 ReportExpectation::Failed({"report0"})); |
430 | 364 |
431 // Disable SafeBrowsing. This should clear all pending reports. | 365 // Disable SafeBrowsing. This should clear all pending reports. |
432 ToggleSafeBrowsingAndWaitForServiceReset(false); | 366 ToggleSafeBrowsingAndWaitForServiceReset(false); |
433 | 367 |
434 // Send pending reports. No reports should be observed. | 368 // Send pending reports. No reports should be observed. |
435 SendPendingReports(); | 369 SendPendingReports(); |
436 CheckNoReports(); | 370 test_helper()->ExpectNoRequests(service()); |
437 | 371 |
438 // Re-enable SafeBrowsing and trigger another report which will be queued. | 372 // Re-enable SafeBrowsing and trigger another report which will be queued. |
439 ToggleSafeBrowsingAndWaitForServiceReset(true); | 373 ToggleSafeBrowsingAndWaitForServiceReset(true); |
440 SendReport("report1"); | 374 SendReport("report1"); |
441 WaitForReports(ReportExpectation::Failed({"report1"})); | 375 test_helper()->WaitForRequestsDestroyed( |
| 376 ReportExpectation::Failed({"report1"})); |
442 | 377 |
443 // Queued report should now be successfully sent. | 378 // Queued report should now be successfully sent. |
444 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 379 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
445 ReportSendingResult::REPORTS_SUCCESSFUL); | 380 ReportSendingResult::REPORTS_SUCCESSFUL); |
446 SendPendingReports(); | 381 SendPendingReports(); |
447 WaitForReports(ReportExpectation::Successful({"report1"})); | 382 test_helper()->WaitForRequestsDestroyed( |
| 383 ReportExpectation::Successful({"report1"})); |
448 } | 384 } |
449 | 385 |
450 // CertificateReportingService should ignore reports older than the report TTL. | 386 // CertificateReportingService should ignore reports older than the report TTL. |
451 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 387 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
452 DontSendOldReports) { | 388 DontSendOldReports) { |
453 SetExpectedHistogramCountOnTeardown(5); | 389 SetExpectedHistogramCountOnTeardown(5); |
454 | 390 |
455 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 391 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
456 base::Time reference_time = base::Time::Now(); | 392 base::Time reference_time = base::Time::Now(); |
457 clock->SetNow(reference_time); | 393 clock->SetNow(reference_time); |
458 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock)); | 394 factory()->SetClockForTesting(std::unique_ptr<base::Clock>(clock)); |
459 | 395 |
460 // The service should ignore reports older than 24 hours. | 396 // The service should ignore reports older than 24 hours. |
461 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24)); | 397 factory()->SetQueuedReportTTLForTesting(base::TimeDelta::FromHours(24)); |
462 | 398 |
463 certificate_reporting_test_utils::SetCertReportingOptIn( | 399 certificate_reporting_test_utils::SetCertReportingOptIn( |
464 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 400 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
465 | 401 |
466 // Let all reports fail. | 402 // Let all reports fail. |
467 test_helper()->SetFailureMode( | 403 test_helper()->SetFailureMode( |
468 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 404 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
469 | 405 |
470 // Send a failed report. | 406 // Send a failed report. |
471 SendReport("report0"); | 407 SendReport("report0"); |
472 WaitForReports(ReportExpectation::Failed({"report0"})); | 408 test_helper()->WaitForRequestsDestroyed( |
| 409 ReportExpectation::Failed({"report0"})); |
473 | 410 |
474 // Advance the clock a bit and trigger another failed report. | 411 // Advance the clock a bit and trigger another failed report. |
475 clock->Advance(base::TimeDelta::FromHours(5)); | 412 clock->Advance(base::TimeDelta::FromHours(5)); |
476 SendReport("report1"); | 413 SendReport("report1"); |
477 WaitForReports(ReportExpectation::Failed({"report1"})); | 414 test_helper()->WaitForRequestsDestroyed( |
| 415 ReportExpectation::Failed({"report1"})); |
478 | 416 |
479 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference | 417 // Advance the clock to 20 hours, putting it 25 hours ahead of the reference |
480 // time. This makes report0 older than 24 hours. report1 is now 20 hours. | 418 // time. This makes report0 older than 24 hours. report1 is now 20 hours. |
481 clock->Advance(base::TimeDelta::FromHours(20)); | 419 clock->Advance(base::TimeDelta::FromHours(20)); |
482 | 420 |
483 // Send pending reports. report0 should be discarded since it's too old. | 421 // Send pending reports. report0 should be discarded since it's too old. |
484 // report1 should be queued again. | 422 // report1 should be queued again. |
485 SendPendingReports(); | 423 SendPendingReports(); |
486 WaitForReports(ReportExpectation::Failed({"report1"})); | 424 test_helper()->WaitForRequestsDestroyed( |
| 425 ReportExpectation::Failed({"report1"})); |
487 | 426 |
488 // Trigger another failed report. | 427 // Trigger another failed report. |
489 SendReport("report2"); | 428 SendReport("report2"); |
490 WaitForReports(ReportExpectation::Failed({"report2"})); | 429 test_helper()->WaitForRequestsDestroyed( |
| 430 ReportExpectation::Failed({"report2"})); |
491 | 431 |
492 // Advance the clock 5 hours. report1 will now be 25 hours old. | 432 // Advance the clock 5 hours. report1 will now be 25 hours old. |
493 clock->Advance(base::TimeDelta::FromHours(5)); | 433 clock->Advance(base::TimeDelta::FromHours(5)); |
494 | 434 |
495 // Send pending reports. report1 should be discarded since it's too old. | 435 // Send pending reports. report1 should be discarded since it's too old. |
496 // report2 should be queued again. | 436 // report2 should be queued again. |
497 SendPendingReports(); | 437 SendPendingReports(); |
498 WaitForReports(ReportExpectation::Failed({"report2"})); | 438 test_helper()->WaitForRequestsDestroyed( |
| 439 ReportExpectation::Failed({"report2"})); |
499 | 440 |
500 // Advance the clock 20 hours again so that report2 is 25 hours old and is | 441 // Advance the clock 20 hours again so that report2 is 25 hours old and is |
501 // older than max age (24 hours). | 442 // older than max age (24 hours). |
502 clock->Advance(base::TimeDelta::FromHours(20)); | 443 clock->Advance(base::TimeDelta::FromHours(20)); |
503 | 444 |
504 // Send pending reports. report2 should be discarded since it's too old. No | 445 // Send pending reports. report2 should be discarded since it's too old. No |
505 // other reports remain. If any report is sent, test teardown will catch it. | 446 // other reports remain. If any report is sent, test teardown will catch it. |
506 SendPendingReports(); | 447 SendPendingReports(); |
507 } | 448 } |
508 | 449 |
(...skipping 15 matching lines...) Expand all Loading... |
524 | 465 |
525 certificate_reporting_test_utils::SetCertReportingOptIn( | 466 certificate_reporting_test_utils::SetCertReportingOptIn( |
526 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 467 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
527 | 468 |
528 // Let all reports fail. | 469 // Let all reports fail. |
529 test_helper()->SetFailureMode( | 470 test_helper()->SetFailureMode( |
530 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); | 471 certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL); |
531 | 472 |
532 // Trigger a failed report. | 473 // Trigger a failed report. |
533 SendReport("report0"); | 474 SendReport("report0"); |
534 WaitForReports(ReportExpectation::Failed({"report0"})); | 475 test_helper()->WaitForRequestsDestroyed( |
| 476 ReportExpectation::Failed({"report0"})); |
535 | 477 |
536 // Trigger three more reports within five hours of each other. After this: | 478 // Trigger three more reports within five hours of each other. After this: |
537 // report0 is 0 hours after reference time (15 hours old). | 479 // report0 is 0 hours after reference time (15 hours old). |
538 // report1 is 5 hours after reference time (10 hours old). | 480 // report1 is 5 hours after reference time (10 hours old). |
539 // report2 is 10 hours after reference time (5 hours old). | 481 // report2 is 10 hours after reference time (5 hours old). |
540 // report3 is 15 hours after reference time (0 hours old). | 482 // report3 is 15 hours after reference time (0 hours old). |
541 clock->Advance(base::TimeDelta::FromHours(5)); | 483 clock->Advance(base::TimeDelta::FromHours(5)); |
542 SendReport("report1"); | 484 SendReport("report1"); |
543 | 485 |
544 clock->Advance(base::TimeDelta::FromHours(5)); | 486 clock->Advance(base::TimeDelta::FromHours(5)); |
545 SendReport("report2"); | 487 SendReport("report2"); |
546 | 488 |
547 clock->Advance(base::TimeDelta::FromHours(5)); | 489 clock->Advance(base::TimeDelta::FromHours(5)); |
548 SendReport("report3"); | 490 SendReport("report3"); |
549 | 491 |
550 WaitForReports(ReportExpectation::Failed({"report1", "report2", "report3"})); | 492 test_helper()->WaitForRequestsDestroyed( |
| 493 ReportExpectation::Failed({"report1", "report2", "report3"})); |
551 | 494 |
552 // Send pending reports. Four reports were generated above, but the service | 495 // Send pending reports. Four reports were generated above, but the service |
553 // only queues three reports, so report0 should be dropped since it's the | 496 // only queues three reports, so report0 should be dropped since it's the |
554 // oldest. | 497 // oldest. |
555 SendPendingReports(); | 498 SendPendingReports(); |
556 WaitForReports(ReportExpectation::Failed({"report1", "report2", "report3"})); | 499 test_helper()->WaitForRequestsDestroyed( |
| 500 ReportExpectation::Failed({"report1", "report2", "report3"})); |
557 | 501 |
558 // Let all reports succeed. | 502 // Let all reports succeed. |
559 test_helper()->SetFailureMode(certificate_reporting_test_utils:: | 503 test_helper()->SetFailureMode(certificate_reporting_test_utils:: |
560 ReportSendingResult::REPORTS_SUCCESSFUL); | 504 ReportSendingResult::REPORTS_SUCCESSFUL); |
561 | 505 |
562 // Advance the clock 15 hours. Current time is now 30 hours after reference | 506 // Advance the clock 15 hours. Current time is now 30 hours after reference |
563 // time, and the ages of reports are now as follows: | 507 // time, and the ages of reports are now as follows: |
564 // report1 is 25 hours old. | 508 // report1 is 25 hours old. |
565 // report2 is 20 hours old. | 509 // report2 is 20 hours old. |
566 // report3 is 15 hours old. | 510 // report3 is 15 hours old. |
567 clock->Advance(base::TimeDelta::FromHours(15)); | 511 clock->Advance(base::TimeDelta::FromHours(15)); |
568 | 512 |
569 // Send pending reports. Only reports 2 and 3 should be sent, report 1 | 513 // Send pending reports. Only reports 2 and 3 should be sent, report 1 |
570 // should be ignored because it's too old. | 514 // should be ignored because it's too old. |
571 SendPendingReports(); | 515 SendPendingReports(); |
572 WaitForReports(ReportExpectation::Successful({"report2", "report3"})); | 516 test_helper()->WaitForRequestsDestroyed( |
573 } | 517 ReportExpectation::Successful({"report2", "report3"})); |
574 | |
575 // Resume a delayed report after CertificateReportingService shuts down. Should | |
576 // not crash. | |
577 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | |
578 Delayed_NotResumed_ShouldNotCrash) { | |
579 SetExpectedHistogramCountOnTeardown(0); | |
580 | |
581 certificate_reporting_test_utils::SetCertReportingOptIn( | |
582 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | |
583 // Let reports hang. | |
584 test_helper()->SetFailureMode( | |
585 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | |
586 | |
587 // Navigate to and away from an interstitial to trigger a report. The report | |
588 // is triggered but hangs, so no error or success callbacks should be called. | |
589 SendReport("no-report"); | |
590 | |
591 SetExpectDelayedReportOnTeardown(); | |
592 } | 518 } |
593 | 519 |
594 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 520 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
595 Delayed_Resumed) { | 521 Delayed_Resumed) { |
596 SetExpectedHistogramCountOnTeardown(0); | 522 SetExpectedHistogramCountOnTeardown(0); |
597 | 523 |
598 certificate_reporting_test_utils::SetCertReportingOptIn( | 524 certificate_reporting_test_utils::SetCertReportingOptIn( |
599 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 525 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
600 // Let all reports fail. | 526 // Let all reports hang. |
601 test_helper()->SetFailureMode( | 527 test_helper()->SetFailureMode( |
602 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 528 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
603 | 529 |
604 // Trigger a report that hangs. | 530 // Trigger a report that hangs. |
605 SendReport("report0"); | 531 SendReport("report0"); |
606 WaitForReports(ReportExpectation::Delayed({"report0"})); | 532 test_helper()->WaitForRequestsCreated( |
| 533 ReportExpectation::Delayed({"report0"})); |
607 | 534 |
608 // Resume the report upload. The report upload should successfully complete. | 535 // Resume the report upload. The report upload should successfully complete. |
609 // The interceptor only observes request creations and not response | 536 // The interceptor only observes request creations and not response |
610 // completions, so there is nothing to observe. | 537 // completions, so there is nothing to observe. |
611 ResumeDelayedRequestAndWait(); | 538 test_helper()->ResumeDelayedRequest(); |
| 539 test_helper()->WaitForRequestsDestroyed( |
| 540 ReportExpectation::Delayed({"report0"})); |
612 } | 541 } |
613 | 542 |
614 // Same as above, but the service is shut down before resuming the delayed | 543 // Same as above, but the service is shut down before resuming the delayed |
615 // request. Should not crash. | 544 // request. Should not crash. |
616 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, | 545 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, |
617 Delayed_Resumed_ServiceShutdown) { | 546 Delayed_Resumed_ServiceShutdown) { |
618 SetExpectedHistogramCountOnTeardown(0); | 547 SetExpectedHistogramCountOnTeardown(0); |
619 | 548 |
620 certificate_reporting_test_utils::SetCertReportingOptIn( | 549 certificate_reporting_test_utils::SetCertReportingOptIn( |
621 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 550 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
622 // Let all reports fail. | 551 // Let all reports hang. |
623 test_helper()->SetFailureMode( | 552 test_helper()->SetFailureMode( |
624 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 553 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
625 | 554 |
626 // Trigger a report that hangs. | 555 // Trigger a report that hangs. |
627 SendReport("report0"); | 556 SendReport("report0"); |
628 WaitForReports(ReportExpectation::Delayed({"report0"})); | 557 test_helper()->WaitForRequestsCreated( |
| 558 ReportExpectation::Delayed({"report0"})); |
629 | 559 |
630 // Shutdown the service. Resuming the delayed request shouldn't crash. | 560 // Shutdown the service and resume the report upload. Shouldn't crash. |
631 ShutdownServiceAndWait(); | 561 service()->Shutdown(); |
632 | 562 test_helper()->ResumeDelayedRequest(); |
633 // Resume the report upload. The report upload should successfully complete. | 563 test_helper()->WaitForRequestsDestroyed( |
634 // The interceptor only observes request creations and not response | 564 ReportExpectation::Delayed({"report0"})); |
635 // completions, so there is nothing to observe. | |
636 ResumeDelayedRequestAndWait(); | |
637 } | 565 } |
638 | 566 |
639 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting | 567 // Trigger a delayed report, then disable Safebrowsing. Certificate reporting |
640 // service should clear its in-flight reports list. | 568 // service should clear its in-flight reports list. |
641 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { | 569 IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) { |
642 SetExpectedHistogramCountOnTeardown(0); | 570 SetExpectedHistogramCountOnTeardown(0); |
643 | 571 |
644 certificate_reporting_test_utils::SetCertReportingOptIn( | 572 certificate_reporting_test_utils::SetCertReportingOptIn( |
645 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); | 573 browser(), certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN); |
646 // Let all reports fail. | 574 // Let all reports hang. |
647 test_helper()->SetFailureMode( | 575 test_helper()->SetFailureMode( |
648 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); | 576 certificate_reporting_test_utils::ReportSendingResult::REPORTS_DELAY); |
649 | 577 |
650 // Trigger a report that hangs. | 578 // Trigger a report that hangs. |
651 SendReport("report0"); | 579 SendReport("report0"); |
652 WaitForReports(ReportExpectation::Delayed({"report0"})); | 580 test_helper()->WaitForRequestsCreated( |
| 581 ReportExpectation::Delayed({"report0"})); |
653 | 582 |
654 // Disable SafeBrowsing. This should clear all pending reports. | 583 // Disable SafeBrowsing. This should clear all pending reports. |
655 ToggleSafeBrowsingAndWaitForServiceReset(false); | 584 ToggleSafeBrowsingAndWaitForServiceReset(false); |
| 585 test_helper()->WaitForRequestsDestroyed( |
| 586 ReportExpectation::Delayed({"report0"})); |
656 | 587 |
657 // Resume delayed report. No response should be observed since all pending | 588 // Resume delayed report. No response should be observed since all pending |
658 // reports should be cleared. | 589 // reports should be cleared. |
659 ResumeDelayedRequestAndWait(); | 590 test_helper()->ResumeDelayedRequest(); |
660 CheckNoReports(); | 591 test_helper()->ExpectNoRequests(service()); |
661 | 592 |
662 // Re-enable SafeBrowsing. | 593 // Re-enable SafeBrowsing. |
663 ToggleSafeBrowsingAndWaitForServiceReset(true); | 594 ToggleSafeBrowsingAndWaitForServiceReset(true); |
664 | 595 |
665 // Trigger a report that hangs. | 596 // Trigger a report that hangs. |
666 SendReport("report1"); | 597 SendReport("report1"); |
667 WaitForReports(ReportExpectation::Delayed({"report1"})); | 598 test_helper()->WaitForRequestsCreated( |
| 599 ReportExpectation::Delayed({"report1"})); |
668 | 600 |
669 // Resume delayed report. By the time the runloop is finished, the response | 601 // Resume the delayed report and wait for it to complete. |
670 // will be complete and CertificateReportingService will process the | 602 test_helper()->ResumeDelayedRequest(); |
671 // error/success callback for the report. There will be no inflight reports | 603 test_helper()->WaitForRequestsDestroyed( |
672 // remaining. | 604 ReportExpectation::Delayed({"report1"})); |
673 ResumeDelayedRequestAndWait(); | |
674 } | 605 } |
675 | 606 |
676 } // namespace safe_browsing | 607 } // namespace safe_browsing |
OLD | NEW |