#include "content/renderer/render_frame_impl.h"
#include <stdint.h>
#include <optional>
#include <tuple>
#include <utility>
#include "base/check_deref.h"
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/protected_memory_buildflags.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "content/common/features.h"
#include "content/common/renderer.mojom.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/extra_mojo_js_features.mojom.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/test/frame_load_waiter.h"
#include "content/public/test/local_frame_host_interceptor.h"
#include "content/public/test/policy_container_utils.h"
#include "content/public/test/render_view_test.h"
#include "content/public/test/test_utils.h"
#include "content/renderer/agent_scheduling_group.h"
#include "content/renderer/document_state.h"
#include "content/renderer/mojo/blink_interface_registry_impl.h"
#include "content/renderer/navigation_state.h"
#include "content/test/frame_host_test_interface.mojom.h"
#include "content/test/test_render_frame.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/navigation/navigation_params.h"
#include "third_party/blink/public/common/navigation/navigation_params_mojom_traits.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/browser_interface_broker.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom.h"
#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
#include "third_party/blink/public/mojom/frame/viewport_intersection_state.mojom.h"
#include "third_party/blink/public/mojom/widget/platform_widget.mojom.h"
#include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom.h"
#include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_v8_value_converter.h"
#include "third_party/blink/public/test/test_web_frame_content_dumper.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_history_item.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_v8_features.h"
#include "third_party/blink/public/web/web_view.h"
#include "ui/display/screen_info.h"
#include "ui/display/screen_infos.h"
#include "ui/gfx/geometry/point.h"
#include "ui/native_theme/native_theme_features.h"
WebURLRequest;
namespace content {
namespace {
constexpr int32_t kSubframeRouteId = …;
constexpr int32_t kSubframeWidgetRouteId = …;
const char kParentFrameHTML[] = …;
const char kSimpleScriptHtml[] = …;
const char kAutoplayTestOrigin[] = …;
}
class RenderFrameImplTest : public RenderViewTest { … };
class RenderFrameTestObserver : public RenderFrameObserver { … };
TEST_F(RenderFrameImplTest, SubframeWidget) { … }
TEST_F(RenderFrameImplTest, FrameResize) { … }
TEST_F(RenderFrameImplTest, FrameWasShown) { … }
namespace {
class DownloadURLMockLocalFrameHost : public LocalFrameHostInterceptor { … };
class DownloadURLTestRenderFrame : public TestRenderFrame { … };
}
class RenderViewImplDownloadURLTest : public RenderFrameImplTest { … };
TEST_F(RenderViewImplDownloadURLTest, DownloadUrlLimit) { … }
TEST_F(RenderFrameImplTest, NoCrashWhenDeletingFrameDuringFind) { … }
TEST_F(RenderFrameImplTest, NoCrashOnReceiveTitleWhenNavigatingToJavascript) { … }
TEST_F(RenderFrameImplTest, AutoplayFlags) { … }
TEST_F(RenderFrameImplTest, AutoplayFlags_WrongOrigin) { … }
TEST_F(RenderFrameImplTest, FileUrlPathAlias) { … }
TEST_F(RenderFrameImplTest, MainFrameIntersectionRecorded) { … }
TEST_F(RenderFrameImplTest, MainFrameViewportRectRecorded) { … }
struct SourceAnnotation { … };
std::ostream& operator<<(std::ostream& out, const SourceAnnotation& s) { … }
namespace {
constexpr char kTestFirstURL[] = …;
constexpr char kTestSecondURL[] = …;
constexpr char kAboutBlankURL[] = …;
constexpr char kFrameEventDidCreateNewFrame[] = …;
constexpr char kFrameEventDidCreateNewDocument[] = …;
constexpr char kFrameEventDidCreateDocumentElement[] = …;
constexpr char kFrameEventReadyToCommitNavigation[] = …;
constexpr char kFrameEventDidCommitProvisionalLoad[] = …;
constexpr char kFrameEventDidCommitSameDocumentLoad[] = …;
constexpr char kFrameEventAfterCommit[] = …;
constexpr char kNoDocumentMarkerURL[] = …;
class TestSimpleBrowserInterfaceBrokerImpl
: public blink::mojom::BrowserInterfaceBroker { … };
class FrameHostTestInterfaceImpl : public mojom::FrameHostTestInterface { … };
class FrameHostTestInterfaceRequestIssuer : public RenderFrameObserver { … };
class FrameCommitWaiter : public RenderFrameObserver { … };
class FrameCreationObservingRendererClient : public ContentRendererClient { … };
class ScopedNewFrameInterfaceProviderExerciser { … };
void ExpectPendingInterfaceReceiversFromSources(
mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker_receiver,
std::vector<SourceAnnotation> expected_sources) { … }
}
class RenderFrameRemoteInterfacesTest : public RenderViewTest { … };
TEST_F(RenderFrameRemoteInterfacesTest, ChildFrameAtFirstCommittedLoad) { … }
TEST_F(RenderFrameRemoteInterfacesTest,
MainFrameOfOpenedWindowAtFirstCommittedLoad) { … }
TEST_F(RenderFrameRemoteInterfacesTest,
ChildFrameReusingWindowOfInitialDocument) { … }
TEST_F(RenderFrameRemoteInterfacesTest, ReplacedOnNonSameDocumentNavigation) { … }
TEST_F(RenderFrameRemoteInterfacesTest, ReusedOnSameDocumentNavigation) { … }
TEST_F(RenderFrameImplTest, LastCommittedUrlForUKM) { … }
TEST_F(RenderFrameImplTest, SendUpdateCancelsPending) { … }
namespace {
blink::mojom::CommonNavigationParamsPtr
GetCommonParamsForContentSettingsTest() { … }
bool HasText(blink::WebLocalFrame* frame, const std::string& text) { … }
void NavigateAndWait(content::TestRenderFrame* frame,
blink::mojom::CommonNavigationParamsPtr common_params,
blink::mojom::CommitNavigationParamsPtr commit_params,
blink::WebView* web_view) { … }
class FakeContentSettingsClient : public blink::WebContentSettingsClient { … };
}
TEST_F(RenderFrameImplTest, ContentSettingsCallbackImageBlocked) { … }
TEST_F(RenderFrameImplTest, ContentSettingsCallbackScriptBlocked) { … }
TEST_F(RenderFrameImplTest, ContentSettingsCallbackScriptAllowed) { … }
TEST_F(RenderFrameImplTest, ContentSettingsNoscriptTag) { … }
TEST_F(RenderFrameImplTest, ContentSettingsSameDocumentNavigation) { … }
class RenderFrameImplMojoJsTest : public RenderViewTest { … };
TEST_F(RenderFrameImplMojoJsTest, AllowMojoWebUIBindings) { … }
TEST_F(RenderFrameImplMojoJsTest, EnableMojoJSBindings) { … }
TEST_F(RenderFrameImplMojoJsTest, EnableMojoJSBindingsWithBroker) { … }
#if BUILDFLAG(PROTECTED_MEMORY_ENABLED)
using RenderFrameImplMojoJsDeathTest = RenderFrameImplMojoJsTest;
TEST_F(RenderFrameImplMojoJsDeathTest, EnabledBindingsTampered) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_CHECK_DEATH_WITH(
{
GetMainRenderFrame()->enabled_bindings_.Put(
BindingsPolicyValue::kMojoWebUi);
LoadHTML(kSimpleScriptHtml);
},
"Check failed: \\*mojo_js_allowed_");
}
TEST_F(RenderFrameImplMojoJsDeathTest, EnableMojoJsBindingsTampered) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_CHECK_DEATH_WITH(
{
GetMainRenderFrame()->enable_mojo_js_bindings_ = true;
LoadHTML(kSimpleScriptHtml);
},
"Check failed: \\*mojo_js_allowed_");
}
TEST_F(RenderFrameImplMojoJsDeathTest, MojoJsInterfaceBrokerTampered) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_CHECK_DEATH_WITH(
{
GetMainRenderFrame()->mojo_js_interface_broker_ =
TestRenderFrame::CreateStubBrowserInterfaceBrokerRemote();
LoadHTML(kSimpleScriptHtml);
},
"Check failed: \\*mojo_js_allowed_");
}
TEST_F(RenderFrameImplMojoJsDeathTest,
ContextFeatureSettingsEnableMojoJsTampered) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_CHECK_DEATH_WITH(ContextFeatureSettingsEnableMojoJsTampered(),
"Check failed: \\*mojo_js_allowed_");
}
#endif
}