chromium/chrome/browser/first_party_sets/first_party_sets_policy_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/first_party_sets/first_party_sets_policy_service.h"

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "chrome/browser/first_party_sets/first_party_sets_policy_service_factory.h"
#include "chrome/browser/first_party_sets/scoped_mock_first_party_sets_handler.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/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/tracking_protection_prefs.h"
#include "content/public/browser/first_party_sets_handler.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/features.h"
#include "net/base/schemeful_site.h"
#include "net/first_party_sets/first_party_set_entry.h"
#include "net/first_party_sets/first_party_set_entry_override.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "net/first_party_sets/first_party_sets_context_config.h"
#include "net/first_party_sets/global_first_party_sets.h"
#include "services/network/public/mojom/first_party_sets_access_delegate.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

_;
Eq;
IsEmpty;
Not;
Optional;
Pair;
UnorderedElementsAre;

MATCHER_P(CarryingConfig, config, "") {}

MATCHER_P2(CarryingConfigAndCacheFilter, config, cache_filter, "") {}

namespace first_party_sets {

namespace {
const base::Version kVersion("1.2.3");
}

class MockFirstPartySetsAccessDelegate
    : public network::mojom::FirstPartySetsAccessDelegate {};

class DefaultFirstPartySetsPolicyServiceTest : public testing::Test {};

TEST_F(DefaultFirstPartySetsPolicyServiceTest, DisabledByFeature) {}

TEST_F(DefaultFirstPartySetsPolicyServiceTest, GuestProfiles) {}

TEST_F(DefaultFirstPartySetsPolicyServiceTest, EnabledForLegitProfile) {}

class FirstPartySetsPolicyServiceTest
    : public DefaultFirstPartySetsPolicyServiceTest {};

TEST_F(FirstPartySetsPolicyServiceTest, IsSiteInManagedSet_WithoutConfig) {}

TEST_F(FirstPartySetsPolicyServiceTest, IsSiteInManagedSet_SiteNotInConfig) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       IsSiteInManagedSet_SiteInConfig_AsDeletion) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       IsSiteInManagedSet_SiteInConfig_AsModification) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       OnFirstPartySetsEnabledChanged_EnabledByBlock3pcToggle) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       OnFirstPartySetsEnabledChanged_DisabledByBlock3pcToggle) {}

// Parameterized test class that controls whether the enabled pref status we are
// setting is for the existing pref or the 3PCD prefs.
class FirstPartySetsPolicyServicePrefTest
    : public FirstPartySetsPolicyServiceTest,
      public testing::WithParamInterface</*enable_3pcd=*/bool> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(FirstPartySetsPolicyServicePrefTest,
       IsSiteInManagedSet_SiteInConfig_PrefDisabled) {}

TEST_P(FirstPartySetsPolicyServicePrefTest, FindEntry_FpsDisabledByPref) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       FindEntry_FpsEnabled_ReturnsEmptyUntilAllSetsReady) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       FindEntry_NumQueriesRecorded_BeforeConfigReady) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       FindEntry_NumQueriesRecorded_AfterConfigReady) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       ForEachEffectiveSetEntry_FPSDisabledByPref) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       ForEachEffectiveSetEntry_ReturnsEmptyUntilAllSetsReady) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       ForEachEffectiveSetEntry_WithNonEmptyConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnProfileConfigReady_InitDisabled_NotifiesReadyWithConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Default_WithConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Default_WithoutConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Disables_WithConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Disables_WithoutConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Enables_WithConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_Enables_WithoutConfig) {}

TEST_F(FirstPartySetsPolicyServicePrefTest,
       OnFirstPartySetsEnabledChanged_OTRProfile) {}

TEST_F(FirstPartySetsPolicyServiceTest, NotifiesReadyWithConfigAndCacheFilter) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       ComputeFirstPartySetMetadata_BeforeInitialization) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       ComputeFirstPartySetMetadata_AfterInitialization_StillAsync) {}

TEST_F(FirstPartySetsPolicyServiceTest,
       ComputeFirstPartySetMetadata_AfterInitialization_Sync) {}

TEST_P(FirstPartySetsPolicyServicePrefTest,
       ComputeFirstPartySetMetadata_PrefDisabled) {}

class ThirdPartyCookieBlockingFirstPartySetsPolicyServiceTest
    : public DefaultFirstPartySetsPolicyServiceTest {};

TEST_F(ThirdPartyCookieBlockingFirstPartySetsPolicyServiceTest, EnabledAtInit) {}

TEST_F(ThirdPartyCookieBlockingFirstPartySetsPolicyServiceTest, AlwaysEnabled) {}

class FirstPartySetsPolicyServiceResumeThrottleTest
    : public FirstPartySetsPolicyServiceTest {};

// Verify the throttle resume callback is always invoked.
TEST_F(FirstPartySetsPolicyServiceResumeThrottleTest,
       RegisterThrottleResumeCallback) {}

}  // namespace first_party_sets