
This simplifies some matcher usage (by mandating a single argument type), and enforces stronger consistency guarantees (since the EnumSet automatically checks its own validity). Change-Id: Ib49862af24c16fa60cf5e2a7c0ac727d8b7336da Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6187264 Reviewed-by: Maks Orlovich <morlovich@chromium.org> Commit-Queue: Maks Orlovich <morlovich@chromium.org> Reviewed-by: Steven Bingler <bingler@chromium.org> Auto-Submit: Chris Fredrickson <cfredric@chromium.org> Cr-Commit-Position: refs/heads/main@{#1409694}
126 lines
5.1 KiB
C++
126 lines
5.1 KiB
C++
// Copyright 2021 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "net/base/network_delegate.h"
|
|
|
|
#include "net/cookies/canonical_cookie.h"
|
|
#include "net/cookies/canonical_cookie_test_helpers.h"
|
|
#include "net/cookies/cookie_inclusion_status.h"
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace net {
|
|
|
|
using testing::_;
|
|
using testing::ElementsAre;
|
|
using testing::IsEmpty;
|
|
using testing::UnorderedElementsAre;
|
|
|
|
namespace {
|
|
|
|
constexpr char kURL[] = "example.test";
|
|
|
|
CanonicalCookie MakeCookie(const std::string& name) {
|
|
return *CanonicalCookie::CreateUnsafeCookieForTesting(
|
|
name, "value", kURL, /*path=*/"/", /*creation=*/base::Time(),
|
|
/*expiration=*/base::Time(), /*last_access=*/base::Time(),
|
|
/*last_update=*/base::Time(),
|
|
/*secure=*/true, /*httponly=*/false, CookieSameSite::UNSPECIFIED,
|
|
CookiePriority::COOKIE_PRIORITY_DEFAULT);
|
|
}
|
|
|
|
CookieAccessResult Include() {
|
|
return {};
|
|
}
|
|
|
|
CookieAccessResult Exclude(CookieInclusionStatus::ExclusionReason reason) {
|
|
return CookieAccessResult(CookieInclusionStatus::MakeFromReasonsForTesting(
|
|
/*exclusions=*/{reason}));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(NetworkDelegateTest, ExcludeAllCookies) {
|
|
CookieAccessResultList maybe_included_cookies = {
|
|
{MakeCookie("1"), Include()}, {MakeCookie("2"), Include()}};
|
|
|
|
CookieAccessResultList excluded_cookies = {
|
|
{MakeCookie("3"),
|
|
Exclude(CookieInclusionStatus::ExclusionReason::EXCLUDE_SECURE_ONLY)}};
|
|
|
|
NetworkDelegate::ExcludeAllCookies(
|
|
CookieInclusionStatus::ExclusionReason::EXCLUDE_USER_PREFERENCES,
|
|
maybe_included_cookies, excluded_cookies);
|
|
|
|
EXPECT_THAT(maybe_included_cookies, IsEmpty());
|
|
EXPECT_THAT(
|
|
excluded_cookies,
|
|
UnorderedElementsAre(MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("1"),
|
|
MatchesCookieAccessResult(
|
|
HasExactlyExclusionReasonsForTesting(
|
|
{CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_USER_PREFERENCES}),
|
|
_, _, _)),
|
|
MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("2"),
|
|
MatchesCookieAccessResult(
|
|
HasExactlyExclusionReasonsForTesting(
|
|
{CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_USER_PREFERENCES}),
|
|
_, _, _)),
|
|
MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("3"),
|
|
MatchesCookieAccessResult(
|
|
HasExactlyExclusionReasonsForTesting(
|
|
{CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_SECURE_ONLY,
|
|
CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_USER_PREFERENCES}),
|
|
_, _, _))));
|
|
}
|
|
|
|
TEST(NetworkDelegateTest, MoveExcludedCookies) {
|
|
CookieAccessResultList maybe_included_cookies = {
|
|
{MakeCookie("1"), Include()},
|
|
{MakeCookie("2"),
|
|
Exclude(CookieInclusionStatus::ExclusionReason::EXCLUDE_SECURE_ONLY)},
|
|
{MakeCookie("3"), Include()}};
|
|
|
|
CookieAccessResultList excluded_cookies = {{
|
|
MakeCookie("4"),
|
|
Exclude(CookieInclusionStatus::ExclusionReason::EXCLUDE_SECURE_ONLY),
|
|
}};
|
|
|
|
NetworkDelegate::MoveExcludedCookies(maybe_included_cookies,
|
|
excluded_cookies);
|
|
|
|
EXPECT_THAT(
|
|
maybe_included_cookies,
|
|
ElementsAre(MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("1"),
|
|
MatchesCookieAccessResult(IsInclude(), _, _, _)),
|
|
MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("3"),
|
|
MatchesCookieAccessResult(IsInclude(), _, _, _))));
|
|
EXPECT_THAT(
|
|
excluded_cookies,
|
|
UnorderedElementsAre(MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("2"),
|
|
MatchesCookieAccessResult(
|
|
HasExactlyExclusionReasonsForTesting(
|
|
{CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_SECURE_ONLY}),
|
|
_, _, _)),
|
|
MatchesCookieWithAccessResult(
|
|
MatchesCookieWithName("4"),
|
|
MatchesCookieAccessResult(
|
|
HasExactlyExclusionReasonsForTesting(
|
|
{CookieInclusionStatus::ExclusionReason::
|
|
EXCLUDE_SECURE_ONLY}),
|
|
_, _, _))));
|
|
}
|
|
|
|
} // namespace net
|