#include <memory>
#include <string_view>
#include "base/containers/adapters.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/net/storage_test_utils.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/storage_access_api/storage_access_grant_permission_context.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/webid/federated_identity_permission_context.h"
#include "chrome/browser/webid/federated_identity_permission_context_factory.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_manager.h"
#include "components/permissions/request_type.h"
#include "components/permissions/test/mock_permission_prompt_factory.h"
#include "components/permissions/test/permission_request_observer.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/base/features.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
#include "net/cookies/cookie_partition_key_collection.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_request_headers.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/test/test_data_directory.h"
#include "services/network/public/cpp/network_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-forward.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#include "ui/base/window_open_disposition.h"
#include "url/origin.h"
BrowserThread;
Contains;
Gt;
IsEmpty;
Pair;
UnorderedElementsAre;
namespace {
constexpr char kHostA[] = …;
constexpr char kOriginA[] = …;
constexpr char kOriginB[] = …;
constexpr char kUrlA[] = …;
constexpr char kHostASubdomain[] = …;
constexpr char kHostB[] = …;
constexpr char kHostBSubdomain[] = …;
constexpr char kHostBSubdomain2[] = …;
constexpr char kHostC[] = …;
constexpr char kHostD[] = …;
constexpr char kUseCounterHistogram[] = …;
constexpr char kRequestOutcomeHistogram[] = …;
constexpr char kGrantIsImplicitHistogram[] = …;
const char* kEchoCookiesWithCorsPath = …;
constexpr char kRetryPath[] = …;
constexpr char kQueryStorageAccessPermission[] = …;
constexpr char kHeaderNotProvidedSentinel[] = …;
enum class TestType { … };
std::pair<std::string, std::string> CookieBundle(const std::string& cookies) { … }
std::tuple<std::string, std::string, std::string> CookieBundleWithContent(
const std::string& cookies) { … }
constexpr std::pair<const char*, const char*> kNoCookies = …;
constexpr std::tuple<const char*, const char*, const char*>
kNoCookiesWithContent = …;
MATCHER_P(HeadersAre, inner_matcher, "") { … }
void SetCORSHeaders(const net::test_server::HttpRequest& request,
net::test_server::BasicHttpResponse& response) { … }
std::unique_ptr<net::test_server::HttpResponse>
HandleEchoCookiesWithCorsRequest(const net::test_server::HttpRequest& request) { … }
std::unique_ptr<net::test_server::HttpResponse> HandleRetryRequest(
int& fetch_count,
const net::test_server::HttpRequest& request) { … }
std::string QueryPermission(content::RenderFrameHost* render_frame_host) { … }
bool ThirdPartyPartitionedStorageAllowedByDefault() { … }
std::string CookieAttributes(std::string_view domain) { … }
std::vector<base::test::FeatureRefAndParams> GetEnabledFeaturesForStorage(
bool is_storage_partitioned) { … }
std::vector<base::test::FeatureRef> GetDisabledFeaturesForStorage(
bool is_storage_partitioned) { … }
class StorageAccessAPIBaseBrowserTest : public policy::PolicyTest { … };
class StorageAccessAPIBrowserTest : public StorageAccessAPIBaseBrowserTest { … };
class StorageAccessAPIOriginIsolationBrowserTest
: public StorageAccessAPIBaseBrowserTest,
public ::testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, PermissionQueryDefault) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
PermissionQueryDefault_AllowCrossSiteCookie) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, PermissionQueryGranted) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, PermissionQueryDenied) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, PermissionQueryCrossSite) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
Permission_Denied_WithoutInteraction) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_CrossSiteIframe) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
AccessGranted_DoesNotConsumeUserInteraction) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
AccessGranted_NoSubsequentUserInteraction) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_CrossSiteIframe_UnrelatedSites) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_NestedCrossSiteIframe_InnerRequestsAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_CrossOriginFetch) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_NestedCrossSiteIframe_MiddleRequestsAccess) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameRequestsAccess_NestedCrossSiteIframe_DistinctSites) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ThirdPartyCookiesCrossSiteSiblingIFrameRequestsAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameThirdPartyExceptions) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameThirdPartyExceptions_NestedSameSite) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameThirdPartyExceptions_NestedCrossSite) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameThirdPartyExceptions_CrossSiteAncestorChain) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
ThirdPartyCookiesIFrameThirdPartyExceptions_SameSiteAncestorChain) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ThirdPartyGrantsDeletedAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
ExplicitUserSettingsBlockThirdPartyGrantsAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, OpaqueOriginRejects) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
MissingSandboxTokenRejects) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, SandboxTokenResolves) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, ThirdPartyGrantsExpiry) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
Navigation_SelfInitiated_SameOrigin_Preserves) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
Navigation_NonSelfInitiated_SameOriginDestination_CrossSiteInitiator) { … }
IN_PROC_BROWSER_TEST_P(
StorageAccessAPIOriginIsolationBrowserTest,
Navigation_NonSelfInitiated_SameOriginDestination_SameSiteInitiator) { … }
IN_PROC_BROWSER_TEST_P(
StorageAccessAPIOriginIsolationBrowserTest,
Navigation_NonSelfInitiated_SameOriginDestination_SameSiteInitiator_TargetHasStorageAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
Navigation_SelfInitiated_SameSiteCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
Navigation_SelfInitiated_CrossSite) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
Navigation_SelfInitiated_SameOrigin_CrossOriginRedirect) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIBrowserTest,
Navigation_SelfInitiated_SameOrigin_CrossSiteAndSameSiteRedirects) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
EmbeddedSameOriginCookieAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
EmbeddedSameSiteCookieAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
NestedSameOriginCookieAccess_CrossSiteAncestorChain) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
NestedSameSiteCookieAccess_CrossSiteAncestorChain) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
DedicatedWorker_InheritsStorageAccessFromDocument) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
WebsocketRequestsUseStorageAccessGrants) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
EmbeddedCrossSiteCookieAccess_Accept) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
EmbeddedCrossSiteCookieAccess_Deny) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
BeyondCookies_WithoutCookiesWithoutPermission) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
BeyondCookies_WithoutCookiesWithPermission) { … }
class StorageAccessAPIStorageBrowserTest
: public StorageAccessAPIBaseBrowserTest,
public testing::WithParamInterface<std::tuple<TestType, bool>> { … };
IN_PROC_BROWSER_TEST_P(StorageAccessAPIStorageBrowserTest,
ThirdPartyIFrameStorageRequestsAccess) { … }
IN_PROC_BROWSER_TEST_P(StorageAccessAPIStorageBrowserTest,
NestedThirdPartyIFrameStorage) { … }
IN_PROC_BROWSER_TEST_P(StorageAccessAPIStorageBrowserTest, MultiTabTest) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
class StorageAccessAPIWithFirstPartySetsBrowserTest
: public StorageAccessAPIBaseBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_AutograntedWithinFirstPartySet) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_PromptOrDenyUnderServiceDomain) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_AutograntedForServiceDomainWithExistingGrant) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_AutodeniedOutsideFirstPartySet_Overridden) { … }
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_AutodeniedInsideFirstPartySet_WithoutInteraction) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
PRE_PermissionGrantsRestoredAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
PermissionGrantsRestoredAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
Permission_GrantedForServiceDomain) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithFirstPartySetsBrowserTest,
SameSite_NoRegression) { … }
class StorageAccessAPIWithFirstPartySetsAndImplicitGrantsBrowserTest
: public StorageAccessAPIBaseBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIWithFirstPartySetsAndImplicitGrantsBrowserTest,
ImplicitGrants) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
RequestStorageAccess_CoexistsWithPartitionedCookies) { … }
class StorageAccessAPIEnterprisePolicyBrowserTest
: public StorageAccessAPIBaseBrowserTest,
public testing::WithParamInterface<
std::tuple<const char*, ContentSetting, bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(StorageAccessAPIEnterprisePolicyBrowserTest,
PartitionedStorage) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
EnsureOnePromptDenialSuffices) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
DismissalAllowsFuturePrompts) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
TopLevelUserInteractionRequired) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
IncognitoDoesntUseRegularInteractionsOrPermission) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest, IncognitoCanUseAPI) { … }
class StorageAccessAPIWithImplicitGrantsBrowserTest
: public StorageAccessAPIBaseBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWithImplicitGrantsBrowserTest,
ImplicitGrantsAllowAccess) { … }
class StorageAccessAPIWith3PCEnabledBrowserTest
: public StorageAccessAPIBaseBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
AllowedWhenUnblocked) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
AllowedByUserBypass) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
BeyondCookies_WithCookiesWithoutPermission) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
BeyondCookies_WithCookiesWithPermission) { … }
class StorageAccessAPIAutograntsWithFedCMBrowserTest
: public StorageAccessAPIBaseBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrants_RequiresPermissionPolicy) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrants_PreventSilentAccess) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrants_PreventSilentAccess_AfterAutogrant) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrants_PermissionPolicyHeaderIgnored) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrantsAllowCookieAccessViaSAA) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessAPIAutograntsWithFedCMBrowserTest,
FedCMGrantsAllowCookieAccess_NestedFrame) { … }
class StorageAccessAPIAutograntsWithFedCMOriginTrialBrowserTest
: public StorageAccessAPIAutograntsWithFedCMBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
StorageAccessAPIAutograntsWithFedCMOriginTrialBrowserTest,
FedCMGrantsAllowCookieAccessViaSAA) { … }
class StorageAccessHeadersDisabledBrowserTest
: public StorageAccessAPIBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersDisabledBrowserTest, RetryHeader) { … }
class StorageAccessHeadersBrowserTest : public StorageAccessAPIBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest, RetryHeader) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RetryHeader_NoopWithoutGrant) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RetryHeader_ABAContext) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RetryHeader_ABAContext_WithIrrelevantApiCall) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest, LoadHeader) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
LoadHeader_NoopWithoutGrant) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RequestHeadersFirstParty) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RequestHeadersCookiesBlocked) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest, RequestHeadersNone) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RequestHeadersInactive) { … }
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersBrowserTest,
RequestHeaderRetryToActive) { … }
class StorageAccessHeadersWithThirdPartyCookiesBrowserTest
: public StorageAccessHeadersBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersWithThirdPartyCookiesBrowserTest,
RetryHeader_NoopWhenCookiesAllowed) { … }
class StorageAccessHeadersWithFedCMBrowserTest
: public StorageAccessAPIAutograntsWithFedCMBrowserTest { … };
IN_PROC_BROWSER_TEST_F(StorageAccessHeadersWithFedCMBrowserTest, RetryHeader) { … }
}