OLD | NEW |
---|---|
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 "base/command_line.h" |
8 #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" | 9 #include "content/browser/frame_host/navigation_request.h" |
10 #include "content/browser/frame_host/navigator.h" | 10 #include "content/browser/frame_host/navigator.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 params.page_state = PageState::CreateForTesting( | 193 params.page_state = PageState::CreateForTesting( |
194 url, | 194 url, |
195 false, | 195 false, |
196 file_path_for_history_item ? "data" : NULL, | 196 file_path_for_history_item ? "data" : NULL, |
197 file_path_for_history_item); | 197 file_path_for_history_item); |
198 | 198 |
199 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); | 199 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); |
200 OnDidCommitProvisionalLoad(msg); | 200 OnDidCommitProvisionalLoad(msg); |
201 } | 201 } |
202 | 202 |
203 void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url, | 203 void TestRenderFrameHost::SendRendererInitiatedNavigationRequest( |
204 bool has_user_gesture) { | 204 const GURL& url, |
205 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, | 205 bool has_user_gesture) { |
206 has_user_gesture); | 206 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
207 CommonNavigationParams common_params; | 207 switches::kEnableBrowserSideNavigation)) { |
208 common_params.url = url; | 208 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, |
209 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); | 209 has_user_gesture); |
210 common_params.transition = ui::PAGE_TRANSITION_LINK; | 210 CommonNavigationParams common_params; |
211 OnBeginNavigation(common_params, begin_params, | 211 common_params.url = url; |
212 scoped_refptr<ResourceRequestBody>()); | 212 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); |
213 common_params.transition = ui::PAGE_TRANSITION_LINK; | |
214 OnBeginNavigation(common_params, begin_params, | |
215 scoped_refptr<ResourceRequestBody>()); | |
216 } | |
213 } | 217 } |
214 | 218 |
215 void TestRenderFrameHost::DidDisownOpener() { | 219 void TestRenderFrameHost::DidDisownOpener() { |
216 OnDidDisownOpener(); | 220 OnDidDisownOpener(); |
217 } | 221 } |
218 | 222 |
219 void TestRenderFrameHost::PrepareForCommit(const GURL& url) { | 223 void TestRenderFrameHost::PrepareForCommit() { |
220 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 224 PrepareForCommitInternal(nullptr); |
221 switches::kEnableBrowserSideNavigation)) { | 225 } |
222 SendBeforeUnloadACK(true); | |
223 return; | |
224 } | |
225 | 226 |
226 // PlzNavigate | 227 void TestRenderFrameHost::PrepareForCommitWithServerRedirect( |
227 // Simulate the network stack commit without any redirects. | 228 const GURL& redirect_url) { |
228 NavigationRequest* request = | 229 PrepareForCommitInternal(&redirect_url); |
229 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
230 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
231 | |
232 // We are simulating a renderer-initiated user-initiated navigation. | |
233 if (!request) { | |
234 SendBeginNavigationWithURL(url, true); | |
235 request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
236 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
237 } | |
238 ASSERT_TRUE(request); | |
239 | |
240 // We may not have simulated the renderer response to the navigation request. | |
241 // Do that now. | |
242 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | |
243 SendBeforeUnloadACK(true); | |
244 | |
245 // We have already simulated the IO thread commit. Only the | |
246 // DidCommitProvisionalLoad from the renderer is missing. | |
247 if (request->state() == NavigationRequest::RESPONSE_STARTED) | |
248 return; | |
249 | |
250 ASSERT_TRUE(request->state() == NavigationRequest::STARTED); | |
251 TestNavigationURLLoader* url_loader = | |
252 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
253 ASSERT_TRUE(url_loader); | |
254 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
255 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | |
256 } | 230 } |
257 | 231 |
258 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { | 232 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { |
259 OnBeforeUnloadHandlersPresent(present); | 233 OnBeforeUnloadHandlersPresent(present); |
260 } | 234 } |
261 | 235 |
262 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { | 236 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { |
263 OnUnloadHandlersPresent(present); | 237 OnUnloadHandlersPresent(present); |
264 } | 238 } |
265 | 239 |
240 void TestRenderFrameHost::PrepareForCommitInternal(const GURL* redirect_url) { | |
241 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
242 switches::kEnableBrowserSideNavigation)) { | |
243 // Non PlzNavigate | |
244 SendBeforeUnloadACK(true); | |
245 return; | |
246 } | |
247 | |
248 // PlzNavigate | |
249 NavigationRequest* request = | |
250 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
251 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
252 CHECK(request); | |
253 | |
254 // Simulate a beforeUnload ACK from the renderer if the browser is waiting for | |
255 // it. | |
256 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | |
257 SendBeforeUnloadACK(true); | |
258 | |
259 // We have already simulated the IO thread commit. Only the | |
nasko
2015/02/26 01:27:42
This comment is confusing. Commit doesn't happen u
carlosk
2015/02/26 11:03:45
Yes, this was/is in the wrong place. I'm moving it
| |
260 // DidCommitProvisionalLoad from the renderer is missing. | |
261 if (request->state() == NavigationRequest::RESPONSE_STARTED) { | |
262 // If a server redirect was requested, the response to the navigation | |
263 // request should not have started. | |
264 CHECK(!redirect_url); | |
265 return; | |
266 } | |
267 | |
268 CHECK(request->state() == NavigationRequest::STARTED); | |
269 | |
270 TestNavigationURLLoader* url_loader = | |
271 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
272 CHECK(url_loader); | |
273 | |
274 // If a |redirect_url| was provided, simulate a server redirect | |
275 if (redirect_url) | |
276 url_loader->SimulateServerRedirect(*redirect_url); | |
277 | |
278 // Simulate the network stack commit | |
279 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
280 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | |
nasko
2015/02/26 01:27:42
This technically will commit, right? Does it belon
carlosk
2015/02/26 11:03:45
Yes, see the reply to your comment in navigation_c
| |
281 } | |
282 | |
266 } // namespace content | 283 } // namespace content |
OLD | NEW |