#include <string_view>
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/policy/policy_constants.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/test/test_data_directory.h"
#include "pdf/buildflags.h"
#include "services/network/public/cpp/content_security_policy/content_security_policy.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/cross_origin_opener_policy.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/frame/frame.mojom.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#if BUILDFLAG(ENABLE_PDF)
#include "base/test/with_feature_override.h"
#include "pdf/pdf_features.h"
#endif
namespace {
const int kWasmPageSize = …;
constexpr char kPnaPath[] = …;
class ChromeWebPlatformSecurityMetricsBrowserTest : public policy::PolicyTest { … };
class PrivateNetworkAccessWebSocketMetricBrowserTest
: public ChromeWebPlatformSecurityMetricsBrowserTest { … };
content::RenderFrameHost* GetChild(content::RenderFrameHost& parent) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingNoHeader) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessFetchWithPreflight) { … }
IN_PROC_BROWSER_TEST_F(
ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessFetchWithPreflightRepliedWithoutPNAHeaders) { … }
IN_PROC_BROWSER_TEST_F(
ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessPolicyEnabledFetchWithPreflightRepliedWithoutPNAHeaders) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessPolicyEnabledFetchWithPreflight) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessFetchInWorker) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_PrivateNetworkAccessWebSocketConnectedPublicToLocal …
#else
#define MAYBE_PrivateNetworkAccessWebSocketConnectedPublicToLocal …
#endif
IN_PROC_BROWSER_TEST_F(
PrivateNetworkAccessWebSocketMetricBrowserTest,
MAYBE_PrivateNetworkAccessWebSocketConnectedPublicToLocal) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_PrivateNetworkAccessWebSocketConnectedLocalToLocal …
#else
#define MAYBE_PrivateNetworkAccessWebSocketConnectedLocalToLocal …
#endif
IN_PROC_BROWSER_TEST_F(PrivateNetworkAccessWebSocketMetricBrowserTest,
MAYBE_PrivateNetworkAccessWebSocketConnectedLocalToLocal) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
PrivateNetworkAccessFetchInSharedWorker) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingReportOnlyHTTP) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingReportOnlyHTTPS) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingCOOPHTTPS) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingCOOPAndReportOnly) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingNoEndpoint) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingMainFrameAndSubframe) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginOpenerPolicyReportingUsageSubframeOnly) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginSubframeWithoutEmbeddingControlSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginSubframeWithoutEmbeddingControlNoHeaders) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
LogCSPFrameSrcWildcardMatchFeature) { … }
IN_PROC_BROWSER_TEST_F(
ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginSubframeWithoutEmbeddingControlFrameAncestors) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginSubframeWithoutEmbeddingControlNoEmbedding) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginSubframeWithoutEmbeddingControlOtherCSP) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
EmbeddingOptIn) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
NonCrossOriginIsolatedCheckSabConstructor) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
NonCrossOriginIsolatedSabSizeZero) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
NonCrossOriginIsolatedSab) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginIsolatedSab) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingCrossSite) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingCrossOriginBeforeSetDocumentDomain) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingCrossOriginAfterSetDocumentDomain) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmMemorySharingCrossOriginIsolated) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmModuleSharingCrossSite) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmModuleSharingSameSite) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmModuleSharingSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmModuleSharingSameSiteBeforeSetDocumentDomain) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WasmModuleSharingSameSiteAfterSetDocumentDomain) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginDocumentsWithSameCOOPStatus) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginDocumentsWithDifferentCOOPStatus) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginDocumentsWithDifferentCOOPStatusBCGSwitch) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossOriginDocumentsWithNoCOOPStatus) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
COOPSameOriginAllowPopupsIframeAndPopup) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginIframeInCrossOriginPopupWithCOOP) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
IFramesWithDifferentCOOPStatus) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginDifferentCOOPStatusRecordedOnce) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
SameOriginDifferentCOOPStatusTwoCOOPPages) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepNoneMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepCredentiallessMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepRequireCorpMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepReportOnlyCredentiallessMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepReportOnlyRequireCorpMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoopAndCoepIsolatedMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoopAndCoepIsolatedEnforcedReportOnlyMainFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoopAndCoepIsolatedMainFrameReportOnly) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoopAndCoepIsolatedIframe) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepRequireCorpEmbedsCredentialless) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepCredentiallessEmbedsRequireCorp) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepNoneSharedWorker) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepCredentiallessSharedWorker) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CoepRequireCorpSharedWorker) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccess) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessCloseSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessCloseCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessIndexedGetter) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessLocationSetSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessLocationSetCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessNamedGetter) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessOpenerSet) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPage) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPartitionedPopin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageCloseSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageCloseCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageIndexedGetter) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageLocationSetSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageLocationSetCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageNamedGetter) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageOpenerSet) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
WindowProxyAccessFromOtherPageWindow) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeInitialEmptyDocumentControl) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeInitialEmptyDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeNavigationControl) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeNavigation) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeIsSandboxedControl) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
AnonymousIframeIsSandboxed) { … }
SameDocumentCrossOriginInitiatorTest;
IN_PROC_BROWSER_TEST_F(SameDocumentCrossOriginInitiatorTest, SameOrigin) { … }
IN_PROC_BROWSER_TEST_F(SameDocumentCrossOriginInitiatorTest, SameSite) { … }
IN_PROC_BROWSER_TEST_F(SameDocumentCrossOriginInitiatorTest, CrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(SameDocumentCrossOriginInitiatorTest,
SameOriginInitiated) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
JavascriptUrlNavigationInIFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
EmptyStringJavascriptUrlNavigationInIFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
JavascriptUrlNavigationInTopFrame) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
DanglingMarkupInIframeName) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
DanglingMarkupInNameWithGreaterThan) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
DanglingMarkupInNameWithNewLineOrGreaterThan) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
DanglingMarkupInTarget) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_DanglingMarkupInTargetWithNewLineOrGreaterThan …
#else
#define MAYBE_DanglingMarkupInTargetWithNewLineOrGreaterThan …
#endif
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
MAYBE_DanglingMarkupInTargetWithNewLineOrGreaterThan) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
DocumentOpenAliasedOriginDocumentDomain) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToHTMLDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToXHTMLDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToSVGDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToImageDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToMediaDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToTextDocument) { … }
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CrossWindowAccessToXMLDocument) { … }
#if BUILDFLAG(ENABLE_PDF)
class ChromeWebPlatformSecurityMetricsBrowserPdfTest
: public base::test::WithFeatureOverride,
public ChromeWebPlatformSecurityMetricsBrowserTest { … };
IN_PROC_BROWSER_TEST_P(ChromeWebPlatformSecurityMetricsBrowserPdfTest,
CrossWindowAccessToPluginDocument) { … }
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(…);
#endif
IN_PROC_BROWSER_TEST_F(ChromeWebPlatformSecurityMetricsBrowserTest,
CSPEESameOriginWithSameCSPHeader) { … }
}