| 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 #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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 456 |
| 457 void OnClientDownloadRequest(content::DownloadItem* download, | 457 void OnClientDownloadRequest(content::DownloadItem* download, |
| 458 const ClientDownloadRequest* request) { | 458 const ClientDownloadRequest* request) { |
| 459 if (request) | 459 if (request) |
| 460 last_client_download_request_.reset(new ClientDownloadRequest(*request)); | 460 last_client_download_request_.reset(new ClientDownloadRequest(*request)); |
| 461 else | 461 else |
| 462 last_client_download_request_.reset(); | 462 last_client_download_request_.reset(); |
| 463 } | 463 } |
| 464 | 464 |
| 465 public: | 465 public: |
| 466 void CheckDoneCallback( | 466 void CheckUrlDoneCallback( |
| 467 DownloadProtectionService::DownloadCheckResult result) { | 467 DownloadProtectionService::DownloadCheckResult result) { |
| 468 result_ = result; | 468 result_ = result; |
| 469 has_result_ = true; | 469 has_result_ = true; |
| 470 MessageLoop::current()->QuitWhenIdle(); | 470 MessageLoop::current()->QuitWhenIdle(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void CheckDoneCallback( |
| 474 DownloadProtectionService::DownloadCheckResult result, |
| 475 const std::string& unused_token) { |
| 476 CheckUrlDoneCallback(result); |
| 477 } |
| 478 |
| 473 void SyncCheckDoneCallback( | 479 void SyncCheckDoneCallback( |
| 474 DownloadProtectionService::DownloadCheckResult result) { | 480 DownloadProtectionService::DownloadCheckResult result, |
| 481 const std::string& token_unused) { |
| 475 result_ = result; | 482 result_ = result; |
| 476 has_result_ = true; | 483 has_result_ = true; |
| 477 } | 484 } |
| 478 | 485 |
| 479 void SendURLFetchComplete(net::TestURLFetcher* fetcher) { | 486 void SendURLFetchComplete(net::TestURLFetcher* fetcher) { |
| 480 fetcher->delegate()->OnURLFetchComplete(fetcher); | 487 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 481 } | 488 } |
| 482 | 489 |
| 483 testing::AssertionResult IsResult( | 490 testing::AssertionResult IsResult( |
| 484 DownloadProtectionService::DownloadCheckResult expected) { | 491 DownloadProtectionService::DownloadCheckResult expected) { |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 1589 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
| 1583 | 1590 |
| 1584 // CheckDownloadURL returns immediately which means the client object callback | 1591 // CheckDownloadURL returns immediately which means the client object callback |
| 1585 // will never be called. Nevertheless the callback provided to | 1592 // will never be called. Nevertheless the callback provided to |
| 1586 // CheckClientDownload must still be called. | 1593 // CheckClientDownload must still be called. |
| 1587 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1594 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1588 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1595 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1589 .WillOnce(Return(true)); | 1596 .WillOnce(Return(true)); |
| 1590 download_service_->CheckDownloadUrl( | 1597 download_service_->CheckDownloadUrl( |
| 1591 item, | 1598 item, |
| 1592 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1599 base::Bind(&DownloadProtectionServiceTest::CheckUrlDoneCallback, |
| 1593 base::Unretained(this))); | 1600 base::Unretained(this))); |
| 1594 MessageLoop::current()->Run(); | 1601 MessageLoop::current()->Run(); |
| 1595 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1602 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1596 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1603 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1597 | 1604 |
| 1598 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1605 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1599 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1606 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1600 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), | 1607 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), |
| 1601 Return(false))); | 1608 Return(false))); |
| 1602 download_service_->CheckDownloadUrl( | 1609 download_service_->CheckDownloadUrl( |
| 1603 item, | 1610 item, |
| 1604 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1611 base::Bind(&DownloadProtectionServiceTest::CheckUrlDoneCallback, |
| 1605 base::Unretained(this))); | 1612 base::Unretained(this))); |
| 1606 MessageLoop::current()->Run(); | 1613 MessageLoop::current()->Run(); |
| 1607 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1614 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1608 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1615 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1609 | 1616 |
| 1610 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1617 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1611 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1618 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1612 .WillOnce(DoAll( | 1619 .WillOnce(DoAll( |
| 1613 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), | 1620 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), |
| 1614 Return(false))); | 1621 Return(false))); |
| 1615 download_service_->CheckDownloadUrl( | 1622 download_service_->CheckDownloadUrl( |
| 1616 item, | 1623 item, |
| 1617 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1624 base::Bind(&DownloadProtectionServiceTest::CheckUrlDoneCallback, |
| 1618 base::Unretained(this))); | 1625 base::Unretained(this))); |
| 1619 MessageLoop::current()->Run(); | 1626 MessageLoop::current()->Run(); |
| 1620 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1627 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1621 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1628 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1622 | 1629 |
| 1623 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1630 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1624 CheckDownloadUrl(ContainerEq(url_chain), | 1631 CheckDownloadUrl(ContainerEq(url_chain), |
| 1625 NotNull())) | 1632 NotNull())) |
| 1626 .WillOnce(DoAll( | 1633 .WillOnce(DoAll( |
| 1627 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), | 1634 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), |
| 1628 Return(false))); | 1635 Return(false))); |
| 1629 download_service_->CheckDownloadUrl( | 1636 download_service_->CheckDownloadUrl( |
| 1630 item, | 1637 item, |
| 1631 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1638 base::Bind(&DownloadProtectionServiceTest::CheckUrlDoneCallback, |
| 1632 base::Unretained(this))); | 1639 base::Unretained(this))); |
| 1633 MessageLoop::current()->Run(); | 1640 MessageLoop::current()->Run(); |
| 1634 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1641 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1635 } | 1642 } |
| 1636 | 1643 |
| 1637 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { | 1644 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { |
| 1638 net::TestURLFetcherFactory factory; | 1645 net::TestURLFetcherFactory factory; |
| 1639 | 1646 |
| 1640 content::MockDownloadItem item; | 1647 content::MockDownloadItem item; |
| 1641 PrepareBasicDownloadItem( | 1648 PrepareBasicDownloadItem( |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2141 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2135 base::Unretained(this))); | 2142 base::Unretained(this))); |
| 2136 MessageLoop::current()->Run(); | 2143 MessageLoop::current()->Run(); |
| 2137 | 2144 |
| 2138 EXPECT_FALSE(HasClientDownloadRequest()); | 2145 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2139 // Overriden by flag: | 2146 // Overriden by flag: |
| 2140 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2147 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2141 } | 2148 } |
| 2142 | 2149 |
| 2143 } // namespace safe_browsing | 2150 } // namespace safe_browsing |
| OLD | NEW |