chromium/chrome/browser/dips/dips_service_unittest.cc

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

#include "chrome/browser/dips/dips_service.h"

#include <optional>

#include "base/files/file_util.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/test_file_util.h"
#include "base/time/default_clock.h"
#include "base/types/pass_key.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/dips/dips_redirect_info.h"
#include "chrome/browser/dips/dips_service_factory.h"
#include "chrome/browser/dips/dips_state.h"
#include "chrome/browser/dips/dips_test_utils.h"
#include "chrome/browser/dips/dips_utils.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_browsing_data_remover_delegate.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/cookie_partition_key.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features_generated.h"
#include "url/gurl.h"

AllOf;
ElementsAre;
IsEmpty;
Pair;

class DIPSServiceTest : public testing::Test {};

TEST_F(DIPSServiceTest, CreateServiceIfFeatureEnabled) {}

TEST_F(DIPSServiceTest, DontCreateServiceIfFeatureDisabled) {}

TEST_F(DIPSServiceTest, NoPrepopulation) {}

// Verifies that if database persistence is disabled via Finch, then when the
// DIPS Service is constructed, it deletes any DIPS Database files for the
// associated BrowserContext.
TEST_F(DIPSServiceTest, DeleteDbFilesIfPersistenceDisabled) {}

// Verifies that when an OTR profile is opened, the DIPS database file for
// the underlying regular profile is NOT deleted.
TEST_F(DIPSServiceTest, PreserveRegularProfileDbFiles) {}

TEST_F(DIPSServiceTest, EmptySiteEventsIgnored) {}

class DIPSServiceStateRemovalTest : public testing::Test {};

TEST_F(DIPSServiceStateRemovalTest,
       CompleteChain_NotifiesRedirectChainObservers) {}

TEST_F(DIPSServiceStateRemovalTest,
       PartialChain_DoesNotNotifyRedirectChainObservers) {}

// NOTE: The use of a MockBrowsingDataRemoverDelegate in this test fixture
// means that when DIPS deletion is enabled, the row for 'url' is not actually
// removed from the DIPS db since 'delegate_' doesn't actually carryout the
// removal task.
TEST_F(DIPSServiceStateRemovalTest, BrowsingDataDeletion_Enabled) {}

TEST_F(DIPSServiceStateRemovalTest, BrowsingDataDeletion_Disabled) {}

TEST_F(DIPSServiceStateRemovalTest,
       BrowsingDataDeletion_Respects3PExceptionsFor3PC) {}

TEST_F(DIPSServiceStateRemovalTest,
       BrowsingDataDeletion_Respects1PExceptionsFor3PC) {}

TEST_F(DIPSServiceStateRemovalTest,
       BrowsingDataDeletion_RespectsStorageAccessGrantExceptions) {}

// When third-party cookies are globally allowed, bounces should be recorded for
// sites which have an exception to block 3PC, but not by default.
TEST_F(
    DIPSServiceStateRemovalTest,
    BrowsingDataDeletion_Respects1PExceptionsForBlocking3PCWhenDefaultAllowed) {}

TEST_F(DIPSServiceStateRemovalTest, ImmediateEnforcement) {}

// A test class that verifies DIPSService state deletion metrics collection
// behavior.
class DIPSServiceHistogramTest : public DIPSServiceStateRemovalTest {};

TEST_F(DIPSServiceHistogramTest, DeletionLatency) {}

TEST_F(DIPSServiceHistogramTest, Deletion_Disallowed) {}

TEST_F(DIPSServiceHistogramTest, Deletion_ExceptedAs1P) {}

TEST_F(DIPSServiceHistogramTest, Deletion_ExceptedAs3P) {}

TEST_F(DIPSServiceHistogramTest, Deletion_Enforced) {}

MATCHER_P(HasSourceId, id, "") {}

MATCHER_P(HasMetrics, matcher, "") {}

DIPSServiceUkmTest;

TEST_F(DIPSServiceUkmTest, BothChainBeginAndChainEnd) {}

TEST_F(DIPSServiceUkmTest, InitialAndFinalSitesSame_True) {}

TEST_F(DIPSServiceUkmTest, DontReportEmptyChainsAtAll) {}

TEST_F(DIPSServiceUkmTest, DontReportChainBeginIfInvalidSourceId) {}

TEST_F(DIPSServiceUkmTest, DontReportChainEndIfInvalidSourceId) {}