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

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

Issue 953503002: PlzNavigate: test updates post beforeUnload IPC refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase with small adaptation to support data URLs. Created 5 years, 9 months 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
« no previous file with comments | « content/test/test_render_frame_host.h ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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() {
224 PrepareForCommitWithServerRedirect(GURL());
225 }
226
227 void TestRenderFrameHost::PrepareForCommitWithServerRedirect(
228 const GURL& redirect_url) {
220 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 229 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
221 switches::kEnableBrowserSideNavigation)) { 230 switches::kEnableBrowserSideNavigation)) {
231 // Non PlzNavigate
222 SendBeforeUnloadACK(true); 232 SendBeforeUnloadACK(true);
223 return; 233 return;
224 } 234 }
225 235
226 // PlzNavigate 236 // PlzNavigate
227 // Simulate the network stack commit without any redirects.
228 NavigationRequest* request = 237 NavigationRequest* request =
229 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) 238 static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
230 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); 239 ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
240 CHECK(request);
231 241
232 // We are simulating a renderer-initiated user-initiated navigation. 242 // Simulate a beforeUnload ACK from the renderer if the browser is waiting for
233 if (!request) { 243 // it. If it runs it will update the request state.
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) 244 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
243 SendBeforeUnloadACK(true); 245 SendBeforeUnloadACK(true);
244 246
245 // We have already simulated the IO thread commit. Only the 247 // If a network request is not needed for this URL,
clamy 2015/03/03 12:47:23 Please finish this comment :).
carlosk 2015/03/03 13:46:58 Done.
246 // DidCommitProvisionalLoad from the renderer is missing. 248 if (!request->ShouldMakeNetworkRequest(request->common_params().url)) {
247 if (request->state() == NavigationRequest::RESPONSE_STARTED) 249 CHECK(request->state() == NavigationRequest::RESPONSE_STARTED);
248 return; 250 return;
251 }
249 252
250 ASSERT_TRUE(request->state() == NavigationRequest::STARTED); 253 CHECK(request->state() == NavigationRequest::STARTED);
254
251 TestNavigationURLLoader* url_loader = 255 TestNavigationURLLoader* url_loader =
252 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); 256 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
253 ASSERT_TRUE(url_loader); 257 CHECK(url_loader);
258
259 // If a non-empty |redirect_url| was provided, simulate a server redirect
260 if (!redirect_url.is_empty())
261 url_loader->SimulateServerRedirect(redirect_url);
262
263 // Simulate the network stack commit
254 scoped_refptr<ResourceResponse> response(new ResourceResponse); 264 scoped_refptr<ResourceResponse> response(new ResourceResponse);
265 // TODO(carlosk): ideally with PlzNavigate it should be possible someday to
266 // fully commit the navigation at this call to CallOnResponseStarted.
255 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); 267 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
256 } 268 }
257 269
258 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { 270 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) {
259 OnBeforeUnloadHandlersPresent(present); 271 OnBeforeUnloadHandlersPresent(present);
260 } 272 }
261 273
262 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { 274 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) {
263 OnUnloadHandlersPresent(present); 275 OnUnloadHandlersPresent(present);
264 } 276 }
265 277
266 } // namespace content 278 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_render_frame_host.h ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698