Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: content/test/test_render_frame_host.cc

Issue 761013003: PlzNavigate: add support in several navigation controller unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved the functions to the TestRenderFrameHost Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/test/test_render_frame_host.h" 5 #include "content/test/test_render_frame_host.h"
6 6
7 #include "base/command_line.h"
7 #include "content/browser/frame_host/frame_tree.h" 8 #include "content/browser/frame_host/frame_tree.h"
9 #include "content/browser/frame_host/navigation_request.h"
10 #include "content/browser/frame_host/navigator.h"
11 #include "content/browser/frame_host/navigator_impl.h"
8 #include "content/browser/frame_host/render_frame_host_delegate.h" 12 #include "content/browser/frame_host/render_frame_host_delegate.h"
9 #include "content/common/frame_messages.h" 13 #include "content/public/browser/stream_handle.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/test/browser_side_navigation_test_utils.h"
16 #include "content/test/test_navigation_url_loader.h"
10 #include "content/test/test_render_view_host.h" 17 #include "content/test/test_render_view_host.h"
11 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
12 #include "third_party/WebKit/public/web/WebPageVisibilityState.h" 19 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
13 #include "ui/base/page_transition_types.h" 20 #include "ui/base/page_transition_types.h"
14 21
15 namespace content { 22 namespace content {
16 23
17 TestRenderFrameHostCreationObserver::TestRenderFrameHostCreationObserver( 24 TestRenderFrameHostCreationObserver::TestRenderFrameHostCreationObserver(
18 WebContents* web_contents) 25 WebContents* web_contents)
19 : WebContentsObserver(web_contents), last_created_frame_(NULL) { 26 : WebContentsObserver(web_contents), last_created_frame_(NULL) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 void TestRenderFrameHost::SendNavigateWithFile( 118 void TestRenderFrameHost::SendNavigateWithFile(
112 int page_id, 119 int page_id,
113 const GURL& url, 120 const GURL& url,
114 const base::FilePath& file_path) { 121 const base::FilePath& file_path) {
115 SendNavigateWithParameters(page_id, url, ui::PAGE_TRANSITION_LINK, url, 200, 122 SendNavigateWithParameters(page_id, url, ui::PAGE_TRANSITION_LINK, url, 200,
116 &file_path, std::vector<GURL>()); 123 &file_path, std::vector<GURL>());
117 } 124 }
118 125
119 void TestRenderFrameHost::SendNavigateWithParams( 126 void TestRenderFrameHost::SendNavigateWithParams(
120 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { 127 FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
128 // PlzNavigate
129 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
130 switches::kEnableBrowserSideNavigation)) {
131 SimulateIOThread(params->url);
132 }
133
121 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); 134 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params);
122 OnDidCommitProvisionalLoad(msg); 135 OnDidCommitProvisionalLoad(msg);
123 } 136 }
124 137
125 void TestRenderFrameHost::SendNavigateWithRedirects( 138 void TestRenderFrameHost::SendNavigateWithRedirects(
126 int page_id, 139 int page_id,
127 const GURL& url, 140 const GURL& url,
128 const std::vector<GURL>& redirects) { 141 const std::vector<GURL>& redirects) {
129 SendNavigateWithParameters( 142 SendNavigateWithParameters(
130 page_id, url, ui::PAGE_TRANSITION_LINK, url, 200, 0, redirects); 143 page_id, url, ui::PAGE_TRANSITION_LINK, url, 200, 0, redirects);
131 } 144 }
132 145
133 void TestRenderFrameHost::SendNavigateWithParameters( 146 void TestRenderFrameHost::SendNavigateWithParameters(
134 int page_id, 147 int page_id,
135 const GURL& url, 148 const GURL& url,
136 ui::PageTransition transition, 149 ui::PageTransition transition,
137 const GURL& original_request_url, 150 const GURL& original_request_url,
138 int response_code, 151 int response_code,
139 const base::FilePath* file_path_for_history_item, 152 const base::FilePath* file_path_for_history_item,
140 const std::vector<GURL>& redirects) { 153 const std::vector<GURL>& redirects) {
154 // PlzNavigate
155 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
156 switches::kEnableBrowserSideNavigation)) {
157 SimulateIOThread(url);
158 }
159
141 FrameHostMsg_DidCommitProvisionalLoad_Params params; 160 FrameHostMsg_DidCommitProvisionalLoad_Params params;
142 params.page_id = page_id; 161 params.page_id = page_id;
143 params.url = url; 162 params.url = url;
144 params.referrer = Referrer(); 163 params.referrer = Referrer();
145 params.transition = transition; 164 params.transition = transition;
146 params.redirects = redirects; 165 params.redirects = redirects;
147 params.should_update_history = true; 166 params.should_update_history = true;
148 params.searchable_form_url = GURL(); 167 params.searchable_form_url = GURL();
149 params.searchable_form_encoding = std::string(); 168 params.searchable_form_encoding = std::string();
150 params.security_info = std::string(); 169 params.security_info = std::string();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 common_params.url = url; 202 common_params.url = url;
184 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); 203 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault);
185 common_params.transition = ui::PAGE_TRANSITION_LINK; 204 common_params.transition = ui::PAGE_TRANSITION_LINK;
186 OnBeginNavigation(begin_params, common_params); 205 OnBeginNavigation(begin_params, common_params);
187 } 206 }
188 207
189 void TestRenderFrameHost::DidDisownOpener() { 208 void TestRenderFrameHost::DidDisownOpener() {
190 OnDidDisownOpener(); 209 OnDidDisownOpener();
191 } 210 }
192 211
212 void TestRenderFrameHost::SendRendererResponseToNavigation(bool proceed,
213 const GURL& url) {
214 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
215 switches::kEnableBrowserSideNavigation)) {
216 // PlzNavigate: if there is a live renderer, send its response to the
nasko 2014/12/16 01:40:26 Is the condition "live renderer"? The check below
clamy 2014/12/17 15:47:57 Done.
217 // navigation request.
218 NavigationRequest* request =
219 static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
220 ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
221 ASSERT_TRUE(request);
222 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
223 SendBeginNavigationWithURL(url);
224 } else {
225 SendBeforeUnloadACK(proceed);
226 }
227 }
228
229 void TestRenderFrameHost::SimulateIOThread(const GURL& url) {
230 // Simulate the network stack commit without any redirects.
231 NavigationRequest* request =
232 static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
233 ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
234
235 // We are simulating a renderer-initiated navigation.
236 if (!request) {
237 SendBeginNavigationWithURL(url);
238 request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
239 ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
240 }
241 ASSERT_TRUE(request);
242
243 // We may not have simulated the renderer response to the navigation request.
244 // Do that now.
245 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
246 SendBeginNavigationWithURL(url);
247
248 // We have already simulated the IO thread commit. Only the
249 // DidCommitProvisionalLoad from the renderer is missing.
250 if (request->state() == NavigationRequest::RESPONSE_STARTED)
251 return;
252
253 ASSERT_TRUE(request->state() == NavigationRequest::STARTED);
254 TestNavigationURLLoader* url_loader =
255 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
256 ASSERT_TRUE(url_loader);
257 scoped_refptr<ResourceResponse> response(new ResourceResponse);
258 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
259 }
260
193 } // namespace content 261 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698