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

Unified 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: Minor comment updates. Created 5 years, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/test_render_frame_host.cc
diff --git a/content/test/test_render_frame_host.cc b/content/test/test_render_frame_host.cc
index 988681c5e04102aa575b5ce7bb88d64e62d5c034..6ef20c1d63e523112db6bcd5088a8b84af5fcdd3 100644
--- a/content/test/test_render_frame_host.cc
+++ b/content/test/test_render_frame_host.cc
@@ -200,58 +200,71 @@ void TestRenderFrameHost::SendNavigateWithParameters(
OnDidCommitProvisionalLoad(msg);
}
-void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url,
- bool has_user_gesture) {
- BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL,
- has_user_gesture);
- CommonNavigationParams common_params;
- common_params.url = url;
- common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault);
- common_params.transition = ui::PAGE_TRANSITION_LINK;
- OnBeginNavigation(common_params, begin_params,
- scoped_refptr<ResourceRequestBody>());
+void TestRenderFrameHost::SendRendererInitiatedNavigationRequest(
+ const GURL& url,
+ bool has_user_gesture) {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL,
+ has_user_gesture);
+ CommonNavigationParams common_params;
+ common_params.url = url;
+ common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault);
+ common_params.transition = ui::PAGE_TRANSITION_LINK;
+ OnBeginNavigation(common_params, begin_params,
+ scoped_refptr<ResourceRequestBody>());
+ }
}
void TestRenderFrameHost::DidDisownOpener() {
OnDidDisownOpener();
}
-void TestRenderFrameHost::PrepareForCommit(const GURL& url) {
+void TestRenderFrameHost::PrepareForCommit() {
+ PrepareForCommitWithServerRedirect(GURL());
+}
+
+void TestRenderFrameHost::PrepareForCommitWithServerRedirect(
+ const GURL& redirect_url) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation)) {
+ // Non PlzNavigate
SendBeforeUnloadACK(true);
return;
}
// PlzNavigate
- // Simulate the network stack commit without any redirects.
NavigationRequest* request =
static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node_);
+ CHECK(request);
- // We are simulating a renderer-initiated user-initiated navigation.
- if (!request) {
- SendBeginNavigationWithURL(url, true);
- request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
- ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
- }
- ASSERT_TRUE(request);
-
- // We may not have simulated the renderer response to the navigation request.
- // Do that now.
+ // Simulate a beforeUnload ACK from the renderer if the browser is waiting for
+ // it. If it runs it will update the request state.
if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
SendBeforeUnloadACK(true);
- // We have already simulated the IO thread commit. Only the
- // DidCommitProvisionalLoad from the renderer is missing.
- if (request->state() == NavigationRequest::RESPONSE_STARTED)
+ // If a network request is not needed for this URL, just check the request is
+ // in the correct state and return.
+ if (!request->ShouldMakeNetworkRequest(request->common_params().url)) {
+ CHECK(request->state() == NavigationRequest::RESPONSE_STARTED);
return;
+ }
+
+ CHECK(request->state() == NavigationRequest::STARTED);
- ASSERT_TRUE(request->state() == NavigationRequest::STARTED);
TestNavigationURLLoader* url_loader =
static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
- ASSERT_TRUE(url_loader);
+ CHECK(url_loader);
+
+ // If a non-empty |redirect_url| was provided, simulate a server redirect.
+ if (!redirect_url.is_empty())
+ url_loader->SimulateServerRedirect(redirect_url);
+
+ // Simulate the network stack commit.
scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ // TODO(carlosk): ideally with PlzNavigate it should be possible someday to
+ // fully commit the navigation at this call to CallOnResponseStarted.
url_loader->CallOnResponseStarted(response, MakeEmptyStream());
}
« 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