// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_ #define CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_ #include <stdint.h> #include <string> #include <vector> #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/time/time.h" #include "build/build_config.h" #include "components/input/cursor_manager.h" #include "components/viz/common/surfaces/frame_sink_id.h" #include "components/viz/host/host_frame_sink_client.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/render_widget_host_view_child_frame.h" #include "content/public/common/page_visibility_state.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_renderer_host.h" #include "third_party/blink/public/common/web_preferences/web_preferences.h" #include "ui/base/cursor/cursor.h" #include "ui/base/ime/dummy_text_input_client.h" #include "ui/base/page_transition_types.h" #include "ui/base/resource/resource_scale_factor.h" #include "ui/gfx/geometry/vector2d_f.h" #if defined(USE_AURA) #include "ui/aura/window.h" #endif #if BUILDFLAG(IS_MAC) #include "third_party/blink/public/mojom/webshare/webshare.mojom.h" #endif // This file provides a testing framework for mocking out the RenderProcessHost // layer. It allows you to test RenderViewHost, WebContentsImpl, // NavigationController, and other layers above that without running an actual // renderer process. // // To use, derive your test base class from RenderViewHostImplTestHarness. namespace gfx { class Rect; } namespace content { class FrameTree; class TestRenderFrameHost; class TestPageBroadcast; class TestWebContents; // TestRenderWidgetHostView ---------------------------------------------------- // Subclass the RenderViewHost's view so that we can call Show(), etc., // without having side-effects. class TestRenderWidgetHostView : public RenderWidgetHostViewBase, public viz::HostFrameSinkClient { … }; // TestRenderWidgetHostViewChildFrame ----------------------------------------- // Test version of RenderWidgetHostViewChildFrame to use in unit tests. class TestRenderWidgetHostViewChildFrame : public RenderWidgetHostViewChildFrame { … }; // TestRenderViewHost ---------------------------------------------------------- // TODO(brettw) this should use a TestWebContents which should be generalized // from the WebContentsImpl test. We will probably also need that class' version // of CreateRenderViewForRenderManager when more complicated tests start using // this. // // Note that users outside of content must use this class by getting // the separate RenderViewHostTester interface via // RenderViewHostTester::For(rvh) on the RenderViewHost they want to // drive tests on. // // Users within content may directly static_cast from a // RenderViewHost* to a TestRenderViewHost*. // // The reasons we do it this way rather than extending the parallel // inheritance hierarchy we have for RenderWidgetHost/RenderViewHost // vs. RenderWidgetHostImpl/RenderViewHostImpl are: // // a) Extending the parallel class hierarchy further would require // more classes to use virtual inheritance. This is a complexity that // is better to avoid, especially when it would be introduced in the // production code solely to facilitate testing code. // // b) While users outside of content only need to drive tests on a // RenderViewHost, content needs a test version of the full // RenderViewHostImpl so that it can test all methods on that concrete // class (e.g. overriding a method such as // RenderViewHostImpl::CreateRenderView). This would have complicated // the dual class hierarchy even further. // // The reason we do it this way instead of using composition is // similar to (b) above, essentially it gets very tricky. By using // the split interface we avoid complexity within content and maintain // reasonable utility for embedders. class TestRenderViewHost : public RenderViewHostImpl, public RenderViewHostTester { … }; // Adds methods to get straight at the impl classes. class RenderViewHostImplTestHarness : public RenderViewHostTestHarness { … }; } // namespace content #endif // CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_