1 // 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.
5 #ifndef CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
6 #define CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
10 #include "base/basictypes.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/test/mock_render_process_host.h"
14 #include "content/public/test/test_renderer_host.h"
15 #include "content/test/test_render_view_host.h"
16 #include "ui/base/page_transition_types.h"
18 struct FrameHostMsg_DidCommitProvisionalLoad_Params
;
22 class TestRenderFrameHostCreationObserver
: public WebContentsObserver
{
24 explicit TestRenderFrameHostCreationObserver(WebContents
* web_contents
);
25 ~TestRenderFrameHostCreationObserver() override
;
27 // WebContentsObserver implementation.
28 void RenderFrameCreated(RenderFrameHost
* render_frame_host
) override
;
30 RenderFrameHost
* last_created_frame() const { return last_created_frame_
; }
33 RenderFrameHost
* last_created_frame_
;
36 class TestRenderFrameHost
: public RenderFrameHostImpl
,
37 public RenderFrameHostTester
{
39 TestRenderFrameHost(SiteInstance
* site_instance
,
40 RenderViewHostImpl
* render_view_host
,
41 RenderFrameHostDelegate
* delegate
,
42 RenderWidgetHostDelegate
* rwh_delegate
,
43 FrameTree
* frame_tree
,
44 FrameTreeNode
* frame_tree_node
,
47 ~TestRenderFrameHost() override
;
49 // RenderFrameHostImpl overrides (same values, but in Test*/Mock* types)
50 TestRenderViewHost
* GetRenderViewHost() override
;
51 MockRenderProcessHost
* GetProcess() override
;
53 // RenderFrameHostTester implementation.
54 void InitializeRenderFrameIfNeeded() override
;
55 TestRenderFrameHost
* AppendChild(const std::string
& frame_name
) override
;
56 void SendNavigate(int page_id
,
58 bool did_create_new_entry
,
59 const GURL
& url
) override
;
60 void SendFailedNavigate(int page_id
,
62 bool did_create_new_entry
,
63 const GURL
& url
) override
;
64 void SendNavigateWithTransition(int page_id
,
66 bool did_create_new_entry
,
68 ui::PageTransition transition
) override
;
69 void SetContentsMimeType(const std::string
& mime_type
) override
;
70 void SendBeforeUnloadACK(bool proceed
) override
;
71 void SimulateSwapOutACK() override
;
73 using ModificationCallback
=
74 base::Callback
<void(FrameHostMsg_DidCommitProvisionalLoad_Params
*)>;
76 void SendNavigateWithModificationCallback(
79 bool did_create_new_entry
,
81 const ModificationCallback
& callback
);
82 void SendNavigateWithParams(
83 FrameHostMsg_DidCommitProvisionalLoad_Params
* params
);
85 // Simulate a renderer-initiated navigation up until commit.
86 void NavigateAndCommitRendererInitiated(int page_id
,
87 bool did_create_new_entry
,
90 // With the current navigation logic this method is a no-op.
91 // PlzNavigate: this method simulates receiving a BeginNavigation IPC.
92 void SendRendererInitiatedNavigationRequest(const GURL
& url
,
93 bool has_user_gesture
);
95 void DidDisownOpener();
97 // If set, navigations will appear to have cleared the history list in the
99 // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared).
101 void set_simulate_history_list_was_cleared(bool cleared
) {
102 simulate_history_list_was_cleared_
= cleared
;
105 // Advances the RenderFrameHost (and through it the RenderFrameHostManager) to
106 // a state where a new navigation can be committed by a renderer. Currently,
107 // this simulates a BeforeUnload ACK from the renderer.
108 // PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the
109 // interaction with the IO thread up until the response is ready to commit.
110 void PrepareForCommit();
112 // This method does the same as PrepareForCommit.
113 // PlzNavigate: Beyond doing the same as PrepareForCommit, this method will
114 // also simulate a server redirect to |redirect_url|. If the URL is empty the
115 // redirect step is ignored.
116 void PrepareForCommitWithServerRedirect(const GURL
& redirect_url
);
119 void set_pending_commit(bool pending
) { pending_commit_
= pending
; }
120 bool pending_commit() const { return pending_commit_
; }
123 void SendNavigateWithParameters(int page_id
,
125 bool did_create_new_entry
,
127 ui::PageTransition transition
,
129 const ModificationCallback
& callback
);
131 TestRenderFrameHostCreationObserver child_creation_observer_
;
133 std::string contents_mime_type_
;
135 // See set_simulate_history_list_was_cleared() above.
136 bool simulate_history_list_was_cleared_
;
138 DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost
);
141 } // namespace content
143 #endif // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_