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 TestRenderFrameHost
* AppendChild(const std::string
& frame_name
) override
;
55 void SendNavigate(int page_id
,
57 bool did_create_new_entry
,
58 const GURL
& url
) override
;
59 void SendFailedNavigate(int page_id
,
61 bool did_create_new_entry
,
62 const GURL
& url
) override
;
63 void SendNavigateWithTransition(int page_id
,
65 bool did_create_new_entry
,
67 ui::PageTransition transition
) override
;
68 void SetContentsMimeType(const std::string
& mime_type
) override
;
69 void SendBeforeUnloadACK(bool proceed
) override
;
70 void SimulateSwapOutACK() override
;
72 void SendNavigateWithTransitionAndResponseCode(int page_id
,
74 bool did_create_new_entry
,
76 ui::PageTransition transition
,
78 void SendNavigateWithOriginalRequestURL(int page_id
,
80 bool did_create_new_entry
,
82 const GURL
& original_request_url
);
83 void SendNavigateWithFile(int page_id
,
85 bool did_create_new_entry
,
87 const base::FilePath
& file_path
);
88 void SendNavigateWithParams(
89 FrameHostMsg_DidCommitProvisionalLoad_Params
* params
);
90 void SendNavigateWithRedirects(int page_id
,
92 bool did_create_new_entry
,
94 const std::vector
<GURL
>& redirects
);
95 void SendNavigateWithParameters(
98 bool did_create_new_entry
,
100 ui::PageTransition transition
,
101 const GURL
& original_request_url
,
103 const base::FilePath
* file_path_for_history_item
,
104 const std::vector
<GURL
>& redirects
);
106 // Simulate a renderer-initiated navigation up until commit.
107 void NavigateAndCommitRendererInitiated(int page_id
,
108 bool did_create_new_entry
,
111 // With the current navigation logic this method is a no-op.
112 // PlzNavigate: this method simulates receiving a BeginNavigation IPC.
113 void SendRendererInitiatedNavigationRequest(const GURL
& url
,
114 bool has_user_gesture
);
116 void DidDisownOpener();
118 // If set, navigations will appear to have cleared the history list in the
120 // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared).
122 void set_simulate_history_list_was_cleared(bool cleared
) {
123 simulate_history_list_was_cleared_
= cleared
;
126 // Advances the RenderFrameHost (and through it the RenderFrameHostManager) to
127 // a state where a new navigation can be committed by a renderer. Currently,
128 // this simulates a BeforeUnload ACK from the renderer.
129 // PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the
130 // interaction with the IO thread up until the response is ready to commit.
131 void PrepareForCommit();
133 // This method does the same as PrepareForCommit.
134 // PlzNavigate: Beyond doing the same as PrepareForCommit, this method will
135 // also simulate a server redirect to |redirect_url|. If the URL is empty the
136 // redirect step is ignored.
137 void PrepareForCommitWithServerRedirect(const GURL
& redirect_url
);
140 void set_pending_commit(bool pending
) { pending_commit_
= pending
; }
141 bool pending_commit() const { return pending_commit_
; }
144 TestRenderFrameHostCreationObserver child_creation_observer_
;
146 std::string contents_mime_type_
;
148 // See set_simulate_history_list_was_cleared() above.
149 bool simulate_history_list_was_cleared_
;
151 DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost
);
154 } // namespace content
156 #endif // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_