blob: 993282be051f753c9335c42807206265bebd94df [file] [log] [blame]
[email protected]2a18ee222013-11-21 07:52:441// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4bfd4612013-12-05 18:12:485#ifndef CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
6#define CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
[email protected]2a18ee222013-11-21 07:52:447
avi66a07722015-12-25 23:38:128#include <stdint.h>
9
[email protected]c1982ff2014-04-23 03:37:2110#include <vector>
11
avi66a07722015-12-25 23:38:1212#include "base/macros.h"
[email protected]2a18ee222013-11-21 07:52:4413#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]e2d2d4202014-07-03 12:17:4814#include "content/public/browser/web_contents_observer.h"
nickddc9d532015-04-16 17:46:2915#include "content/public/test/mock_render_process_host.h"
[email protected]e2d2d4202014-07-03 12:17:4816#include "content/public/test/test_renderer_host.h"
[email protected]6b50e362014-08-15 05:15:5917#include "content/test/test_render_view_host.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3518#include "ui/base/page_transition_types.h"
[email protected]37567b432014-02-12 01:12:2219
20struct FrameHostMsg_DidCommitProvisionalLoad_Params;
[email protected]2a18ee222013-11-21 07:52:4421
22namespace content {
23
[email protected]e2d2d4202014-07-03 12:17:4824class TestRenderFrameHostCreationObserver : public WebContentsObserver {
25 public:
26 explicit TestRenderFrameHostCreationObserver(WebContents* web_contents);
dchenge933b3eb2014-10-21 11:44:0927 ~TestRenderFrameHostCreationObserver() override;
[email protected]e2d2d4202014-07-03 12:17:4828
29 // WebContentsObserver implementation.
dchenge933b3eb2014-10-21 11:44:0930 void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
[email protected]e2d2d4202014-07-03 12:17:4831
32 RenderFrameHost* last_created_frame() const { return last_created_frame_; }
33
34 private:
35 RenderFrameHost* last_created_frame_;
36};
37
38class TestRenderFrameHost : public RenderFrameHostImpl,
39 public RenderFrameHostTester {
[email protected]2a18ee222013-11-21 07:52:4440 public:
nasko9a45a9a2015-01-27 22:42:5441 TestRenderFrameHost(SiteInstance* site_instance,
42 RenderViewHostImpl* render_view_host,
[email protected]92404c62013-12-04 16:40:4643 RenderFrameHostDelegate* delegate,
kenrba7199832015-01-22 23:44:5944 RenderWidgetHostDelegate* rwh_delegate,
[email protected]2a18ee222013-11-21 07:52:4445 FrameTree* frame_tree,
[email protected]52913802013-12-10 05:52:1846 FrameTreeNode* frame_tree_node,
avi66a07722015-12-25 23:38:1247 int32_t routing_id,
48 int32_t widget_routing_id,
kenrb32d18a42014-11-17 22:16:0749 int flags);
dchenge933b3eb2014-10-21 11:44:0950 ~TestRenderFrameHost() override;
[email protected]2a18ee222013-11-21 07:52:4451
nickddc9d532015-04-16 17:46:2952 // RenderFrameHostImpl overrides (same values, but in Test*/Mock* types)
dchenge933b3eb2014-10-21 11:44:0953 TestRenderViewHost* GetRenderViewHost() override;
nickddc9d532015-04-16 17:46:2954 MockRenderProcessHost* GetProcess() override;
[email protected]6b50e362014-08-15 05:15:5955
[email protected]e2d2d4202014-07-03 12:17:4856 // RenderFrameHostTester implementation.
nasko8c95dcf52015-06-02 13:44:4857 void InitializeRenderFrameIfNeeded() override;
dchenge933b3eb2014-10-21 11:44:0958 TestRenderFrameHost* AppendChild(const std::string& frame_name) override;
jyasskin4a12e672016-02-09 22:39:0759 void Detach() override;
clamy0e119882015-07-31 16:12:3360 void SimulateNavigationStart(const GURL& url) override;
61 void SimulateRedirect(const GURL& new_url) override;
62 void SimulateNavigationCommit(const GURL& url) override;
63 void SimulateNavigationError(const GURL& url, int error_code) override;
64 void SimulateNavigationErrorPageCommit() override;
65 void SimulateNavigationStop() override;
avif9a94c7e2016-10-14 15:54:1166 void SendNavigate(int nav_entry_id,
avi7c6f35e2015-05-08 17:52:3867 bool did_create_new_entry,
68 const GURL& url) override;
avif9a94c7e2016-10-14 15:54:1169 void SendFailedNavigate(int nav_entry_id,
avi7c6f35e2015-05-08 17:52:3870 bool did_create_new_entry,
71 const GURL& url) override;
avif9a94c7e2016-10-14 15:54:1172 void SendNavigateWithTransition(int nav_entry_id,
avi7c6f35e2015-05-08 17:52:3873 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0974 const GURL& url,
75 ui::PageTransition transition) override;
76 void SetContentsMimeType(const std::string& mime_type) override;
77 void SendBeforeUnloadACK(bool proceed) override;
78 void SimulateSwapOutACK() override;
avif9a94c7e2016-10-14 15:54:1179 void NavigateAndCommitRendererInitiated(bool did_create_new_entry,
scottmg045680d2016-09-08 19:56:1480 const GURL& url) override;
[email protected]e2d2d4202014-07-03 12:17:4881
avif9a94c7e2016-10-14 15:54:1182 void SendNavigateWithReplacement(int nav_entry_id,
creis865ad442016-03-15 16:43:0983 bool did_create_new_entry,
84 const GURL& url);
85
avi13963b62015-06-12 23:10:5886 using ModificationCallback =
87 base::Callback<void(FrameHostMsg_DidCommitProvisionalLoad_Params*)>;
88
89 void SendNavigateWithModificationCallback(
avi7c6f35e2015-05-08 17:52:3890 int nav_entry_id,
91 bool did_create_new_entry,
[email protected]37567b432014-02-12 01:12:2292 const GURL& url,
avi13963b62015-06-12 23:10:5893 const ModificationCallback& callback);
94 void SendNavigateWithParams(
95 FrameHostMsg_DidCommitProvisionalLoad_Params* params);
carloskd6a4ef362015-03-04 10:46:1796
97 // With the current navigation logic this method is a no-op.
98 // PlzNavigate: this method simulates receiving a BeginNavigation IPC.
99 void SendRendererInitiatedNavigationRequest(const GURL& url,
100 bool has_user_gesture);
[email protected]37567b432014-02-12 01:12:22101
alexmos95733002015-08-24 16:38:09102 void DidChangeOpener(int opener_routing_id);
[email protected]eaece5472014-08-22 23:36:47103
mkwstf672e7ef2016-06-09 20:51:07104 void DidEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy);
estarka886b8d2015-12-18 21:53:08105
[email protected]37567b432014-02-12 01:12:22106 // If set, navigations will appear to have cleared the history list in the
107 // RenderFrame
108 // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared).
109 // False by default.
110 void set_simulate_history_list_was_cleared(bool cleared) {
111 simulate_history_list_was_cleared_ = cleared;
112 }
113
clamy7c5016cc2014-12-19 15:58:29114 // Advances the RenderFrameHost (and through it the RenderFrameHostManager) to
115 // a state where a new navigation can be committed by a renderer. Currently,
116 // this simulates a BeforeUnload ACK from the renderer.
117 // PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the
118 // interaction with the IO thread up until the response is ready to commit.
carloskd6a4ef362015-03-04 10:46:17119 void PrepareForCommit();
120
121 // This method does the same as PrepareForCommit.
122 // PlzNavigate: Beyond doing the same as PrepareForCommit, this method will
123 // also simulate a server redirect to |redirect_url|. If the URL is empty the
124 // redirect step is ignored.
125 void PrepareForCommitWithServerRedirect(const GURL& redirect_url);
clamy7c5016cc2014-12-19 15:58:29126
scottmgd2b6c5d2016-09-01 18:36:25127 // If we are doing a cross-site navigation, this simulates the current
128 // RenderFrameHost notifying that BeforeUnload has executed so the pending
129 // RenderFrameHost is resumed and can navigate.
130 // PlzNavigate: This simulates a BeforeUnload ACK from the renderer, and the
131 // interaction with the IO thread up until the response is ready to commit.
132 void PrepareForCommitIfNecessary();
133
clamy5bf36112015-04-17 15:23:22134 // PlzNavigate
135 void set_pending_commit(bool pending) { pending_commit_ = pending; }
136 bool pending_commit() const { return pending_commit_; }
137
ortuno77bb42c2016-08-01 18:41:09138 // Creates a WebBluetooth Service with a dummy InterfaceRequest.
139 WebBluetoothServiceImpl* CreateWebBluetoothServiceForTesting();
140
[email protected]2a18ee222013-11-21 07:52:44141 private:
avif9a94c7e2016-10-14 15:54:11142 void SendNavigateWithParameters(int nav_entry_id,
avi13963b62015-06-12 23:10:58143 bool did_create_new_entry,
creis865ad442016-03-15 16:43:09144 bool should_replace_entry,
avi13963b62015-06-12 23:10:58145 const GURL& url,
146 ui::PageTransition transition,
147 int response_code,
148 const ModificationCallback& callback);
149
clamy0e119882015-07-31 16:12:33150 // Computes the page ID for a pending navigation in this RenderFrameHost;
avi66a07722015-12-25 23:38:12151 int32_t ComputeNextPageID();
clamy0e119882015-07-31 16:12:33152
csharrisondd06bab2016-07-22 14:15:02153 void SimulateWillStartRequest(ui::PageTransition transition);
154
[email protected]e2d2d4202014-07-03 12:17:48155 TestRenderFrameHostCreationObserver child_creation_observer_;
156
[email protected]37567b432014-02-12 01:12:22157 std::string contents_mime_type_;
158
159 // See set_simulate_history_list_was_cleared() above.
160 bool simulate_history_list_was_cleared_;
161
[email protected]2a18ee222013-11-21 07:52:44162 DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost);
163};
164
165} // namespace content
166
[email protected]4bfd4612013-12-05 18:12:48167#endif // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_