Commit b19c3d4d authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add browser test for the deep scanning of downloads

This CL adds a fixture that can be used for integration tests when deep
scanning downloads. Future CLs will use this fixture for testing the
core user journeys in download deep scanning.

Bug: 1060367
Change-Id: I1aea7d4821e9abe6230038419de7061bee88e5a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2117294Reviewed-by: default avatarXinghui Lu <xinghuilu@chromium.org>
Reviewed-by: default avatarDominique Fauteux-Chapleau <domfc@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753742}
parent e334b16e
......@@ -16,7 +16,10 @@
namespace safe_browsing {
// TestSafeBrowsingService functions:
TestSafeBrowsingService::TestSafeBrowsingService() {
TestSafeBrowsingService::TestSafeBrowsingService()
: test_shared_loader_factory_(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {
#if BUILDFLAG(FULL_SAFE_BROWSING)
services_delegate_ = ServicesDelegate::CreateForTest(this, this);
#endif // BUILDFLAG(FULL_SAFE_BROWSING)
......@@ -34,6 +37,17 @@ void TestSafeBrowsingService::UseV4LocalDatabaseManager() {
use_v4_local_db_manager_ = true;
}
void TestSafeBrowsingService::SetUseTestUrlLoaderFactory(
bool use_test_url_loader_factory) {
use_test_url_loader_factory_ = use_test_url_loader_factory;
}
network::TestURLLoaderFactory*
TestSafeBrowsingService::GetTestUrlLoaderFactory() {
DCHECK(use_test_url_loader_factory_);
return &test_url_loader_factory_;
}
std::unique_ptr<SafeBrowsingService::StateSubscription>
TestSafeBrowsingService::RegisterStateCallback(
const base::Callback<void(void)>& callback) {
......@@ -132,6 +146,13 @@ TestSafeBrowsingService::CreateResourceRequestDetector() {
return nullptr;
}
scoped_refptr<network::SharedURLLoaderFactory>
TestSafeBrowsingService::GetURLLoaderFactory() {
if (use_test_url_loader_factory_)
return test_shared_loader_factory_;
return SafeBrowsingService::GetURLLoaderFactory();
}
// TestSafeBrowsingServiceFactory functions:
TestSafeBrowsingServiceFactory::TestSafeBrowsingServiceFactory()
: test_safe_browsing_service_(nullptr), use_v4_local_db_manager_(false) {}
......
......@@ -11,6 +11,8 @@
#include "chrome/browser/safe_browsing/ui_manager.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/db/v4_protocol_manager_util.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
namespace safe_browsing {
class SafeBrowsingDatabaseManager;
......@@ -61,8 +63,15 @@ class TestSafeBrowsingService : public SafeBrowsingService,
const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager()
const override;
void UseV4LocalDatabaseManager();
// By default, the TestSafeBrowsing service uses a regular URLLoaderFactory.
// This function can be used to override that behavior, exposing a
// TestURLLoaderFactory for mocking network traffic.
void SetUseTestUrlLoaderFactory(bool use_test_url_loader_factory);
std::unique_ptr<SafeBrowsingService::StateSubscription> RegisterStateCallback(
const base::Callback<void(void)>& callback) override;
network::TestURLLoaderFactory* GetTestUrlLoaderFactory();
protected:
// SafeBrowsingService overrides
......@@ -84,11 +93,16 @@ class TestSafeBrowsingService : public SafeBrowsingService,
IncidentReportingService* CreateIncidentReportingService() override;
ResourceRequestDetector* CreateResourceRequestDetector() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
private:
std::unique_ptr<V4ProtocolConfig> v4_protocol_config_;
std::string serialized_download_report_;
scoped_refptr<SafeBrowsingDatabaseManager> test_database_manager_;
bool use_v4_local_db_manager_ = false;
bool use_test_url_loader_factory_ = false;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;
DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingService);
};
......
......@@ -1130,6 +1130,7 @@ if (!is_android) {
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_views_browsertest.cc",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_test_utils.cc",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_test_utils.h",
"../browser/safe_browsing/download_protection/deep_scanning_browsertest.cc",
"../browser/safe_browsing/download_protection/download_protection_service_browsertest.cc",
"../browser/safe_browsing/test_safe_browsing_database_helper.cc",
"../browser/safe_browsing/test_safe_browsing_database_helper.h",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment