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