chromium/content/browser/cookie_store/cookie_store_manager_unittest.cc

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

#include <memory>

#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/scoped_refptr.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/cookie_store/cookie_store_manager.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/fake_embedded_worker_instance_client.h"
#include "content/browser/service_worker/fake_service_worker.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/common/content_client.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/test/storage_partition_test_helpers.h"
#include "content/test/test_content_browser_client.h"
#include "mojo/public/cpp/test_support/fake_message_dispatch_context.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "net/base/features.h"
#include "net/cookies/cookie_access_result.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_util.h"
#include "services/network/public/cpp/features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {

namespace {

// Synchronous proxies to a wrapped CookieStore service's methods.
class CookieStoreSync {};

const char kExampleScope[] =;
const char kExampleWorkerScript[] =;
const char kGoogleScope[] =;
const char kGoogleWorkerScript[] =;
const char kLegacyScope[] =;
const char kLegacyWorkerScript[] =;
const char kThirdPartyTopLevelSite[] =;

const base::UnguessableToken kStorageKeyNonce =;

// Mocks a service worker that uses the cookieStore API.
class CookieStoreWorkerTestHelper : public EmbeddedWorkerTestHelper {};

}  // namespace

// This class cannot be in an anonymous namespace because it needs to be a
// friend of StoragePartitionImpl, to access its constructor.
class CookieStoreManagerTest
    : public testing::Test,
      public TestContentBrowserClient,
      public testing::WithParamInterface<
          testing::tuple<bool /* reset_context */,
                         bool /* block_third_party_cookies */>> {};

const int64_t CookieStoreManagerTest::kInvalidRegistrationId;

namespace {

// Useful for sorting a vector of cookie change subscriptions.
bool CookieChangeSubscriptionLessThan(
    const blink::mojom::CookieChangeSubscriptionPtr& lhs,
    const blink::mojom::CookieChangeSubscriptionPtr& rhs) {}

TEST_P(CookieStoreManagerTest, NoSubscriptions) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_EmptyInput) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_OneSubscription) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_WrongScopeOrigin) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_NonexistentRegistrationId) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_WrongRegistrationOrigin) {}

TEST_P(CookieStoreManagerTest, AddSubscriptionsMultipleWorkers) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_MultipleSubscriptions) {}

TEST_P(CookieStoreManagerTest, AddSubscriptions_MultipleAddsAcrossRestart) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_EmptyVector) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_OneExistingSubscription) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_OneNonexistingSubscription) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_NonexistentRegistrationId) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_WrongRegistrationOrigin) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_MultipleWorkers) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_MultipleSubscriptionsLeft) {}

TEST_P(CookieStoreManagerTest, RemoveSubscriptions_OneSubscriptionLeft) {}

TEST_P(CookieStoreManagerTest, OneCookieChange) {}

// Same as above except this tests that the LEGACY access semantics for
// legacy.com cookies is correctly reflected in the change info.
TEST_P(CookieStoreManagerTest, OneCookieChangeLegacy) {}

TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWith) {}

// Same as above except this tests that the LEGACY access semantics for
// legacy.com cookies is correctly reflected in the change info.
TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWithLegacy) {}

TEST_P(CookieStoreManagerTest, CookieChangeUrl) {}

// Same as above except this tests that the LEGACY access semantics for
// legacy.com cookies is correctly reflected in the change info.
TEST_P(CookieStoreManagerTest, CookieChangeUrlLegacy) {}

TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) {}

// Same as above except this tests that the LEGACY access semantics for
// legacy.com cookies is correctly reflected in the change info.
TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) {}

TEST_P(CookieStoreManagerTest, CookieChangeForDeletion) {}

TEST_P(CookieStoreManagerTest, CookieChangeForOverwrite) {}

TEST_P(CookieStoreManagerTest, GetSubscriptionsFromWrongOrigin) {}

TEST_F(CookieStoreManagerTest, UnTrustworthyOrigin) {}

// TODO(crbug.com/40063772): Test that the worker still can access unpartitioned
// cookies with third-party cookie blocking on.
TEST_F(CookieStoreManagerTest, PartitionedWorker_FirstPartyPartition) {}

// TODO(crbug.com/40063772): Test that the worker cannot access unpartitioned
// cookies with third-party cookie blocking on.
TEST_P(CookieStoreManagerTest, PartitionedWorker_ThirdPartyPartition) {}

TEST_F(CookieStoreManagerTest, PartitionedWorker_NoncedPartition) {}

TEST_P(CookieStoreManagerTest, PartitionedWorkerBlocksThirdPartyCookies) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace

}  // namespace content