chromium/services/network/restricted_cookie_manager_unittest.cc

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

#include "services/network/restricted_cookie_manager.h"

#include <set>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "base/version.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/functions.h"
#include "net/base/features.h"
#include "net/base/isolation_info.h"
#include "net/base/network_isolation_key.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_partition_key.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/site_for_cookies.h"
#include "net/cookies/test_cookie_access_delegate.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "net/first_party_sets/global_first_party_sets.h"
#include "net/storage_access_api/status.h"
#include "services/network/cookie_access_delegate_impl.h"
#include "services/network/cookie_settings.h"
#include "services/network/first_party_sets/first_party_sets_access_delegate.h"
#include "services/network/public/mojom/cookie_access_observer.mojom.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/restricted_cookie_manager.mojom-shared.h"
#include "services/network/test/test_network_context_client.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
#include "url/url_util.h"

AllOf;

namespace net {
bool operator==(const net::SiteForCookies& a, const net::SiteForCookies& b) {}
}  // namespace net

namespace network {

namespace {

net::FirstPartySetMetadata ComputeFirstPartySetMetadataSync(
    const url::Origin& origin,
    const net::CookieStore* cookie_store,
    const net::IsolationInfo& isolation_info) {}

}  // namespace

class RecordingCookieObserver : public network::mojom::CookieAccessObserver {};

// Synchronous proxies to a wrapped RestrictedCookieManager's methods.
class RestrictedCookieManagerSync {};

namespace {

// Stashes the cookie changes it receives, for testing.
class TestCookieChangeListener : public network::mojom::CookieChangeListener {};

}  // namespace

class RestrictedCookieManagerTest
    : public testing::TestWithParam<mojom::RestrictedCookieManagerRole> {};

namespace {

Contains;
ElementsAre;
ElementsAreArray;
IsEmpty;
Not;
UnorderedElementsAre;

CanonicalCookieMatcher;

MATCHER_P5(MatchesCookieOp,
           type,
           url,
           site_for_cookies,
           cookie_or_line,
           status,
           "") {}

MATCHER_P2(CookieOrLine, string, type, "") {}

}  // anonymous namespace

// Test the case when `origin` differs from `isolation_info.frame_origin`.
// RestrictedCookieManager only works for the bound origin and doesn't care
// about the IsolationInfo's frame_origin. Technically this should only happen
// when role == mojom::RestrictedCookieManagerRole::NETWORK. Otherwise, it
// should trigger a CHECK in the RestrictedCookieManager constructor (which is
// bypassed here due to constructing it properly, then using an origin
// override).
TEST_P(RestrictedCookieManagerTest,
       GetAllForUrlFromMismatchingIsolationInfoFrameOrigin) {}

// TODO(crbug.com/40061885): Add test cases that modify the cookies through
// net::CookieStore::SetCanonicalCookie and/or modify the subscription URL.
TEST_P(RestrictedCookieManagerTest, CookieVersion) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlBlankFilter) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlEmptyFilter) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlEqualsMatch) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlEqualsMatch_WithStorageAccess) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlStartsWithMatch) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlHttpOnly) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlFromWrongOrigin) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlFromOpaqueOrigin) {}

TEST_P(RestrictedCookieManagerTest, GetCookieStringFromWrongOrigin) {}

TEST_P(RestrictedCookieManagerTest, GetAllAdTagged) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) {}

TEST_P(RestrictedCookieManagerTest, FilteredCookieAccessEvents) {}

TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicyWarnActual) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookie) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookie_WithStorageAccess) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieHttpOnly) {}

TEST_P(RestrictedCookieManagerTest, SetCookieFromString) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieFromWrongOrigin) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieFromOpaqueOrigin) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieWithMismatchingDomain) {}

TEST_P(RestrictedCookieManagerTest, SetCookieFromStringWrongOrigin) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicy) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicyWarnActual) {}

TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieWithInclusionStatus) {}

TEST_P(RestrictedCookieManagerTest, CookiesEnabledFor) {}

TEST_P(RestrictedCookieManagerTest, CookiesEnabledFor_WithStorageAccess) {}

// Test that special chrome:// scheme always attaches SameSite cookies when the
// requested origin is secure.
TEST_P(RestrictedCookieManagerTest, SameSiteCookiesSpecialScheme) {}

TEST_P(RestrictedCookieManagerTest, ChangeDispatch) {}

TEST_P(RestrictedCookieManagerTest, ChangeSettings) {}

TEST_P(RestrictedCookieManagerTest, AddChangeListenerFromWrongOrigin) {}

TEST_P(RestrictedCookieManagerTest, AddChangeListenerFromOpaqueOrigin) {}

// Test that the Change listener receives the access semantics, and that they
// are taken into account when deciding when to dispatch the change.
TEST_P(RestrictedCookieManagerTest, ChangeNotificationIncludesAccessSemantics) {}

TEST_P(RestrictedCookieManagerTest, NoChangeNotificationForNonlegacyCookie) {}

// Test Partitioned cookie behavior when feature is enabled.
TEST_P(RestrictedCookieManagerTest, PartitionedCookies) {}

TEST_P(RestrictedCookieManagerTest, PartitionKeyFromScript) {}

TEST_P(RestrictedCookieManagerTest, PartitionKeyWithNonce) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace network