chromium/chrome/browser/enterprise/connectors/analysis/content_analysis_delegate_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"

#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/scoped_refptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_delegate.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/analysis_settings.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_sdk_manager.h"  // nogncheck
#endif

namespace enterprise_connectors {

namespace {

constexpr char kDmToken[] =;
constexpr char kTestUrl[] =;

constexpr char kBlockingScansForDlpAndMalware[] =;

constexpr char kBlockingScansForDlp[] =;

constexpr char kBlockingScansForMalware[] =;

constexpr char kNothingEnabled[] =;

// Helpers to get text with sizes relative to the minimum required size of 100
// bytes for scans to trigger.
std::string large_text() {}

std::string small_text() {}

base::ReadOnlySharedMemoryRegion create_page(size_t size) {}

base::ReadOnlySharedMemoryRegion normal_page() {}

class ScopedSetDMToken {};

class BaseTest : public testing::Test {};

}  // namespace

ContentAnalysisDelegateIsEnabledTest;

TEST_F(ContentAnalysisDelegateIsEnabledTest, NoDMTokenNoPref) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, NoDMToken) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpNoPref) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpNoPref2) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpNoPref3) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpEnabled) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpEnabled2) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpEnabledWithUrl) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpDisabledByList) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, DlpDisabledByListWithPatterns) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, MalwareNoPref) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, MalwareNoPref2) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, MalwareNoPref3) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, MalwareEnabled) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, NoScanInIncognito) {}

TEST_F(ContentAnalysisDelegateIsEnabledTest, MalwareEnabledWithPatterns) {}

class ContentAnalysisDelegateAuditOnlyTest : public BaseTest {};

TEST_F(ContentAnalysisDelegateAuditOnlyTest, Empty) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringData) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringData2) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringData3) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, PagePrintAllowed) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, PagePrintBlocked) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest,
       FileDataPositiveMalwareAndDlpVerdicts) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest,
       FileDataPositiveMalwareAndDlpVerdicts2) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileDataPositiveMalwareVerdict) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileIsEncrypted) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileIsEncrypted_PolicyAllows) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileDataNegativeMalwareVerdict) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileDataPositiveDlpVerdict) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, FileDataNegativeDlpVerdict) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest,
       FileDataNegativeMalwareAndDlpVerdicts) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringFileData) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringFileDataNoDLP) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, ImageData) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, TextAndImageData) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringFileDataFailedDLP) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, StringFileDataPartialSuccess) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, NoDelay) {}

TEST_F(ContentAnalysisDelegateAuditOnlyTest, EmptyWait) {}

// test params:
// 0: upload result from binary upload service.
// 1: whether an cloud analysis is done.
// 2: whether to fail open.
class ContentAnalysisDelegateResultHandlingTest
    : public BaseTest,
      public testing::WithParamInterface<
          std::tuple<safe_browsing::BinaryUploadService::Result, bool, bool>> {};

TEST_P(ContentAnalysisDelegateResultHandlingTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

// The following tests should only be executed on the OS that support LCAC.
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
class ContentAnalysisDelegateWithLocalClient : public BaseTest {};

TEST_F(ContentAnalysisDelegateWithLocalClient, StringDataWithValidClient) {}

TEST_F(ContentAnalysisDelegateWithLocalClient, FailOpen) {}

TEST_F(ContentAnalysisDelegateWithLocalClient, FailClosed) {}
#endif

// Calling GetRequestData() twice should return the same valid region.
TEST(StringAnalysisRequest, GetRequestData) {}

}  // namespace enterprise_connectors