#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <tuple>
#include "base/command_line.h"
#include "base/containers/heap_array.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_state.h"
#include "cc/trees/layer_tree_host.h"
#include "components/input/native_web_keyboard_event.h"
#include "content/common/renderer.mojom.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/renderer_preferences_util.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_controller_factory.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fake_render_widget_host.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/accessibility/render_accessibility_impl.h"
#include "content/renderer/accessibility/render_accessibility_manager.h"
#include "content/renderer/agent_scheduling_group.h"
#include "content/renderer/document_state.h"
#include "content/renderer/navigation_state.h"
#include "content/renderer/render_process.h"
#include "content/renderer/service_worker/service_worker_network_provider_for_frame.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/test/mock_keyboard.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/mojom/base/text_direction.mojom-blink.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h"
#include "net/dns/public/resolve_error_info.h"
#include "net/http/http_util.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "skia/ext/legacy_display_globals.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
#include "third_party/blink/public/common/navigation/navigation_params.h"
#include "third_party/blink/public/common/origin_trials/scoped_test_origin_trial_policy.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/common/switches.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/common/widget/device_emulation_params.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/remote_frame.mojom.h"
#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_network_provider.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/public/platform/web_http_body.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/test/test_web_frame_content_dumper.h"
#include "third_party/blink/public/web/web_autofill_client.h"
#include "third_party/blink/public/web/web_document_loader.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_history_commit_type.h"
#include "third_party/blink/public/web/web_history_item.h"
#include "third_party/blink/public/web/web_input_method_controller.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_navigation_params.h"
#include "third_party/blink/public/web/web_navigation_type.h"
#include "third_party/blink/public/web/web_origin_trials.h"
#include "third_party/blink/public/web/web_page_popup.h"
#include "third_party/blink/public/web/web_performance_metrics_for_reporting.h"
#include "third_party/blink/public/web/web_picture_in_picture_window_options.h"
#include "third_party/blink/public/web/web_remote_frame.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view.h"
#include "third_party/blink/public/web/web_window_features.h"
#include "ui/accessibility/ax_mode.h"
#include "ui/base/ime/mojom/text_input_state.mojom.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/range/range.h"
#include "url/url_constants.h"
#if BUILDFLAG(IS_ANDROID)
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
#include "third_party/blink/public/common/input/web_gesture_device.h"
#include "third_party/blink/public/common/input/web_gesture_event.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#endif
#if BUILDFLAG(IS_OZONE)
#include "ui/events/keycodes/keyboard_code_conversion.h"
#endif
TestWebFrameContentDumper;
WebFrame;
WebGestureEvent;
WebInputEvent;
WebLocalFrame;
WebMouseEvent;
WebString;
WebURLError;
namespace content {
namespace {
static const int kProxyRoutingId = …;
#if BUILDFLAG(IS_OZONE)
int ConvertMockKeyboardModifier(MockKeyboard::Modifiers modifiers) { … }
#endif
class WebUITestWebUIControllerFactory : public WebUIControllerFactory { … };
blink::mojom::FrameReplicationStatePtr ReconstructReplicationStateForTesting(
TestRenderFrame* test_render_frame) { … }
blink::mojom::CommonNavigationParamsPtr MakeCommonNavigationParams(
base::TimeDelta navigation_start_offset) { … }
template <class MockedLocalFrameHostInterceptor>
class MockedLocalFrameHostInterceptorTestRenderFrame : public TestRenderFrame { … };
blink::mojom::CommitNavigationParamsPtr DummyCommitNavigationParams() { … }
blink::mojom::RemoteFrameInterfacesFromBrowserPtr
CreateStubRemoteFrameInterfaces() { … }
blink::mojom::RemoteMainFrameInterfacesPtr
CreateStubRemoteMainFrameInterfaces() { … }
class CommonParamsFrameLoadWaiter : public FrameLoadWaiter { … };
}
class RenderViewImplTest : public RenderViewTest { … };
class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { … };
class RenderViewImplScaleFactorTest : public RenderViewImplTest { … };
TEST_F(RenderViewImplTest, IsPinchGestureActivePropagatesToProxies) { … }
TEST_F(RenderViewImplTest, OnNavStateChanged) { … }
TEST_F(RenderViewImplTest, OnNavigationHttpPost) { … }
#if BUILDFLAG(IS_ANDROID)
namespace {
class UpdateTitleLocalFrameHost : public LocalFrameHostInterceptor {
public:
explicit UpdateTitleLocalFrameHost(
blink::AssociatedInterfaceProvider* provider)
: LocalFrameHostInterceptor(provider) {}
MOCK_METHOD2(UpdateTitle,
void(const std::optional<::std::u16string>& title,
base::i18n::TextDirection title_direction));
};
}
class RenderViewImplUpdateTitleTest : public RenderViewImplTest {
public:
using MockedTestRenderFrame =
MockedLocalFrameHostInterceptorTestRenderFrame<UpdateTitleLocalFrameHost>;
RenderViewImplUpdateTitleTest()
: RenderViewImplTest(&MockedTestRenderFrame::CreateTestRenderFrame) {}
UpdateTitleLocalFrameHost* title_mock_frame_host() {
return static_cast<MockedTestRenderFrame*>(frame())
->mock_local_frame_host();
}
};
TEST_F(RenderViewImplUpdateTitleTest, OnNavigationLoadDataWithBaseURL) {
auto common_params = blink::CreateCommonNavigationParams();
common_params->url = GURL("data:text/html,");
common_params->navigation_type =
blink::mojom::NavigationType::DIFFERENT_DOCUMENT;
common_params->transition = ui::PAGE_TRANSITION_TYPED;
common_params->base_url_for_data_url = GURL("about:blank");
auto commit_params = DummyCommitNavigationParams();
commit_params->data_url_as_string =
"data:text/html,<html><head><title>Data page</title></head></html>";
const std::optional<::std::u16string>& title =
std::make_optional(u"Data page");
EXPECT_CALL(*title_mock_frame_host(), UpdateTitle(title, testing::_))
.Times(1);
FrameLoadWaiter waiter(frame());
frame()->Navigate(std::move(common_params), std::move(commit_params));
waiter.Wait();
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(title_mock_frame_host());
}
#endif
TEST_F(RenderViewImplTest, BeginNavigation) { … }
TEST_F(RenderViewImplTest, BeginNavigationHandlesAllTopLevel) { … }
TEST_F(RenderViewImplTest, BeginNavigationForWebUI) { … }
TEST_F(RenderViewImplScaleFactorTest, DeviceEmulationWithOOPIF) { … }
TEST_F(RenderViewImplTest, OriginReplicationForUnload) { … }
TEST_F(RenderViewImplScaleFactorTest, DeviceScaleCorrectAfterCrossOriginNav) { … }
TEST_F(RenderViewImplTest, DetachingProxyAlsoDestroysProvisionalFrame) { … }
TEST_F(RenderViewImplScaleFactorTest, SetZoomLevelAfterCrossProcessNavigation) { … }
class TextInputStateFakeRenderWidgetHost : public FakeRenderWidgetHost { … };
class RenderViewImplTextInputStateChanged : public RenderViewImplTest { … };
TEST_F(RenderViewImplTextInputStateChanged, OnImeTypeChanged) { … }
TEST_F(RenderViewImplTextInputStateChanged,
ShouldSuppressKeyboardIsPropagated) { … }
TEST_F(RenderViewImplTextInputStateChanged,
EditContextGetLayoutBoundsAndInputPanelPolicy) { … }
TEST_F(RenderViewImplTextInputStateChanged,
EditContextGetLayoutBoundsWithFloatingValues) { … }
TEST_F(RenderViewImplTextInputStateChanged,
EditContextGetLayoutBoundsWithOverflowFloatingValues) { … }
TEST_F(RenderViewImplTextInputStateChanged, ActiveElementGetLayoutBounds) { … }
TEST_F(RenderViewImplTextInputStateChanged,
ActiveElementMultipleLayoutBoundsUpdates) { … }
TEST_F(RenderViewImplTextInputStateChanged,
ActiveElementLayoutBoundsUpdatesDuringBrowserZoom) { … }
TEST_F(RenderViewImplTextInputStateChanged, VirtualKeyboardPolicyAuto) { … }
TEST_F(RenderViewImplTextInputStateChanged, VirtualKeyboardPolicyAutoToManual) { … }
TEST_F(RenderViewImplTextInputStateChanged,
VirtualKeyboardPolicyManualAndShowHideAPIsCalledInInsecureContext) { … }
TEST_F(RenderViewImplTextInputStateChanged,
VirtualKeyboardPolicyAutoAndShowHideAPIsCalled) { … }
TEST_F(RenderViewImplTest, ImeComposition) { … }
TEST_F(RenderViewImplTest, OnSetTextDirection) { … }
TEST_F(RenderViewImplTest, DroppedNavigationStaysInViewSourceMode) { … }
namespace {
class ContextMenuFrameHost : public LocalFrameHostInterceptor { … };
}
class RenderViewImplContextMenuTest : public RenderViewImplTest { … };
#if !BUILDFLAG(IS_ANDROID)
TEST_F(RenderViewImplContextMenuTest, ContextMenu) { … }
#else
TEST_F(RenderViewImplContextMenuTest, AndroidContextMenuSelectionOrdering) {
LoadHTML("<div>Page A</div><div id=result>Not selected</div>");
ExecuteJavaScriptForTests(
"document.onselectionchange = function() { "
"document.getElementById('result').innerHTML = 'Selected'}");
WebGestureEvent gesture_event(WebInputEvent::Type::kGestureLongPress,
WebInputEvent::kNoModifiers,
ui::EventTimeForNow());
gesture_event.SetPositionInWidget(gfx::PointF(250, 250));
EXPECT_CALL(*context_menu_frame_host(),
ShowContextMenu(testing::_, testing::_))
.Times(0);
SendWebGestureEvent(gesture_event);
EXPECT_CALL(*context_menu_frame_host(),
ShowContextMenu(testing::_, testing::_))
.Times(1);
scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
blink::scheduler::GetSingleThreadTaskRunnerForTesting()->PostTask(
FROM_HERE, message_loop_runner->QuitClosure());
message_loop_runner->Run();
int did_select = -1;
std::u16string check_did_select =
u"Number(document.getElementById('result').innerHTML == 'Selected')";
EXPECT_TRUE(
ExecuteJavaScriptAndReturnIntValue(check_did_select, &did_select));
EXPECT_EQ(1, did_select);
}
#endif
TEST_F(RenderViewImplTest, TestBackForward) { … }
#if BUILDFLAG(IS_MAC) || defined(USE_AURA)
TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) { … }
#endif
TEST_F(RenderViewImplTest, SetEditableSelectionAndComposition) { … }
TEST_F(RenderViewImplTest, OnExtendSelectionAndDelete) { … }
TEST_F(RenderViewImplTest, OnDeleteSurroundingText) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_OnDeleteSurroundingTextInCodePoints …
#else
#define MAYBE_OnDeleteSurroundingTextInCodePoints …
#endif
TEST_F(RenderViewImplTest, MAYBE_OnDeleteSurroundingTextInCodePoints) { … }
TEST_F(RenderViewImplTest, NavigateSubframe) { … }
TEST_F(RenderViewImplTest, BasicRenderFrame) { … }
namespace {
class MessageOrderFakeRenderWidgetHost : public FakeRenderWidgetHost { … };
class TextSelectionChangedLocalFrameHost : public LocalFrameHostInterceptor { … };
}
class RenderViewImplTextInputMessageOrder : public RenderViewImplTest { … };
#if BUILDFLAG(IS_WIN)
#define MAYBE_MessageOrderInDidChangeSelection …
#else
#define MAYBE_MessageOrderInDidChangeSelection …
#endif
TEST_F(RenderViewImplTextInputMessageOrder,
MAYBE_MessageOrderInDidChangeSelection) { … }
class RendererErrorPageTest : public RenderViewImplTest { … };
TEST_F(RendererErrorPageTest, RegularError) { … }
TEST_F(RenderViewImplTest, SetAccessibilityMode) { … }
TEST_F(RenderViewImplTest, AccessibilityModeOnClosingConnection) { … }
TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { … }
TEST_F(RenderViewImplTest, BrowserNavigationStart) { … }
TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) { … }
TEST_F(RenderViewImplTest, NavigationStartWhenInitialDocumentWasAccessed) { … }
TEST_F(RenderViewImplTest, NavigationStartForReload) { … }
TEST_F(RenderViewImplTest, NavigationStartForSameProcessHistoryNavigation) { … }
TEST_F(RenderViewImplTest, NavigationStartForCrossProcessHistoryNavigation) { … }
TEST_F(RenderViewImplTest, PreferredSizeZoomed) { … }
TEST_F(RenderViewImplScaleFactorTest, PreferredSizeWithScaleFactor) { … }
TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnNavigation) { … }
TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnHistoryNavigation) { … }
TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnShouldClearHistoryList) { … }
namespace {
class AddMessageToConsoleMockLocalFrameHost : public LocalFrameHostInterceptor { … };
}
class RenderViewImplAddMessageToConsoleTest : public RenderViewImplTest { … };
TEST_F(RenderViewImplAddMessageToConsoleTest,
DispatchBeforeUnloadCanDetachFrame) { … }
namespace {
class AlertDialogMockLocalFrameHost : public LocalFrameHostInterceptor { … };
}
class RenderViewImplModalDialogTest : public RenderViewImplTest { … };
TEST_F(RenderViewImplModalDialogTest, ModalDialogs) { … }
TEST_F(RenderViewImplBlinkSettingsTest, Default) { … }
TEST_F(RenderViewImplBlinkSettingsTest, CommandLine) { … }
TEST_F(RenderViewImplBlinkSettingsTest, DefaultPageScaleSettings) { … }
TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) { … }
TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) { … }
TEST_F(RenderViewImplScaleFactorTest, ConvertViewportToWindow) { … }
#if BUILDFLAG(IS_MAC) || defined(USE_AURA)
TEST_F(RenderViewImplScaleFactorTest,
DISABLED_GetCompositionCharacterBoundsTest) { … }
#endif
#if !BUILDFLAG(IS_ANDROID)
namespace {
const char kAutoResizeTestPage[] = …;
}
TEST_F(RenderViewImplScaleFactorTest, AutoResize) { … }
TEST_F(RenderViewImplTest, ZoomLevelUpdate) { … }
#endif
TEST_F(RenderViewImplTest, OriginTrialDisabled) { … }
TEST_F(RenderViewImplTest, OriginTrialEnabled) { … }
TEST_F(RenderViewImplTest, CollapseSelectionNotChangeFocus) { … }
#if BUILDFLAG(IS_WIN)
class RenderViewImplContrastGammaSettingsTest : public RenderViewImplTest {
protected:
void SetUp() override {
RenderViewImplTest::SetUp();
feature_list_.InitAndEnableFeature(
features::kUseGammaContrastRegistrySettings);
}
base::test::ScopedFeatureList feature_list_;
};
TEST_F(RenderViewImplContrastGammaSettingsTest,
ContrastGammaSetRendererPreferences) {
LoadHTML(R"HTML(
<input id='test' type='text'></input>
)HTML");
constexpr float test_contrast = 0.95;
static_assert(test_contrast != SK_GAMMA_CONTRAST);
static_assert(test_contrast >= SkSurfaceProps::kMinContrastInclusive);
static_assert(test_contrast <= SkSurfaceProps::kMaxContrastInclusive);
constexpr float test_gamma = 3.99;
static_assert(test_gamma != SK_GAMMA_EXPONENT);
static_assert(test_gamma >= SkSurfaceProps::kMinGammaInclusive);
static_assert(test_gamma < SkSurfaceProps::kMaxGammaExclusive);
blink::RendererPreferences renderer_preferences =
web_view_->GetRendererPreferences();
EXPECT_NE(renderer_preferences.text_contrast, test_contrast);
EXPECT_NE(renderer_preferences.text_gamma, test_gamma);
renderer_preferences.text_contrast = test_contrast;
renderer_preferences.text_gamma = test_gamma;
web_view_->SetRendererPreferences(renderer_preferences);
SkSurfaceProps surface_props =
skia::LegacyDisplayGlobals::GetSkSurfaceProps();
EXPECT_EQ(surface_props.textContrast(), test_contrast);
EXPECT_EQ(surface_props.textGamma(), test_gamma);
}
#endif
}