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

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

Issue 2681783003: Since SafeBrowsingNavigationObserverManager cleans up navigation events every two minutes, if downl… (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 1717 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
1718 net::TestURLFetcherFactory factory; 1718 net::TestURLFetcherFactory factory;
1719 1719
1720 std::vector<GURL> url_chain; 1720 std::vector<GURL> url_chain;
1721 url_chain.push_back(GURL("http://www.google.com/")); 1721 url_chain.push_back(GURL("http://www.google.com/"));
1722 url_chain.push_back(GURL("http://www.google.com/bla.exe")); 1722 url_chain.push_back(GURL("http://www.google.com/bla.exe"));
1723 GURL referrer("http://www.google.com/"); 1723 GURL referrer("http://www.google.com/");
1724 std::string hash = "hash"; 1724 std::string hash = "hash";
1725 1725
1726 content::MockDownloadItem item; 1726 content::MockDownloadItem item;
1727 EXPECT_CALL(item, GetURL()).WillRepeatedly(ReturnRef(url_chain.back()));
1727 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 1728 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
1728 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 1729 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
1729 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 1730 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
1730 1731
1731 { 1732 {
1732 // CheckDownloadURL returns immediately which means the client object 1733 // CheckDownloadURL returns immediately which means the client object
1733 // callback will never be called. Nevertheless the callback provided 1734 // callback will never be called. Nevertheless the callback provided
1734 // to CheckClientDownload must still be called. 1735 // to CheckClientDownload must still be called.
1735 EXPECT_CALL(*sb_service_->mock_database_manager(), 1736 EXPECT_CALL(*sb_service_->mock_database_manager(),
1736 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 1737 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
1737 .WillOnce(Return(true)); 1738 .WillOnce(Return(true));
1738 RunLoop run_loop; 1739 RunLoop run_loop;
1739 download_service_->CheckDownloadUrl( 1740 download_service_->CheckDownloadUrl(
1740 item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1741 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1741 base::Unretained(this), run_loop.QuitClosure())); 1742 base::Unretained(this), run_loop.QuitClosure()));
1742 run_loop.Run(); 1743 run_loop.Run();
1743 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 1744 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
1744 Mock::VerifyAndClearExpectations(sb_service_.get()); 1745 Mock::VerifyAndClearExpectations(sb_service_.get());
1745 } 1746 }
1746 { 1747 {
1747 EXPECT_CALL(*sb_service_->mock_database_manager(), 1748 EXPECT_CALL(*sb_service_->mock_database_manager(),
1748 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 1749 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
1749 .WillOnce( 1750 .WillOnce(
1750 DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), Return(false))); 1751 DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), Return(false)));
1751 RunLoop run_loop; 1752 RunLoop run_loop;
1752 download_service_->CheckDownloadUrl( 1753 download_service_->CheckDownloadUrl(
1753 item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1754 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1754 base::Unretained(this), run_loop.QuitClosure())); 1755 base::Unretained(this), run_loop.QuitClosure()));
1755 run_loop.Run(); 1756 run_loop.Run();
1756 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 1757 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
1757 Mock::VerifyAndClearExpectations(sb_service_.get()); 1758 Mock::VerifyAndClearExpectations(sb_service_.get());
1758 } 1759 }
1759 { 1760 {
1760 EXPECT_CALL(*sb_service_->mock_database_manager(), 1761 EXPECT_CALL(*sb_service_->mock_database_manager(),
1761 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 1762 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
1762 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), 1763 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE),
1763 Return(false))); 1764 Return(false)));
1764 RunLoop run_loop; 1765 RunLoop run_loop;
1765 download_service_->CheckDownloadUrl( 1766 download_service_->CheckDownloadUrl(
1766 item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1767 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1767 base::Unretained(this), run_loop.QuitClosure())); 1768 base::Unretained(this), run_loop.QuitClosure()));
1768 run_loop.Run(); 1769 run_loop.Run();
1769 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 1770 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
1770 Mock::VerifyAndClearExpectations(sb_service_.get()); 1771 Mock::VerifyAndClearExpectations(sb_service_.get());
1771 } 1772 }
1772 { 1773 {
1773 EXPECT_CALL(*sb_service_->mock_database_manager(), 1774 EXPECT_CALL(*sb_service_->mock_database_manager(),
1774 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 1775 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
1775 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), 1776 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL),
1776 Return(false))); 1777 Return(false)));
1777 RunLoop run_loop; 1778 RunLoop run_loop;
1778 download_service_->CheckDownloadUrl( 1779 download_service_->CheckDownloadUrl(
1779 item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1780 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1780 base::Unretained(this), run_loop.QuitClosure())); 1781 base::Unretained(this), run_loop.QuitClosure()));
1781 run_loop.Run(); 1782 run_loop.Run();
1782 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 1783 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
1783 } 1784 }
1784 } 1785 }
1785 1786
1786 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { 1787 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) {
1787 net::TestURLFetcherFactory factory; 1788 net::TestURLFetcherFactory factory;
1788 1789
1789 content::MockDownloadItem item; 1790 content::MockDownloadItem item;
1790 PrepareBasicDownloadItem( 1791 PrepareBasicDownloadItem(
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2322 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2322 base::Unretained(this), run_loop.QuitClosure())); 2323 base::Unretained(this), run_loop.QuitClosure()));
2323 run_loop.Run(); 2324 run_loop.Run();
2324 2325
2325 EXPECT_FALSE(HasClientDownloadRequest()); 2326 EXPECT_FALSE(HasClientDownloadRequest());
2326 // Overriden by flag: 2327 // Overriden by flag:
2327 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2328 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2328 } 2329 }
2329 2330
2330 } // namespace safe_browsing 2331 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698