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 28 matching lines...) Expand all Loading... |
39 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 39 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
40 #include "chrome/common/safe_browsing/csd.pb.h" | 40 #include "chrome/common/safe_browsing/csd.pb.h" |
41 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" | 41 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" |
42 #include "chrome/test/base/testing_profile.h" | 42 #include "chrome/test/base/testing_profile.h" |
43 #include "components/history/core/browser/history_service.h" | 43 #include "components/history/core/browser/history_service.h" |
44 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
45 #include "components/safe_browsing_db/database_manager.h" | 45 #include "components/safe_browsing_db/database_manager.h" |
46 #include "components/safe_browsing_db/test_database_manager.h" | 46 #include "components/safe_browsing_db/test_database_manager.h" |
47 #include "content/public/browser/download_danger_type.h" | 47 #include "content/public/browser/download_danger_type.h" |
48 #include "content/public/browser/page_navigator.h" | 48 #include "content/public/browser/page_navigator.h" |
| 49 #include "content/public/browser/shell_context.h" |
49 #include "content/public/test/mock_download_item.h" | 50 #include "content/public/test/mock_download_item.h" |
50 #include "content/public/test/test_browser_thread_bundle.h" | 51 #include "content/public/test/test_browser_thread_bundle.h" |
51 #include "content/public/test/test_utils.h" | 52 #include "content/public/test/test_utils.h" |
52 #include "net/base/url_util.h" | 53 #include "net/base/url_util.h" |
53 #include "net/cert/x509_certificate.h" | 54 #include "net/cert/x509_certificate.h" |
54 #include "net/http/http_status_code.h" | 55 #include "net/http/http_status_code.h" |
55 #include "net/url_request/test_url_fetcher_factory.h" | 56 #include "net/url_request/test_url_fetcher_factory.h" |
56 #include "net/url_request/url_fetcher_delegate.h" | 57 #include "net/url_request/url_fetcher_delegate.h" |
57 #include "net/url_request/url_fetcher_impl.h" | 58 #include "net/url_request/url_fetcher_impl.h" |
58 #include "net/url_request/url_request_status.h" | 59 #include "net/url_request/url_request_status.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 base::Owned(check))); | 238 base::Owned(check))); |
238 } | 239 } |
239 | 240 |
240 class DownloadProtectionServiceTest : public testing::Test { | 241 class DownloadProtectionServiceTest : public testing::Test { |
241 protected: | 242 protected: |
242 DownloadProtectionServiceTest() | 243 DownloadProtectionServiceTest() |
243 : test_browser_thread_bundle_( | 244 : test_browser_thread_bundle_( |
244 content::TestBrowserThreadBundle::IO_MAINLOOP) { | 245 content::TestBrowserThreadBundle::IO_MAINLOOP) { |
245 } | 246 } |
246 void SetUp() override { | 247 void SetUp() override { |
| 248 shell_context_ = content::ShellContext::Create(); |
247 // Start real threads for the IO and File threads so that the DCHECKs | 249 // Start real threads for the IO and File threads so that the DCHECKs |
248 // to test that we're on the correct thread work. | 250 // to test that we're on the correct thread work. |
249 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); | 251 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); |
250 sb_service_->Initialize(); | 252 sb_service_->Initialize(); |
251 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>(); | 253 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>(); |
252 ON_CALL(*binary_feature_extractor_, ExtractImageFeatures(_, _, _, _)) | 254 ON_CALL(*binary_feature_extractor_, ExtractImageFeatures(_, _, _, _)) |
253 .WillByDefault(Return(true)); | 255 .WillByDefault(Return(true)); |
254 download_service_ = sb_service_->download_protection_service(); | 256 download_service_ = sb_service_->download_protection_service(); |
255 download_service_->binary_feature_extractor_ = binary_feature_extractor_; | 257 download_service_->binary_feature_extractor_ = binary_feature_extractor_; |
256 download_service_->SetEnabled(true); | 258 download_service_->SetEnabled(true); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // This will effectivly mask the global Singleton while this is in scope. | 526 // This will effectivly mask the global Singleton while this is in scope. |
525 FileTypePoliciesTestOverlay policies_; | 527 FileTypePoliciesTestOverlay policies_; |
526 | 528 |
527 scoped_refptr<FakeSafeBrowsingService> sb_service_; | 529 scoped_refptr<FakeSafeBrowsingService> sb_service_; |
528 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; | 530 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; |
529 DownloadProtectionService* download_service_; | 531 DownloadProtectionService* download_service_; |
530 DownloadProtectionService::DownloadCheckResult result_; | 532 DownloadProtectionService::DownloadCheckResult result_; |
531 bool has_result_; | 533 bool has_result_; |
532 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 534 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
533 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 535 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
| 536 std::unique_ptr<content::ShellContext> shell_context_; |
534 base::FilePath testdata_path_; | 537 base::FilePath testdata_path_; |
535 DownloadProtectionService::ClientDownloadRequestSubscription | 538 DownloadProtectionService::ClientDownloadRequestSubscription |
536 client_download_request_subscription_; | 539 client_download_request_subscription_; |
537 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; | 540 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; |
538 base::ScopedTempDir profile_dir_; | 541 base::ScopedTempDir profile_dir_; |
539 std::unique_ptr<TestingProfile> profile_; | 542 std::unique_ptr<TestingProfile> profile_; |
540 // The following 5 fields are used by PrepareBasicDownloadItem() function to | 543 // The following 5 fields are used by PrepareBasicDownloadItem() function to |
541 // store attributes of the last download item. | 544 // store attributes of the last download item. |
542 std::vector<GURL> url_chain_; | 545 std::vector<GURL> url_chain_; |
543 GURL referrer_; | 546 GURL referrer_; |
(...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2287 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
2285 base::Unretained(this))); | 2288 base::Unretained(this))); |
2286 base::RunLoop().Run(); | 2289 base::RunLoop().Run(); |
2287 | 2290 |
2288 EXPECT_FALSE(HasClientDownloadRequest()); | 2291 EXPECT_FALSE(HasClientDownloadRequest()); |
2289 // Overriden by flag: | 2292 // Overriden by flag: |
2290 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2293 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2291 } | 2294 } |
2292 | 2295 |
2293 } // namespace safe_browsing | 2296 } // namespace safe_browsing |
OLD | NEW |