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 #include <map> | 10 #include <map> |
| 11 #include <memory> |
10 #include <string> | 12 #include <string> |
11 | 13 |
12 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
13 #include "base/bind.h" | 15 #include "base/bind.h" |
14 #include "base/callback.h" | 16 #include "base/callback.h" |
15 #include "base/command_line.h" | 17 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
18 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
19 #include "base/macros.h" | 21 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_ptr.h" | |
22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
24 #include "base/run_loop.h" | 25 #include "base/run_loop.h" |
25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
26 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
27 #include "chrome/browser/history/history_service_factory.h" | 28 #include "chrome/browser/history/history_service_factory.h" |
28 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 29 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
29 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 30 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
30 #include "chrome/browser/safe_browsing/local_database_manager.h" | 31 #include "chrome/browser/safe_browsing/local_database_manager.h" |
31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 scoped_refptr<FakeSafeBrowsingService> sb_service_; | 423 scoped_refptr<FakeSafeBrowsingService> sb_service_; |
423 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; | 424 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; |
424 DownloadProtectionService* download_service_; | 425 DownloadProtectionService* download_service_; |
425 DownloadProtectionService::DownloadCheckResult result_; | 426 DownloadProtectionService::DownloadCheckResult result_; |
426 bool has_result_; | 427 bool has_result_; |
427 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 428 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
428 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 429 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
429 base::FilePath testdata_path_; | 430 base::FilePath testdata_path_; |
430 DownloadProtectionService::ClientDownloadRequestSubscription | 431 DownloadProtectionService::ClientDownloadRequestSubscription |
431 client_download_request_subscription_; | 432 client_download_request_subscription_; |
432 scoped_ptr<ClientDownloadRequest> last_client_download_request_; | 433 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; |
433 base::ScopedTempDir profile_dir_; | 434 base::ScopedTempDir profile_dir_; |
434 scoped_ptr<TestingProfile> profile_; | 435 std::unique_ptr<TestingProfile> profile_; |
435 }; | 436 }; |
436 | 437 |
437 | 438 |
438 void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptZip( | 439 void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptZip( |
439 bool is_extended_reporting, | 440 bool is_extended_reporting, |
440 bool is_incognito) { | 441 bool is_incognito) { |
441 ClientDownloadResponse response; | 442 ClientDownloadResponse response; |
442 response.set_verdict(ClientDownloadResponse::SAFE); | 443 response.set_verdict(ClientDownloadResponse::SAFE); |
443 net::FakeURLFetcherFactory factory(NULL); | 444 net::FakeURLFetcherFactory factory(NULL); |
444 // Empty response means SAFE. | 445 // Empty response means SAFE. |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 net::TestURLFetcherFactory factory; | 1742 net::TestURLFetcherFactory factory; |
1742 | 1743 |
1743 std::vector<GURL> url_chain; | 1744 std::vector<GURL> url_chain; |
1744 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 1745 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
1745 GURL referrer("http://www.google.com/"); | 1746 GURL referrer("http://www.google.com/"); |
1746 GURL tab_url("http://www.google.com/tab"); | 1747 GURL tab_url("http://www.google.com/tab"); |
1747 base::FilePath tmp_path(FILE_PATH_LITERAL("a.tmp")); | 1748 base::FilePath tmp_path(FILE_PATH_LITERAL("a.tmp")); |
1748 base::FilePath final_path(FILE_PATH_LITERAL("a.exe")); | 1749 base::FilePath final_path(FILE_PATH_LITERAL("a.exe")); |
1749 std::string hash = "hash"; | 1750 std::string hash = "hash"; |
1750 | 1751 |
1751 scoped_ptr<content::MockDownloadItem> item(new content::MockDownloadItem); | 1752 std::unique_ptr<content::MockDownloadItem> item( |
| 1753 new content::MockDownloadItem); |
1752 EXPECT_CALL(*item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path)); | 1754 EXPECT_CALL(*item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path)); |
1753 EXPECT_CALL(*item, GetTargetFilePath()) | 1755 EXPECT_CALL(*item, GetTargetFilePath()) |
1754 .WillRepeatedly(ReturnRef(final_path)); | 1756 .WillRepeatedly(ReturnRef(final_path)); |
1755 EXPECT_CALL(*item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 1757 EXPECT_CALL(*item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
1756 EXPECT_CALL(*item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 1758 EXPECT_CALL(*item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
1757 EXPECT_CALL(*item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); | 1759 EXPECT_CALL(*item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); |
1758 EXPECT_CALL(*item, GetTabReferrerUrl()) | 1760 EXPECT_CALL(*item, GetTabReferrerUrl()) |
1759 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 1761 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
1760 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 1762 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
1761 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(100)); | 1763 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2003 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
2002 base::Unretained(this))); | 2004 base::Unretained(this))); |
2003 MessageLoop::current()->Run(); | 2005 MessageLoop::current()->Run(); |
2004 | 2006 |
2005 EXPECT_FALSE(HasClientDownloadRequest()); | 2007 EXPECT_FALSE(HasClientDownloadRequest()); |
2006 // Overriden by flag: | 2008 // Overriden by flag: |
2007 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2009 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2008 } | 2010 } |
2009 | 2011 |
2010 } // namespace safe_browsing | 2012 } // namespace safe_browsing |
OLD | NEW |