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

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: Comment changes. 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
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() {
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 if (request->state() == NavigationRequest::RESPONSE_STARTED) {
clamy 2015/02/26 13:17:29 All considered, I think this if clause should be r
carlosk 2015/03/02 16:35:45 Done.
260 // We have already simulated the IO thread commit. Only the
261 // DidCommitProvisionalLoad from the renderer is missing.
262
263 // If a server redirect was requested, the response to the navigation
264 // request should not have started.
265 CHECK(!redirect_url);
266
267 return;
268 }
269
270 CHECK(request->state() == NavigationRequest::STARTED);
271
272 TestNavigationURLLoader* url_loader =
273 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
274 CHECK(url_loader);
275
276 // If a |redirect_url| was provided, simulate a server redirect
277 if (redirect_url)
278 url_loader->SimulateServerRedirect(*redirect_url);
279
280 // Simulate the network stack commit
281 scoped_refptr<ResourceResponse> response(new ResourceResponse);
282 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
283 }
284
266 } // namespace content 285 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698