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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 ~CertificateReportingServiceTest() override {} | 343 ~CertificateReportingServiceTest() override {} |
344 | 344 |
345 void SetUp() override { | 345 void SetUp() override { |
346 service_observer_.Clear(); | 346 service_observer_.Clear(); |
347 test_helper_.SetUpInterceptor(); | 347 test_helper_.SetUpInterceptor(); |
348 WaitForIOThread(); | 348 WaitForIOThread(); |
349 | 349 |
350 content::BrowserThread::PostTask( | 350 content::BrowserThread::PostTask( |
351 content::BrowserThread::IO, FROM_HERE, | 351 content::BrowserThread::IO, FROM_HERE, |
352 base::Bind( | 352 base::BindOnce( |
353 &CertificateReportingServiceTest::SetUpURLRequestContextOnIOThread, | 353 &CertificateReportingServiceTest::SetUpURLRequestContextOnIOThread, |
354 base::Unretained(this))); | 354 base::Unretained(this))); |
355 WaitForIOThread(); | 355 WaitForIOThread(); |
356 | 356 |
357 safe_browsing::SafeBrowsingService::RegisterFactory(&sb_service_factory); | 357 safe_browsing::SafeBrowsingService::RegisterFactory(&sb_service_factory); |
358 sb_service_ = sb_service_factory.CreateSafeBrowsingService(); | 358 sb_service_ = sb_service_factory.CreateSafeBrowsingService(); |
359 | 359 |
360 clock_.reset(new base::SimpleTestClock()); | 360 clock_.reset(new base::SimpleTestClock()); |
361 service_.reset(new CertificateReportingService( | 361 service_.reset(new CertificateReportingService( |
362 sb_service_.get(), url_request_context_getter(), &profile_, | 362 sb_service_.get(), url_request_context_getter(), &profile_, |
363 test_helper_.server_public_key(), | 363 test_helper_.server_public_key(), |
364 test_helper_.server_public_key_version(), kMaxReportCountInQueue, | 364 test_helper_.server_public_key_version(), kMaxReportCountInQueue, |
365 base::TimeDelta::FromHours(24), clock_.get(), | 365 base::TimeDelta::FromHours(24), clock_.get(), |
366 base::Bind(&CertificateReportingServiceObserver::OnServiceReset, | 366 base::Bind(&CertificateReportingServiceObserver::OnServiceReset, |
367 base::Unretained(&service_observer_)))); | 367 base::Unretained(&service_observer_)))); |
368 service_observer_.WaitForReset(); | 368 service_observer_.WaitForReset(); |
369 } | 369 } |
370 | 370 |
371 void TearDown() override { | 371 void TearDown() override { |
372 WaitForIOThread(); | 372 WaitForIOThread(); |
373 test_helper()->ExpectNoRequests(service()); | 373 test_helper()->ExpectNoRequests(service()); |
374 | 374 |
375 service_->Shutdown(); | 375 service_->Shutdown(); |
376 WaitForIOThread(); | 376 WaitForIOThread(); |
377 service_.reset(nullptr); | 377 service_.reset(nullptr); |
378 | 378 |
379 content::BrowserThread::PostTask( | 379 content::BrowserThread::PostTask( |
380 content::BrowserThread::IO, FROM_HERE, | 380 content::BrowserThread::IO, FROM_HERE, |
381 base::Bind(&CertificateReportingServiceTest::TearDownOnIOThread, | 381 base::BindOnce(&CertificateReportingServiceTest::TearDownOnIOThread, |
382 base::Unretained(this))); | 382 base::Unretained(this))); |
383 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 383 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
384 base::Bind(&ClearURLHandlers)); | 384 base::BindOnce(&ClearURLHandlers)); |
385 WaitForIOThread(); | 385 WaitForIOThread(); |
386 | 386 |
387 histogram_test_helper_.CheckHistogram(); | 387 histogram_test_helper_.CheckHistogram(); |
388 } | 388 } |
389 | 389 |
390 protected: | 390 protected: |
391 net::URLRequestContextGetter* url_request_context_getter() { | 391 net::URLRequestContextGetter* url_request_context_getter() { |
392 return url_request_context_getter_.get(); | 392 return url_request_context_getter_.get(); |
393 } | 393 } |
394 | 394 |
395 void WaitForIOThread() { | 395 void WaitForIOThread() { |
396 scoped_refptr<base::ThreadTestHelper> io_helper( | 396 scoped_refptr<base::ThreadTestHelper> io_helper( |
397 new base::ThreadTestHelper(io_task_runner_)); | 397 new base::ThreadTestHelper(io_task_runner_)); |
398 ASSERT_TRUE(io_helper->Run()); | 398 ASSERT_TRUE(io_helper->Run()); |
399 } | 399 } |
400 | 400 |
401 CertificateReportingService* service() { return service_.get(); } | 401 CertificateReportingService* service() { return service_.get(); } |
402 | 402 |
403 // Sets service enabled state and waits for a reset event. | 403 // Sets service enabled state and waits for a reset event. |
404 void SetServiceEnabledAndWait(bool enabled) { | 404 void SetServiceEnabledAndWait(bool enabled) { |
405 service_observer_.Clear(); | 405 service_observer_.Clear(); |
406 service()->SetEnabled(enabled); | 406 service()->SetEnabled(enabled); |
407 service_observer_.WaitForReset(); | 407 service_observer_.WaitForReset(); |
408 } | 408 } |
409 | 409 |
410 void AdvanceClock(base::TimeDelta delta) { | 410 void AdvanceClock(base::TimeDelta delta) { |
411 content::BrowserThread::PostTask( | 411 content::BrowserThread::PostTask( |
412 content::BrowserThread::IO, FROM_HERE, | 412 content::BrowserThread::IO, FROM_HERE, |
413 base::Bind(&base::SimpleTestClock::Advance, | 413 base::BindOnce(&base::SimpleTestClock::Advance, |
414 base::Unretained(clock_.get()), delta)); | 414 base::Unretained(clock_.get()), delta)); |
415 } | 415 } |
416 | 416 |
417 void SetNow(base::Time now) { | 417 void SetNow(base::Time now) { |
418 content::BrowserThread::PostTask( | 418 content::BrowserThread::PostTask( |
419 content::BrowserThread::IO, FROM_HERE, | 419 content::BrowserThread::IO, FROM_HERE, |
420 base::Bind(&base::SimpleTestClock::SetNow, | 420 base::BindOnce(&base::SimpleTestClock::SetNow, |
421 base::Unretained(clock_.get()), now)); | 421 base::Unretained(clock_.get()), now)); |
422 } | 422 } |
423 | 423 |
424 void SetExpectedFailedReportCountOnTearDown(unsigned int count) { | 424 void SetExpectedFailedReportCountOnTearDown(unsigned int count) { |
425 histogram_test_helper_.SetExpectedFailedReportCount(count); | 425 histogram_test_helper_.SetExpectedFailedReportCount(count); |
426 } | 426 } |
427 | 427 |
428 CertificateReportingServiceTestHelper* test_helper() { return &test_helper_; } | 428 CertificateReportingServiceTestHelper* test_helper() { return &test_helper_; } |
429 | 429 |
430 private: | 430 private: |
431 void SetUpURLRequestContextOnIOThread() { | 431 void SetUpURLRequestContextOnIOThread() { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 // callbacks should be called. The report id is again 0 since the pending | 703 // callbacks should be called. The report id is again 0 since the pending |
704 // report queue has been cleared above. | 704 // report queue has been cleared above. |
705 service()->Send(MakeReport("report1")); | 705 service()->Send(MakeReport("report1")); |
706 | 706 |
707 // Resume delayed report. Two reports are successfully sent. | 707 // Resume delayed report. Two reports are successfully sent. |
708 test_helper()->ResumeDelayedRequest(); | 708 test_helper()->ResumeDelayedRequest(); |
709 test_helper()->WaitForRequestsDestroyed( | 709 test_helper()->WaitForRequestsDestroyed( |
710 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}, | 710 ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}, |
711 {"report1", RetryStatus::NOT_RETRIED}})); | 711 {"report1", RetryStatus::NOT_RETRIED}})); |
712 } | 712 } |
OLD | NEW |