chromium/third_party/blink/renderer/core/frame/frame_test_helpers.cc

/*
 * Copyright (C) 2011 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"

#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "cc/test/test_ukm_recorder_factory.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/render_frame_metadata_observer.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/cpp/web_sandbox_flags.h"
#include "services/network/public/mojom/content_security_policy.mojom-blink-forward.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/frame/fenced_frame_sandbox_flags.h"
#include "third_party/blink/public/common/frame/frame_policy.h"
#include "third_party/blink/public/common/page/browsing_context_group_info.h"
#include "third_party/blink/public/common/page/color_provider_color_maps.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-blink.h"
#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom.h"
#include "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom-blink.h"
#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom-blink.h"
#include "third_party/blink/public/mojom/input/touch_event.mojom-blink.h"
#include "third_party/blink/public/mojom/page/prerender_page_param.mojom.h"
#include "third_party/blink/public/mojom/page/widget.mojom-blink.h"
#include "third_party/blink/public/mojom/partitioned_popins/partitioned_popin_params.mojom.h"
#include "third_party/blink/public/platform/interface_registry.h"
#include "third_party/blink/public/platform/platform.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_string.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/test/test_web_frame_helper.h"
#include "third_party/blink/public/web/web_console_message.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_navigation_params.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view_client.h"
#include "third_party/blink/renderer/core/frame/csp/conversion_util.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/frame/web_remote_frame_impl.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/fake_web_plugin.h"
#include "third_party/blink/renderer/core/testing/mock_policy_container_host.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/scheduler/public/main_thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/widget/input/widget_input_handler_manager.h"
#include "third_party/blink/renderer/platform/widget/widget_base.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "ui/base/ime/mojom/text_input_state.mojom-blink.h"

namespace blink {
namespace frame_test_helpers {

namespace {

// The frame test helpers coordinate frame loads in a carefully choreographed
// dance. Since the parser is threaded, simply spinning the run loop once is not
// enough to ensure completion of a load. Instead, the following pattern is
// used to ensure that tests see the final state:
// 1. Starts a load.
// 2. Enter the run loop.
// 3. Posted task triggers the load, and starts pumping pending resource
//    requests using runServeAsyncRequestsTask().
// 4. TestWebFrameClient watches for DidStartLoading/DidStopLoading calls,
//    keeping track of how many loads it thinks are in flight.
// 5. While RunServeAsyncRequestsTask() observes TestWebFrameClient to still
//    have loads in progress, it posts itself back to the run loop.
// 6. When RunServeAsyncRequestsTask() notices there are no more loads in
//    progress, it exits the run loop.
// 7. At this point, all parsing, resource loads, and layout should be finished.

void RunServeAsyncRequestsTask(scoped_refptr<base::TaskRunner> task_runner,
                               base::OnceClosure quit_closure) {}

// Helper to create a default test client if the supplied client pointer is
// null. The |owned_client| is used to store the client if it must be created.
// In both cases the client to be used is returned.
template <typename T>
T* CreateDefaultClientIfNeeded(T* client, std::unique_ptr<T>& owned_client) {}

template <typename T>
mojo::PendingAssociatedRemote<T> CreateStubRemoteIfNeeded(
    mojo::PendingAssociatedRemote<T> remote) {}

viz::FrameSinkId AllocateFrameSinkId() {}

// Installs a create hook and uninstalls it when this object is
// destroyed.
class ScopedCreateWebFrameWidget {};

}  // namespace

cc::LayerTreeSettings GetSynchronousSingleThreadLayerTreeSettings() {}

void LoadFrameDontWait(WebLocalFrame* frame, const WebURL& url) {}

void LoadFrame(WebLocalFrame* frame, const std::string& url) {}

void LoadHTMLString(WebLocalFrame* frame,
                    const std::string& html,
                    const WebURL& base_url,
                    const base::TickClock* clock) {}

void LoadHistoryItem(WebLocalFrame* frame,
                     const WebHistoryItem& item,
                     mojom::FetchCacheMode cache_mode) {}

void ReloadFrame(WebLocalFrame* frame) {}

void ReloadFrameBypassingCache(WebLocalFrame* frame) {}

void PumpPendingRequestsForFrameToLoad(WebLocalFrame* frame) {}

void FillNavigationParamsResponse(WebNavigationParams* params) {}

WebMouseEvent CreateMouseEvent(WebInputEvent::Type type,
                               WebMouseEvent::Button button,
                               const gfx::Point& point,
                               int modifiers) {}

WebLocalFrameImpl* CreateLocalChild(
    WebLocalFrame& parent,
    mojom::blink::TreeScopeType scope,
    TestWebFrameClient* client,
    WebPolicyContainerBindParams policy_container_bind_params,
    WebLocalFrameClient::FinishChildFrameCreationFn finish_creation) {}

WebLocalFrameImpl* CreateLocalChild(
    WebLocalFrame& parent,
    mojom::blink::TreeScopeType scope,
    std::unique_ptr<TestWebFrameClient> self_owned,
    WebPolicyContainerBindParams policy_container_bind_params,
    WebLocalFrameClient::FinishChildFrameCreationFn finish_creation) {}

WebRemoteFrameImpl* CreateRemote() {}

WebRemoteFrameImpl* CreateRemoteChild(
    WebRemoteFrame& parent,
    const WebString& name,
    scoped_refptr<SecurityOrigin> security_origin) {}

void SwapRemoteFrame(
    WebFrame* old_frame,
    WebRemoteFrame* new_remote_frame,
    mojo::PendingAssociatedRemote<mojom::blink::RemoteFrameHost> frame_host) {}

WebViewHelper::WebViewHelper(
    CreateTestWebFrameWidgetCallback create_web_frame_callback)
    :{}

WebViewHelper::~WebViewHelper() {}

WebViewImpl* WebViewHelper::InitializeWithOpener(
    WebFrame* opener,
    TestWebFrameClient* web_frame_client,
    WebViewClient* web_view_client,
    void (*update_settings_func)(WebSettings*),
    std::optional<blink::FencedFrame::DeprecatedFencedFrameMode>
        fenced_frame_mode,
    bool is_prerendering) {}

WebViewImpl* WebViewHelper::Initialize(
    TestWebFrameClient* web_frame_client,
    WebViewClient* web_view_client,
    void (*update_settings_func)(WebSettings*)) {}

WebViewImpl* WebViewHelper::InitializeWithSettings(
    void (*update_settings_func)(WebSettings*)) {}

// static
void WebViewHelper::UpdateAndroidCompositingSettings(WebSettings* settings) {}

WebViewImpl* WebViewHelper::InitializeAndLoad(
    const std::string& url,
    TestWebFrameClient* web_frame_client,
    WebViewClient* web_view_client,
    void (*update_settings_func)(WebSettings*)) {}

WebViewImpl* WebViewHelper::InitializePlaceholderRemote() {}

WebViewImpl* WebViewHelper::InitializeRemote(
    scoped_refptr<SecurityOrigin> security_origin,
    WebViewClient* web_view_client) {}

WebViewImpl* WebViewHelper::InitializeRemoteWithOpener(
    WebFrame* opener,
    scoped_refptr<SecurityOrigin> security_origin,
    WebViewClient* web_view_client) {}

WebViewImpl*
WebViewHelper::InitializeRemoteWithOpenerAndAssociatedRemoteAndReceivers(
    WebFrame* opener,
    scoped_refptr<SecurityOrigin> security_origin,
    WebViewClient* web_view_client,
    mojo::PendingAssociatedRemote<mojom::blink::RemoteFrameHost>
        remote_frame_host,
    mojo::PendingAssociatedReceiver<mojom::blink::RemoteFrame> receiver) {}

void WebViewHelper::CheckFrameIsAssociatedWithWebView(WebFrame* frame) {}

WebLocalFrameImpl* WebViewHelper::CreateLocalChild(
    WebRemoteFrame& parent,
    const WebString& name,
    const WebFrameOwnerProperties& properties,
    WebFrame* previous_sibling,
    TestWebFrameClient* client) {}

WebLocalFrameImpl* WebViewHelper::CreateProvisional(
    WebFrame& old_frame,
    TestWebFrameClient* client) {}

TestWebFrameWidget* WebViewHelper::CreateFrameWidget(WebLocalFrame* frame) {}

TestWebFrameWidget* WebViewHelper::CreateFrameWidgetAndInitializeCompositing(
    WebLocalFrame* frame) {}

void WebViewHelper::LoadAhem() {}

void WebViewHelper::Reset() {}

cc::LayerTreeHost* WebViewHelper::GetLayerTreeHost() const {}

WebLocalFrameImpl* WebViewHelper::LocalMainFrame() const {}

WebRemoteFrameImpl* WebViewHelper::RemoteMainFrame() const {}

TestWebFrameWidget* WebViewHelper::GetMainFrameWidget() const {}

void WebViewHelper::Resize(const gfx::Size& size) {}

void WebViewHelper::InitializeWebView(
    WebViewClient* web_view_client,
    class WebView* opener,
    std::optional<blink::FencedFrame::DeprecatedFencedFrameMode>
        fenced_frame_mode,
    bool is_prerendering) {}

WebViewImpl* WebViewHelper::CreateWebView(WebViewClient* web_view_client,
                                          bool compositing_enabled) {}

int TestWebFrameClient::loads_in_progress_ =;

TestWebFrameClient::TestWebFrameClient()
    :{}

TestWebFrameClient::~TestWebFrameClient() = default;

void TestWebFrameClient::Bind(WebLocalFrame* frame,
                              std::unique_ptr<TestWebFrameClient> self_owned) {}

void TestWebFrameClient::FrameDetached() {}

WebLocalFrame* TestWebFrameClient::CreateChildFrame(
    mojom::blink::TreeScopeType scope,
    const WebString& name,
    const WebString& fallback_name,
    const FramePolicy& frame_policy,
    const WebFrameOwnerProperties&,
    FrameOwnerElementType,
    WebPolicyContainerBindParams policy_container_bind_params,
    ukm::SourceId document_ukm_source_id,
    FinishChildFrameCreationFn finish_creation) {}

void TestWebFrameClient::DidStartLoading() {}

void TestWebFrameClient::DidStopLoading() {}

bool TestWebFrameClient::SwapIn(WebFrame* previous_frame) {}

std::unique_ptr<URLLoader> TestWebFrameClient::CreateURLLoaderForTesting() {}

void TestWebFrameClient::BeginNavigation(
    std::unique_ptr<WebNavigationInfo> info) {}

void TestWebFrameClient::CommitNavigation(
    std::unique_ptr<WebNavigationInfo> info) {}

WebEffectiveConnectionType TestWebFrameClient::GetEffectiveConnectionType() {}

void TestWebFrameClient::SetEffectiveConnectionTypeForTesting(
    WebEffectiveConnectionType effective_connection_type) {}

void TestWebFrameClient::DidAddMessageToConsole(
    const WebConsoleMessage& message,
    const WebString& source_name,
    unsigned source_line,
    const WebString& stack_trace) {}

WebPlugin* TestWebFrameClient::CreatePlugin(const WebPluginParams& params) {}

AssociatedInterfaceProvider*
TestWebFrameClient::GetRemoteNavigationAssociatedInterfaces() {}

void TestWebFrameClient::DidMeaningfulLayout(
    WebMeaningfulLayout meaningful_layout) {}

WebView* TestWebFrameClient::CreateNewWindow(
    const WebURLRequest&,
    const WebWindowFeatures&,
    const WebString& name,
    WebNavigationPolicy,
    network::mojom::blink::WebSandboxFlags,
    const SessionStorageNamespaceId&,
    bool& consumed_user_gesture,
    const std::optional<Impression>&,
    const std::optional<WebPictureInPictureWindowOptions>&,
    const WebURL&) {}

void TestWebFrameClient::DestroyChildViews() {}

void TestWebFrameClient::SetFrameDetachedCallback(base::OnceClosure callback) {}

TestWidgetInputHandlerHost* TestWebFrameWidget::GetInputHandlerHost() {}

WidgetInputHandlerManager* TestWebFrameWidget::GetWidgetInputHandlerManager()
    const {}

void TestWebFrameWidget::FlushInputHandlerTasks() {}

void TestWebFrameWidget::DispatchThroughCcInputHandler(
    const WebInputEvent& event) {}

display::ScreenInfo TestWebFrameWidget::GetInitialScreenInfo() {}

cc::FakeLayerTreeFrameSink* TestWebFrameWidget::LastCreatedFrameSink() {}

std::unique_ptr<TestWebFrameWidgetHost> TestWebFrameWidget::CreateWidgetHost() {}

void TestWebFrameWidget::BindWidgetChannels(
    mojo::AssociatedRemote<mojom::blink::Widget> widget_remote,
    mojo::PendingAssociatedReceiver<mojom::blink::WidgetHost> receiver,
    mojo::PendingAssociatedReceiver<mojom::blink::FrameWidgetHost>
        frame_receiver) {}

bool TestWebFrameWidget::HaveScrollEventHandlers() const {}

std::unique_ptr<cc::LayerTreeFrameSink>
TestWebFrameWidget::AllocateNewLayerTreeFrameSink() {}

void TestWebFrameWidget::WillQueueSyntheticEvent(
    const WebCoalescedInputEvent& event) {}

void TestWebFrameWidgetHost::SetCursor(const ui::Cursor& cursor) {}

void TestWebFrameWidgetHost::UpdateTooltipUnderCursor(
    const String& tooltip_text,
    base::i18n::TextDirection text_direction_hint) {}

void TestWebFrameWidgetHost::UpdateTooltipFromKeyboard(
    const String& tooltip_text,
    base::i18n::TextDirection text_direction_hint,
    const gfx::Rect& bounds) {}

void TestWebFrameWidgetHost::ClearKeyboardTriggeredTooltip() {}

void TestWebFrameWidgetHost::TextInputStateChanged(
    ui::mojom::blink::TextInputStatePtr state) {}

void TestWebFrameWidgetHost::SelectionBoundsChanged(
    const gfx::Rect& anchor_rect,
    base::i18n::TextDirection anchor_dir,
    const gfx::Rect& focus_rect,
    base::i18n::TextDirection focus_dir,
    const gfx::Rect& bounding_box,
    bool is_anchor_first) {}

void TestWebFrameWidgetHost::CreateFrameSink(
    mojo::PendingReceiver<viz::mojom::blink::CompositorFrameSink>
        compositor_frame_sink_receiver,
    mojo::PendingRemote<viz::mojom::blink::CompositorFrameSinkClient>
        compositor_frame_sink_client) {}

void TestWebFrameWidgetHost::RegisterRenderFrameMetadataObserver(
    mojo::PendingReceiver<cc::mojom::blink::RenderFrameMetadataObserverClient>
        render_frame_metadata_observer_client_receiver,
    mojo::PendingRemote<cc::mojom::blink::RenderFrameMetadataObserver>
        render_frame_metadata_observer) {}

void TestWebFrameWidgetHost::AnimateDoubleTapZoomInMainFrame(
    const gfx::Point& tap_point,
    const gfx::Rect& rect_to_zoom) {}

void TestWebFrameWidgetHost::ZoomToFindInPageRectInMainFrame(
    const gfx::Rect& rect_to_zoom) {}

void TestWebFrameWidgetHost::SetHasTouchEventConsumers(
    mojom::blink::TouchEventConsumersPtr consumers) {}

void TestWebFrameWidgetHost::IntrinsicSizingInfoChanged(
    mojom::blink::IntrinsicSizingInfoPtr sizing_info) {}

void TestWebFrameWidgetHost::AutoscrollStart(const gfx::PointF& position) {}

void TestWebFrameWidgetHost::AutoscrollFling(const gfx::Vector2dF& position) {}

void TestWebFrameWidgetHost::AutoscrollEnd() {}

void TestWebFrameWidgetHost::BindWidgetHost(
    mojo::PendingAssociatedReceiver<mojom::blink::WidgetHost> receiver,
    mojo::PendingAssociatedReceiver<mojom::blink::FrameWidgetHost>
        frame_receiver) {}

void TestWebFrameWidgetHost::BindRenderInputRouterInterfaces(
    mojo::PendingRemote<mojom::blink::RenderInputRouterClient> remote) {}

void TestWebFrameWidgetHost::GetWidgetInputHandler(
    mojo::PendingReceiver<mojom::blink::WidgetInputHandler> request,
    mojo::PendingRemote<mojom::blink::WidgetInputHandlerHost> host) {}

mojo::PendingRemote<mojom::blink::WidgetInputHandlerHost>
TestWidgetInputHandlerHost::BindNewRemote() {}

void TestWidgetInputHandlerHost::SetTouchActionFromMain(
    cc::TouchAction touch_action) {}

void TestWidgetInputHandlerHost::SetPanAction(
    mojom::blink::PanAction pan_action) {}

void TestWidgetInputHandlerHost::DidOverscroll(
    mojom::blink::DidOverscrollParamsPtr params) {}

void TestWidgetInputHandlerHost::DidStartScrollingViewport() {}

void TestWidgetInputHandlerHost::ImeCancelComposition() {}

void TestWidgetInputHandlerHost::ImeCompositionRangeChanged(
    const gfx::Range& range,
    const std::optional<WTF::Vector<gfx::Rect>>& character_bounds,
    const std::optional<WTF::Vector<gfx::Rect>>& line_bounds) {}

void TestWidgetInputHandlerHost::SetMouseCapture(bool capture) {}

void TestWidgetInputHandlerHost::SetAutoscrollSelectionActiveInMainFrame(
    bool autoscroll_selection) {}

void TestWidgetInputHandlerHost::RequestMouseLock(
    bool from_user_gesture,
    bool unadjusted_movement,
    RequestMouseLockCallback callback) {}

}  // namespace frame_test_helpers
}  // namespace blink