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

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

Issue 2163883005: WIP: Obtain Bootstrap from utility process Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 27 matching lines...) Expand all
38 #include "chrome/common/safe_browsing/binary_feature_extractor.h" 38 #include "chrome/common/safe_browsing/binary_feature_extractor.h"
39 #include "chrome/common/safe_browsing/csd.pb.h" 39 #include "chrome/common/safe_browsing/csd.pb.h"
40 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" 40 #include "chrome/common/safe_browsing/file_type_policies_test_util.h"
41 #include "chrome/test/base/testing_profile.h" 41 #include "chrome/test/base/testing_profile.h"
42 #include "components/history/core/browser/history_service.h" 42 #include "components/history/core/browser/history_service.h"
43 #include "components/prefs/pref_service.h" 43 #include "components/prefs/pref_service.h"
44 #include "components/safe_browsing_db/database_manager.h" 44 #include "components/safe_browsing_db/database_manager.h"
45 #include "components/safe_browsing_db/test_database_manager.h" 45 #include "components/safe_browsing_db/test_database_manager.h"
46 #include "content/public/browser/download_danger_type.h" 46 #include "content/public/browser/download_danger_type.h"
47 #include "content/public/browser/page_navigator.h" 47 #include "content/public/browser/page_navigator.h"
48 #include "content/public/browser/service_manager_context.h"
48 #include "content/public/test/mock_download_item.h" 49 #include "content/public/test/mock_download_item.h"
49 #include "content/public/test/test_browser_thread_bundle.h" 50 #include "content/public/test/test_browser_thread_bundle.h"
50 #include "content/public/test/test_utils.h" 51 #include "content/public/test/test_utils.h"
51 #include "net/base/url_util.h" 52 #include "net/base/url_util.h"
52 #include "net/cert/x509_certificate.h" 53 #include "net/cert/x509_certificate.h"
53 #include "net/http/http_status_code.h" 54 #include "net/http/http_status_code.h"
54 #include "net/url_request/test_url_fetcher_factory.h" 55 #include "net/url_request/test_url_fetcher_factory.h"
55 #include "net/url_request/url_fetcher_delegate.h" 56 #include "net/url_request/url_fetcher_delegate.h"
56 #include "net/url_request/url_fetcher_impl.h" 57 #include "net/url_request/url_fetcher_impl.h"
57 #include "net/url_request/url_request_status.h" 58 #include "net/url_request/url_request_status.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 base::Owned(check))); 237 base::Owned(check)));
237 } 238 }
238 239
239 class DownloadProtectionServiceTest : public testing::Test { 240 class DownloadProtectionServiceTest : public testing::Test {
240 protected: 241 protected:
241 DownloadProtectionServiceTest() 242 DownloadProtectionServiceTest()
242 : test_browser_thread_bundle_( 243 : test_browser_thread_bundle_(
243 content::TestBrowserThreadBundle::IO_MAINLOOP) { 244 content::TestBrowserThreadBundle::IO_MAINLOOP) {
244 } 245 }
245 void SetUp() override { 246 void SetUp() override {
247 service_manager_context_ = content::ServiceManagerContext::Create();
246 // Start real threads for the IO and File threads so that the DCHECKs 248 // Start real threads for the IO and File threads so that the DCHECKs
247 // to test that we're on the correct thread work. 249 // to test that we're on the correct thread work.
248 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); 250 sb_service_ = new StrictMock<FakeSafeBrowsingService>();
249 sb_service_->Initialize(); 251 sb_service_->Initialize();
250 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>(); 252 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>();
251 ON_CALL(*binary_feature_extractor_, ExtractImageFeatures(_, _, _, _)) 253 ON_CALL(*binary_feature_extractor_, ExtractImageFeatures(_, _, _, _))
252 .WillByDefault(Return(true)); 254 .WillByDefault(Return(true));
253 download_service_ = sb_service_->download_protection_service(); 255 download_service_ = sb_service_->download_protection_service();
254 download_service_->binary_feature_extractor_ = binary_feature_extractor_; 256 download_service_->binary_feature_extractor_ = binary_feature_extractor_;
255 download_service_->SetEnabled(true); 257 download_service_->SetEnabled(true);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // This will effectivly mask the global Singleton while this is in scope. 525 // This will effectivly mask the global Singleton while this is in scope.
524 FileTypePoliciesTestOverlay policies_; 526 FileTypePoliciesTestOverlay policies_;
525 527
526 scoped_refptr<FakeSafeBrowsingService> sb_service_; 528 scoped_refptr<FakeSafeBrowsingService> sb_service_;
527 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; 529 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_;
528 DownloadProtectionService* download_service_; 530 DownloadProtectionService* download_service_;
529 DownloadProtectionService::DownloadCheckResult result_; 531 DownloadProtectionService::DownloadCheckResult result_;
530 bool has_result_; 532 bool has_result_;
531 content::TestBrowserThreadBundle test_browser_thread_bundle_; 533 content::TestBrowserThreadBundle test_browser_thread_bundle_;
532 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; 534 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
535 std::unique_ptr<content::ServiceManagerContext> service_manager_context_;
533 base::FilePath testdata_path_; 536 base::FilePath testdata_path_;
534 DownloadProtectionService::ClientDownloadRequestSubscription 537 DownloadProtectionService::ClientDownloadRequestSubscription
535 client_download_request_subscription_; 538 client_download_request_subscription_;
536 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; 539 std::unique_ptr<ClientDownloadRequest> last_client_download_request_;
537 base::ScopedTempDir profile_dir_; 540 base::ScopedTempDir profile_dir_;
538 std::unique_ptr<TestingProfile> profile_; 541 std::unique_ptr<TestingProfile> profile_;
539 // The following 5 fields are used by PrepareBasicDownloadItem() function to 542 // The following 5 fields are used by PrepareBasicDownloadItem() function to
540 // store attributes of the last download item. 543 // store attributes of the last download item.
541 std::vector<GURL> url_chain_; 544 std::vector<GURL> url_chain_;
542 GURL referrer_; 545 GURL referrer_;
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2406 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2404 base::Unretained(this), run_loop.QuitClosure())); 2407 base::Unretained(this), run_loop.QuitClosure()));
2405 run_loop.Run(); 2408 run_loop.Run();
2406 2409
2407 EXPECT_FALSE(HasClientDownloadRequest()); 2410 EXPECT_FALSE(HasClientDownloadRequest());
2408 // Overriden by flag: 2411 // Overriden by flag:
2409 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2412 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2410 } 2413 }
2411 2414
2412 } // namespace safe_browsing 2415 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698