OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
7 // service. | 7 // service. |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 Mock::VerifyAndClear(&observer_); | 499 Mock::VerifyAndClear(&observer_); |
500 g_browser_process->safe_browsing_service()->RemoveObserver(&observer_); | 500 g_browser_process->safe_browsing_service()->RemoveObserver(&observer_); |
501 } | 501 } |
502 | 502 |
503 } // namespace | 503 } // namespace |
504 | 504 |
505 class TestSBClient | 505 class TestSBClient |
506 : public base::RefCountedThreadSafe<TestSBClient>, | 506 : public base::RefCountedThreadSafe<TestSBClient>, |
507 public SafeBrowsingService::Client { | 507 public SafeBrowsingService::Client { |
508 public: | 508 public: |
509 TestSBClient() : result_(SafeBrowsingService::SAFE), | 509 TestSBClient() |
510 safe_browsing_service_(g_browser_process-> | 510 : result_(SafeBrowsingService::SAFE), |
511 safe_browsing_service()) { | 511 safe_browsing_service_(g_browser_process->safe_browsing_service()) { |
512 } | 512 } |
513 | 513 |
514 int GetResult() { | 514 int GetResult() { |
515 return result_; | 515 return result_; |
516 } | 516 } |
517 | 517 |
518 void CheckDownloadUrl(const std::vector<GURL>& url_chain) { | 518 void CheckDownloadUrl(const std::vector<GURL>& url_chain) { |
519 BrowserThread::PostTask( | 519 BrowserThread::PostTask( |
520 BrowserThread::IO, FROM_HERE, | 520 BrowserThread::IO, FROM_HERE, |
521 base::Bind(&TestSBClient::CheckDownloadUrlOnIOThread, | 521 base::Bind(&TestSBClient::CheckDownloadUrlOnIOThread, |
522 this, url_chain)); | 522 this, url_chain)); |
523 ui_test_utils::RunMessageLoop(); // Will stop in OnDownloadUrlCheckResult. | 523 ui_test_utils::RunMessageLoop(); // Will stop in OnDownloadUrlCheckResult. |
524 } | 524 } |
525 | 525 |
526 void CheckDownloadHash(const std::string& full_hash) { | 526 void CheckDownloadHash(const std::string& full_hash) { |
527 BrowserThread::PostTask( | 527 BrowserThread::PostTask( |
528 BrowserThread::IO, FROM_HERE, | 528 BrowserThread::IO, FROM_HERE, |
529 base::Bind(&TestSBClient::CheckDownloadHashOnIOThread, | 529 base::Bind(&TestSBClient::CheckDownloadHashOnIOThread, |
530 this, full_hash)); | 530 this, full_hash)); |
531 ui_test_utils::RunMessageLoop(); // Will stop in OnDownloadHashCheckResult. | 531 ui_test_utils::RunMessageLoop(); // Will stop in OnDownloadHashCheckResult. |
532 } | 532 } |
533 | 533 |
534 private: | 534 private: |
| 535 friend class base::RefCountedThreadSafe<TestSBClient>; |
| 536 virtual ~TestSBClient() {} |
| 537 |
535 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) { | 538 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) { |
536 safe_browsing_service_->CheckDownloadUrl(url_chain, this); | 539 safe_browsing_service_->CheckDownloadUrl(url_chain, this); |
537 } | 540 } |
538 | 541 |
539 void CheckDownloadHashOnIOThread(const std::string& full_hash) { | 542 void CheckDownloadHashOnIOThread(const std::string& full_hash) { |
540 safe_browsing_service_->CheckDownloadHash(full_hash, this); | 543 safe_browsing_service_->CheckDownloadHash(full_hash, this); |
541 } | 544 } |
542 | 545 |
543 // Called when the result of checking a download URL is known. | 546 // Called when the result of checking a download URL is known. |
544 void OnDownloadUrlCheckResult(const std::vector<GURL>& url_chain, | 547 void OnDownloadUrlCheckResult(const std::vector<GURL>& url_chain, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 759 |
757 // Delete the Profile. SBS stops again. | 760 // Delete the Profile. SBS stops again. |
758 pref_service2 = NULL; | 761 pref_service2 = NULL; |
759 profile2.reset(); | 762 profile2.reset(); |
760 WaitForIOThread(); | 763 WaitForIOThread(); |
761 EXPECT_FALSE(sb_service->enabled()); | 764 EXPECT_FALSE(sb_service->enabled()); |
762 EXPECT_FALSE(csd_service->enabled()); | 765 EXPECT_FALSE(csd_service->enabled()); |
763 } | 766 } |
764 | 767 |
765 } // namespace | 768 } // namespace |
OLD | NEW |