#include "content/browser/renderer_host/navigation_request.h"
#include <memory>
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "content/browser/process_lock.h"
#include "content/browser/renderer_host/debug_urls.h"
#include "content/browser/renderer_host/navigation_controller_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/runtime_feature_state/runtime_feature_state_document_data.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_content_browser_client.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/mock_web_contents_observer.h"
#include "content/public/test/navigation_handle_observer.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_service.mojom.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "content/test/mock_commit_deferring_condition.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "services/network/public/cpp/features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/runtime_feature_state/runtime_feature_state_context.h"
#include "third_party/blink/public/common/runtime_feature_state/runtime_feature_state_read_context.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
#include "third_party/blink/public/mojom/runtime_feature_state/runtime_feature.mojom.h"
#include "ui/base/page_transition_types.h"
#include "url/scheme_host_port.h"
#include "url/url_constants.h"
namespace {
const char kBodyTextContent[] = …;
}
namespace content {
namespace {
class TestNavigationThrottle : public NavigationThrottle { … };
class TestNavigationThrottleInstaller : public WebContentsObserver { … };
class TestDeferringNavigationThrottleInstaller
: public TestNavigationThrottleInstaller { … };
class NavigationStartUrlRecorder : public WebContentsObserver { … };
void ExpectChildFrameSetAsCollapsedInFTN(Shell* shell, bool expect_collapsed) { … }
void ExpectChildFrameCollapsedInLayout(Shell* shell,
const std::string& frame_id,
bool expect_collapsed) { … }
void ExpectChildFrameCollapsed(Shell* shell,
const std::string& frame_id,
bool expect_collapsed) { … }
}
class NavigationRequestBrowserTest : public ContentBrowserTest { … };
class NavigationRequestBrowserTest_IsolateAllSites
: public NavigationRequestBrowserTest { … };
class NavigationRequestDownloadBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifyPageTransition) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifyFrameTree) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifyRedirect) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RuntimeFeatureStatePersisted) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RuntimeFeatureStatePersistedForSameValue) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RuntimeFeatureStateClearOnRedirect) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifyCertErrorFailure) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifyRendererInitiated) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifySrcdoc) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, VerifySameDocument) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleCancelStart) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleCancelRedirect) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleCancelFailure) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleCancelResponse) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ThrottleCancelCommitWithoutUrlLoader) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleDefer) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleDeferFailure) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ThrottleDeferCommitWithoutUrlLoader) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ThrottleDeferAndCancelCommitWithoutUrlLoader) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ThrottleBlockAndCollapse) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ThrottleBlockAndCollapse_LegacyFrameNotCollapsed) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
VerifyRequestContextTypeForFrameTree) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
VerifyHyperlinkRequestContextType) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
VerifyFormRequestContextType) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ErrorCodeOnThrottleCancelNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
CancelNavigationInWillStartRequest) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
NoLeakFromStartingSiteInstance) { … }
class NavigationRequestHttpsUpgradeBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestHttpsUpgradeBrowserTest,
StartUrlIsHttpsUpgradedSameSite) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestHttpsUpgradeBrowserTest,
StartUrlIsHttpsUpgradedCrossSite) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
BrowserInitiatedMainFrameReload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
BrowserInitiatedSubFrameReload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RendererInitiatedMainFrameReload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RendererInitiatedSubFrameReload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
SameDocumentBrowserInitiatedNoReload) { … }
class NavigationRequestHostResolutionFailureTest : public ContentBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestHostResolutionFailureTest,
HostResolutionFailure) { … }
class NavigationLogger : public WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, BlockedOnRedirect) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ErrorCodeOnCancel) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ErrorCodeOnRedirect) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ErrorPageBlockedNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, ErrorPageNetworkError) { … }
class ReadyToCommitObserver : public WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
SynchronouslyCompleteCommitDeferringCondition) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
AsyncCommitDeferringCondition) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
CancelWhileCommitDeferred) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RegisterThrottleForTestingIsLast) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, BlockedRequestAfterWebUI) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RedirectToRendererDebugUrl) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
DISABLED_BlockCredentialedSubresources) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest_IsolateAllSites,
StartToCommitMetrics) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
TimeToReadyToCommitMetrics) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest, IsDownload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
DownloadFalseForHtmlResponse) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
DownloadFalseFor404) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
DownloadFalseForFailedNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
RedirectToDownload) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
RedirectToDownloadFails) { … }
class NavigationRequestThrottleResultWithErrorPageBrowserTest
: public NavigationRequestBrowserTest,
public ::testing::WithParamInterface<NavigationThrottle::ThrottleAction> { … };
IN_PROC_BROWSER_TEST_P(NavigationRequestThrottleResultWithErrorPageBrowserTest,
WillStartRequest) { … }
IN_PROC_BROWSER_TEST_P(NavigationRequestThrottleResultWithErrorPageBrowserTest,
WillRedirectRequest) { … }
IN_PROC_BROWSER_TEST_P(NavigationRequestThrottleResultWithErrorPageBrowserTest,
WillFailRequest) { … }
IN_PROC_BROWSER_TEST_P(NavigationRequestThrottleResultWithErrorPageBrowserTest,
WillProcessResponse) { … }
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
AllowedResourceDownloaded) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest,
AllowedResourceNotDownloaded) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestDownloadBrowserTest, Disallowed) { … }
class NavigationRequestBackForwardBrowserTest
: public NavigationRequestBrowserTest,
public WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBackForwardBrowserTest,
NavigationEntryOffsets) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBackForwardBrowserTest,
NavigationEntryOffsetsForSubframes) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBackForwardBrowserTest,
NavigationEntryLimit) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBackForwardBrowserTest,
LocationReplace) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, AuthChallengeInfo) { … }
class TestMixedContentWebContentsDelegate : public WebContentsDelegate { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
NonWebbyIframeIsNotMixedContent) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
GetRFHDuringSyncRendererCommitSameDocumentNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
GetRFHDuringInitialAboutBlankNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
SiteIsSetAtResponseTimeWithoutSiteIsolation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
OriginForSrcdocErrorPageInSubframe) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
ErrorPageMarksProcessAsUsed) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
NavigateToAboutBlankFromErrorPage) { … }
CSPEmbeddedEnforcementBrowserTest;
IN_PROC_BROWSER_TEST_F(CSPEmbeddedEnforcementBrowserTest,
CheckCSPEmbeddedEnforcement) { … }
class NavigationRequestFencedFrameBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
NavigationRequestFencedFrameBrowserTest,
ShouldRespectOutermostFrameCOEPParentAndChildOnInsecureContent) { … }
IN_PROC_BROWSER_TEST_F(
NavigationRequestFencedFrameBrowserTest,
RespectOutermostFrameCOEPParentOnInsecureContentAndChildOnSecureContent) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestFencedFrameBrowserTest,
ViewSourceNavigation_FencedFrame) { … }
class NavigationRequestPrerenderBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
CoopWithMainframeAboutSrcdocNavigation) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
CoopWithMainframeAboutSrcdocNavigation2) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestPrerenderBrowserTest,
CoopCoepCheckWithPrerender) { … }
enum class TestMPArchType { … };
class NavigationRequestMPArchBrowserTest
: public NavigationRequestBrowserTest,
public testing::WithParamInterface<TestMPArchType> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(NavigationRequestMPArchBrowserTest,
ShouldNotUpdateHistory) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
RendererCrashedBeforeCommitErrorPage) { … }
namespace {
constexpr char kResponseBody[] = …;
const char kResponseTemplate[] = …;
class ResponseBodyNavigationThrottle : public NavigationThrottle { … };
}
class NavigationRequestResponseBodyBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest, Received) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest,
ContentLengthZero) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest,
BodyLargerThanDataPipeSize) { … }
class NavigationRequestNoSiteIsolationBrowserTest
: public NavigationRequestBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NavigationRequestNoSiteIsolationBrowserTest,
EarlySwapMetrics_InitialFrame) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestNoSiteIsolationBrowserTest,
UserActivationSameSite) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestNoSiteIsolationBrowserTest,
UserActivationJavascriptUrlMainFrame) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestNoSiteIsolationBrowserTest,
UserActivationJavascriptUrlChildFrame) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
EarlySwapMetrics_CrashNoCommit) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
EarlySwapMetrics_CrashedSubframe) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
EarlySwapMetrics_NoSwapForWebUI) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
InitiatorSandboxFlags_BrowserInitiated) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
InitiatorSandboxFlags_DocumentInitiated) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
InitiatorSandboxFlags_SandboxedIframe) { … }
IN_PROC_BROWSER_TEST_F(
NavigationRequestBrowserTest,
ThrottleDeferAndCancelCommitWithoutUrlLoaderWithErrorPage) { … }
IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest,
TentativeOriginToCommitIsStable_Data) { … }
}