chromium/services/network/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.

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

#include "services/network/cookie_manager.h"

#include <algorithm>
#include <vector>

#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/run_loop.h"
#include "base/strings/strcat.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "base/test/scoped_command_line.h"
#include "base/test/spin_wait.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
#include "net/cookies/cookie_access_result.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_store.h"
#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/cookies/cookie_store_test_helpers.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/test_cookie_access_delegate.h"
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/cookie_access_delegate_impl.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/session_cleanup_cookie_store.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

// Test infrastructure outline:
//      # Classes
//      * SynchronousMojoCookieWrapper: Takes a mojom::CookieManager at
//        construction; exposes synchronous interfaces that wrap the
//        mojom::CookieManager async interfaces to make testing easier.
//      * CookieChangeListener: Test class implementing the CookieChangeListener
//        interface and recording incoming messages on it.
//      * CookieManagerTest: Test base class.  Automatically sets up
//        a cookie store, a cookie service wrapping it, a mojo pipe
//        connected to the server, and the cookie service implemented
//        by the other end of the pipe.
//
//      # Functions
//      * CompareCanonicalCookies: Comparison function to make it easy to
//        sort cookie list responses from the mojom::CookieManager.
//      * CompareCookiesByValue: As above, but only by value.

namespace network {
namespace {
StrCat;
IsEmpty;
UnorderedElementsAre;

CookieDeletionInfo;

const base::FilePath::CharType kTestCookiesFilename[] =);

constexpr char kCookieDomain[] =;
constexpr char kCookieURL[] =;
constexpr char kCookieHttpsURL[] =;

// Wraps a mojom::CookieManager in synchronous, blocking calls to make
// it easier to test.
class SynchronousCookieManager {};

class CookieManagerTest : public testing::Test {};

bool CompareCanonicalCookies(const net::CanonicalCookie& c1,
                             const net::CanonicalCookie& c2) {}

// Test the GetAllCookies accessor.  Also tests that canonical
// cookies come out of the store unchanged.
TEST_F(CookieManagerTest, GetAllCookies) {}

TEST_F(CookieManagerTest, GetAllCookiesWithAccessSemantics) {}

TEST_F(CookieManagerTest, GetCookieList) {}

TEST_F(CookieManagerTest, GetCookieListHttpOnly) {}

TEST_F(CookieManagerTest, GetCookieListSameSite) {}

TEST_F(CookieManagerTest, GetCookieListCookiePartitionKeyCollection) {}

TEST_F(CookieManagerTest, GetCookieListAccessTime) {}

TEST_F(CookieManagerTest, DeleteCanonicalCookie) {}

TEST_F(CookieManagerTest, DeleteThroughSet) {}

TEST_F(CookieManagerTest, ConfirmSecureSetFails) {}

// Test CookieAccessDelegateImpl functionality for allowing Secure cookie access
// from potentially trustworthy origins, even if non-cryptographic.
TEST_F(CookieManagerTest, SecureCookieNonCryptographicPotentiallyTrustworthy) {}

TEST_F(CookieManagerTest, ConfirmHttpOnlySetFails) {}

TEST_F(CookieManagerTest, ConfirmSecureOverwriteFails) {}

TEST_F(CookieManagerTest, ConfirmHttpOnlyOverwriteFails) {}

TEST_F(CookieManagerTest, DeleteEverything) {}

TEST_F(CookieManagerTest, DeleteByTime) {}

TEST_F(CookieManagerTest, DeleteByExcludingDomains) {}

TEST_F(CookieManagerTest, DeleteByIncludingDomains) {}

TEST_F(CookieManagerTest, DeleteByEmptyIncludingDomains) {}

TEST_F(CookieManagerTest, DeleteByEmptyExcludingDomains) {}

// Confirm deletion is based on eTLD+1
TEST_F(CookieManagerTest, DeleteDetails_eTLD) {}

// Confirm deletion ignores host/domain distinction.
TEST_F(CookieManagerTest, DeleteDetails_HostDomain) {}

TEST_F(CookieManagerTest, DeleteDetails_eTLDvsPrivateRegistry) {}

TEST_F(CookieManagerTest, DeleteDetails_PrivateRegistry) {}

// Test to probe and make sure the attributes that deletion should ignore
// don't affect the results.
TEST_F(CookieManagerTest, DeleteDetails_IgnoredFields) {}

// A set of tests specified by the only consumer of this interface
// (BrowsingDataFilterBuilderImpl).
TEST_F(CookieManagerTest, DeleteDetails_Consumer) {}

TEST_F(CookieManagerTest, DeleteByName) {}

TEST_F(CookieManagerTest, DeleteByURL) {}

TEST_F(CookieManagerTest, DeleteBySessionStatus) {}

TEST_F(CookieManagerTest, DeleteByAll) {}

// Receives and records notifications from the mojom::CookieManager.
class CookieChangeListener : public mojom::CookieChangeListener {};

TEST_F(CookieManagerTest, AddCookieChangeListener) {}

TEST_F(CookieManagerTest, AddGlobalChangeListener) {}

// Confirm the service operates properly if a returned notification interface
// is destroyed.
TEST_F(CookieManagerTest, ListenerDestroyed) {}

// Confirm we get a connection error notification if the service dies.
TEST_F(CookieManagerTest, ServiceDestructVisible) {}

// Test service cloning.  Also confirm that the service notices if a client
// dies.
TEST_F(CookieManagerTest, CloningAndClientDestructVisible) {}

TEST_F(CookieManagerTest, BlockThirdPartyCookies) {}

// A test class having cookie store with a persistent backing store.
class FlushableCookieManagerTest : public CookieManagerTest {};

// Tests that the cookie's backing store (if available) gets flush to disk.
TEST_F(FlushableCookieManagerTest, FlushCookieStore) {}

TEST_F(FlushableCookieManagerTest, DeletionFilterToInfo) {}

// A test class having cookie store with a persistent backing store. The cookie
// store can be destroyed and recreated by calling InitializeCookieService
// again.
class SessionCleanupCookieManagerTest : public CookieManagerTest {};

TEST_F(SessionCleanupCookieManagerTest, PersistSessionCookies) {}

TEST_F(SessionCleanupCookieManagerTest, DeleteSessionCookiesOnShutdown) {}

TEST_F(SessionCleanupCookieManagerTest, SettingMustMatchDomainOnShutdown) {}

TEST_F(SessionCleanupCookieManagerTest, DeleteSessionOnlyCookies) {}

TEST_F(SessionCleanupCookieManagerTest, SettingMustMatchDomain) {}

TEST_F(SessionCleanupCookieManagerTest, DeleteStaleSessionOnlyCookies) {}

TEST_F(SessionCleanupCookieManagerTest, MorePreciseSettingTakesPrecedence) {}

TEST_F(SessionCleanupCookieManagerTest, ForceKeepSessionState) {}

TEST_F(SessionCleanupCookieManagerTest, HttpCookieAllowedOnHttps) {}

// Each call to SetStorageAccessGrantSettings should run the provided callback
// when complete.
TEST_F(CookieManagerTest, SetStorageAccessGrantSettingsRunsCallback) {}

}  // namespace
}  // namespace network