#include "content/browser/renderer_host/render_frame_host_impl.h"
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/buildflag.h"
#include "components/input/timeout_monitor.h"
#include "content/browser/renderer_host/navigation_controller_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/common/features.h"
#include "content/public/browser/cors_origin_pattern_setter.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/content_features.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/fake_local_frame.h"
#include "content/public/test/test_utils.h"
#include "content/test/navigation_simulator_impl.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "net/base/features.h"
#include "net/base/isolation_info.h"
#include "net/cookies/site_for_cookies.h"
#include "services/network/public/cpp/cors/origin_access_list.h"
#include "services/network/public/mojom/cors.mojom.h"
#include "services/network/public/mojom/cors_origin_pattern.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.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/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_util.h"
#if !BUILDFLAG(IS_ANDROID)
#include "content/browser/webauth/authenticator_environment.h"
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom.h"
#endif
namespace content {
namespace {
void AddHostPermissions(const std::string& host, RenderFrameHost* rfh) { … }
}
class RenderFrameHostImplTest : public RenderViewHostImplTestHarness { … };
class FirstPartyOverrideContentBrowserClient : public ContentBrowserClient { … };
class RenderFrameHostImplTest_NoOriginKeyedProcessesByDefault
: public RenderFrameHostImplTest { … };
TEST_F(RenderFrameHostImplTest_NoOriginKeyedProcessesByDefault,
ExpectedMainWorldOrigin) { … }
TEST_F(RenderFrameHostImplTest, InvalidURL) { … }
TEST_F(RenderFrameHostImplTest, CrossSiteAncestorInFrameTree) { … }
TEST_F(RenderFrameHostImplTest_NoOriginKeyedProcessesByDefault,
IsolationInfoDuringCommit) { … }
TEST_F(RenderFrameHostImplTest, PolicyContainerLifecycle) { … }
TEST_F(RenderFrameHostImplTest, FaviconURLsSet) { … }
TEST_F(RenderFrameHostImplTest, FaviconURLsResetWithNavigation) { … }
TEST_F(RenderFrameHostImplTest, ChildOfCredentiallessIsCredentialless) { … }
class FakeLocalFrameWithBeforeUnload : public content::FakeLocalFrame { … };
TEST_F(RenderFrameHostImplTest, BeforeUnloadNotSentToRenderer) { … }
class LoadingStateChangedDelegate : public WebContentsDelegate { … };
TEST_F(RenderFrameHostImplTest, NavigationApiInterceptShowLoadingUi) { … }
TEST_F(RenderFrameHostImplTest, NavigationApiInterceptBrowserInitiated) { … }
TEST_F(RenderFrameHostImplTest, CalculateStorageKey) { … }
#if BUILDFLAG(IS_LINUX)
#define MAYBE_CalculateStorageKeyFirstPartyOverride …
#else
#define MAYBE_CalculateStorageKeyFirstPartyOverride …
#endif
TEST_F(RenderFrameHostImplTest, MAYBE_CalculateStorageKeyFirstPartyOverride) { … }
TEST_F(RenderFrameHostImplTest,
CalculateStorageKeyWhenPassedOriginIsNotCurrentFrame) { … }
TEST_F(RenderFrameHostImplTest,
CalculateStorageKeyTakeNewDocumentPropertiesFromNavigation) { … }
TEST_F(RenderFrameHostImplTest,
CalculateStorageKeyStoragePartitioningCorrectFrameWithExtension) { … }
TEST_F(RenderFrameHostImplTest, CalculateStorageKeyOfUnnavigatedFrame) { … }
TEST_F(RenderFrameHostImplTest,
NewFrameInheritsRuntimeFeatureStateReadContext) { … }
#if BUILDFLAG(IS_ANDROID)
class TestWebAuthnContentBrowserClientImpl : public ContentBrowserClient {
public:
MOCK_METHOD(bool,
IsSecurityLevelAcceptableForWebAuthn,
(RenderFrameHost*, const url::Origin& origin),
());
};
class RenderFrameHostImplWebAuthnTest : public RenderFrameHostImplTest {
public:
void SetUp() override {
RenderFrameHostImplTest::SetUp();
old_browser_client_ = SetBrowserClientForTesting(browser_client_.get());
contents()->GetController().LoadURLWithParams(
NavigationController::LoadURLParams(
GURL("https://example.com/navigation.html")));
}
void TearDown() override {
RenderFrameHostImplTest::TearDown();
SetBrowserClientForTesting(old_browser_client_);
}
protected:
raw_ptr<ContentBrowserClient> old_browser_client_;
std::unique_ptr<TestWebAuthnContentBrowserClientImpl> browser_client_ =
std::make_unique<TestWebAuthnContentBrowserClientImpl>();
};
TEST_F(RenderFrameHostImplWebAuthnTest,
PerformGetAssertionWebAuthSecurityChecks_TLSError) {
GURL url("https://doofenshmirtz.evil");
const auto origin = url::Origin::Create(url);
EXPECT_CALL(*browser_client_,
IsSecurityLevelAcceptableForWebAuthn(main_test_rfh(), origin))
.WillOnce(testing::Return(false));
std::optional<blink::mojom::AuthenticatorStatus> status;
main_test_rfh()->PerformGetAssertionWebAuthSecurityChecks(
"doofenshmirtz.evil", url::Origin::Create(url),
false,
base::BindLambdaForTesting(
[&status](blink::mojom::AuthenticatorStatus s, bool is_cross_origin) {
status = s;
}));
EXPECT_EQ(status.value(),
blink::mojom::AuthenticatorStatus::CERTIFICATE_ERROR);
}
TEST_F(RenderFrameHostImplWebAuthnTest,
PerformMakeCredentialWebAuthSecurityChecks_TLSError) {
GURL url("https://doofenshmirtz.evil");
const auto origin = url::Origin::Create(url);
EXPECT_CALL(*browser_client_,
IsSecurityLevelAcceptableForWebAuthn(main_test_rfh(), origin))
.WillOnce(testing::Return(false));
std::optional<blink::mojom::AuthenticatorStatus> status;
main_test_rfh()->PerformMakeCredentialWebAuthSecurityChecks(
"doofenshmirtz.evil", url::Origin::Create(url),
false,
base::BindLambdaForTesting(
[&status](blink::mojom::AuthenticatorStatus s, bool is_cross_origin) {
status = s;
}));
EXPECT_EQ(status.value(),
blink::mojom::AuthenticatorStatus::CERTIFICATE_ERROR);
}
TEST_F(RenderFrameHostImplWebAuthnTest,
PerformGetAssertionWebAuthSecurityChecks_Success) {
GURL url("https://owca.org");
const auto origin = url::Origin::Create(url);
EXPECT_CALL(*browser_client_,
IsSecurityLevelAcceptableForWebAuthn(main_test_rfh(), origin))
.WillOnce(testing::Return(true));
std::optional<blink::mojom::AuthenticatorStatus> status;
main_test_rfh()->PerformGetAssertionWebAuthSecurityChecks(
"owca.org", url::Origin::Create(url),
false,
base::BindLambdaForTesting(
[&status](blink::mojom::AuthenticatorStatus s, bool is_cross_origin) {
status = s;
}));
EXPECT_EQ(status.value(), blink::mojom::AuthenticatorStatus::SUCCESS);
}
TEST_F(RenderFrameHostImplWebAuthnTest,
PerformMakeCredentialWebAuthSecurityChecks_Success) {
GURL url("https://owca.org");
const auto origin = url::Origin::Create(url);
EXPECT_CALL(*browser_client_,
IsSecurityLevelAcceptableForWebAuthn(main_test_rfh(), origin))
.WillOnce(testing::Return(true));
std::optional<blink::mojom::AuthenticatorStatus> status;
main_test_rfh()->PerformMakeCredentialWebAuthSecurityChecks(
"owca.org", url::Origin::Create(url),
false,
base::BindLambdaForTesting(
[&status](blink::mojom::AuthenticatorStatus s, bool is_cross_origin) {
status = s;
}));
EXPECT_EQ(status.value(), blink::mojom::AuthenticatorStatus::SUCCESS);
}
#endif
class RenderFrameHostImplThirdPartyStorageTest
: public RenderViewHostImplTestHarness,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(RenderFrameHostImplThirdPartyStorageTest,
ChildFramePartitionedByThirdPartyStorageKey) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(RenderFrameHostImplTest, GetVirtualAuthenticatorManagerWhenInactiveRFH) { … }
#endif
namespace {
class MockWebContentsDelegate : public WebContentsDelegate { … };
}
TEST_F(RenderFrameHostImplTest,
RendererInitiatedCloseIsCancelledIfPageIsntPrimary) { … }
TEST_F(RenderFrameHostImplTest,
BrowserInitiatedCloseIsNotCancelledIfPageIsntPrimary) { … }
class TextCopiedEventObserver : public WebContentsObserver { … };
TEST_F(RenderFrameHostImplTest, OnTextCopiedToClipboard) { … }
TEST_F(RenderFrameHostImplTest, LoadedWithCacheControlNoStoreHeader) { … }
class MediaStreamCaptureObserver : public WebContentsObserver { … };
TEST_F(RenderFrameHostImplTest, CapturedMediaStreamAddedRemoved) { … }
}