#include <memory>
#include "base/base64.h"
#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_commands.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_features.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client_factory.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_browsertest_base.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/identifiers/profile_id_service_factory.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_fcm_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/cloud_binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/cloud_binary_upload_service_factory.h"
#include "chrome/browser/safe_browsing/download_protection/deep_scanning_request.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/download_protection/ppapi_download_request.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_features.h"
#include "components/enterprise/browser/identifiers/profile_id_service.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/common/file_type_policies_test_util.h"
#include "components/safe_browsing/core/browser/db/test_database_manager.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/save_page_type.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/data_element.h"
#include "services/network/public/mojom/data_pipe_getter.mojom.h"
#include "services/network/test/test_utils.h"
namespace safe_browsing {
namespace {
constexpr char kUserName[] = …;
constexpr char kResumableUploadUrl[] = …;
bool GetMultipartUploadMetadata(
const std::string& upload_request,
enterprise_connectors::ContentAnalysisRequest* out_proto) { … }
bool GetResumableUploadMetadata(
const std::string& upload_request,
enterprise_connectors::ContentAnalysisRequest* out_proto) { … }
}
class FakeBinaryFCMService : public BinaryFCMService { … };
class DownloadDeepScanningBrowserTestBase
: public enterprise_connectors::test::DeepScanningBrowserTestBase,
public content::DownloadManager::Observer,
public download::DownloadItem::Observer { … };
class ConsumerDeepScanningBrowserTest
: public DownloadDeepScanningBrowserTestBase { … };
class DownloadDeepScanningBrowserTest
: public DownloadDeepScanningBrowserTestBase,
public testing::WithParamInterface<std::tuple<bool, bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest,
SafeDownloadHasCorrectDangerType) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest, FailedScanFailsOpen) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest,
PartialFailureShowsMalwareWarning) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest,
PartialFailureShowsDlpWarning) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest,
PasswordProtectedTxtFilesAreBlocked) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest, MultipleFCMResponses) { … }
IN_PROC_BROWSER_TEST_P(DownloadDeepScanningBrowserTest,
DlpAndMalwareViolations) { … }
class DownloadRestrictionsDeepScanningBrowserTest
: public DownloadDeepScanningBrowserTestBase,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(DownloadRestrictionsDeepScanningBrowserTest,
ReportsDownloadsBlockedByDownloadRestrictions) { … }
class AllowlistedUrlDeepScanningBrowserTest
: public DownloadDeepScanningBrowserTestBase,
public testing::WithParamInterface<std::tuple<bool, bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(AllowlistedUrlDeepScanningBrowserTest,
AllowlistedUrlStillDoesDlpAndMalware) { … }
class WaitForModalObserver : public DeepScanningRequest::Observer { … };
class WaitForFinishObserver : public DeepScanningRequest::Observer { … };
IN_PROC_BROWSER_TEST_F(ConsumerDeepScanningBrowserTest, ErrorIndicatesFailure) { … }
class SavePackageDeepScanningBrowserTest
: public DownloadDeepScanningBrowserTestBase,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(SavePackageDeepScanningBrowserTest, Allowed) { … }
IN_PROC_BROWSER_TEST_P(SavePackageDeepScanningBrowserTest, Blocked) { … }
IN_PROC_BROWSER_TEST_P(SavePackageDeepScanningBrowserTest, KeepAfterWarning) { … }
IN_PROC_BROWSER_TEST_P(SavePackageDeepScanningBrowserTest,
DiscardAfterWarning) { … }
IN_PROC_BROWSER_TEST_P(SavePackageDeepScanningBrowserTest, OpenNow) { … }
}