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

Unified 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: Addressed Nasko's comments 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 side-by-side diff with in-line comments
Download patch
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 3e568e17dd3e1ada56aa5de0070e43cdf358d698..2aec3357d7e6ad7d0285663e8543daf5c4de2853 100644
--- a/content/test/test_render_frame_host.cc
+++ b/content/test/test_render_frame_host.cc
@@ -4,9 +4,16 @@
#include "content/test/test_render_frame_host.h"
+#include "base/command_line.h"
#include "content/browser/frame_host/frame_tree.h"
+#include "content/browser/frame_host/navigation_request.h"
+#include "content/browser/frame_host/navigator.h"
+#include "content/browser/frame_host/navigator_impl.h"
#include "content/browser/frame_host/render_frame_host_delegate.h"
-#include "content/common/frame_messages.h"
+#include "content/public/browser/stream_handle.h"
+#include "content/public/common/content_switches.h"
+#include "content/test/browser_side_navigation_test_utils.h"
+#include "content/test/test_navigation_url_loader.h"
#include "content/test/test_render_view_host.h"
#include "net/base/load_flags.h"
#include "third_party/WebKit/public/web/WebPageVisibilityState.h"
@@ -118,6 +125,12 @@ void TestRenderFrameHost::SendNavigateWithFile(
void TestRenderFrameHost::SendNavigateWithParams(
FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
+ // PlzNavigate
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ PrepareForCommit(params->url);
nasko 2014/12/17 19:55:38 Do we only need to do this in PlzNavigate and not
clamy 2014/12/18 13:54:42 I think so. The tests call SendBeforeUnloadACK exp
nasko 2014/12/18 15:53:34 Why not eliminate all calls to SendBeforeUnloadACK
clamy 2014/12/19 14:39:33 Done.
+ }
+
FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params);
OnDidCommitProvisionalLoad(msg);
}
@@ -138,6 +151,12 @@ void TestRenderFrameHost::SendNavigateWithParameters(
int response_code,
const base::FilePath* file_path_for_history_item,
const std::vector<GURL>& redirects) {
+ // PlzNavigate
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ PrepareForCommit(url);
+ }
+
FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.page_id = page_id;
params.url = url;
@@ -190,4 +209,61 @@ void TestRenderFrameHost::DidDisownOpener() {
OnDidDisownOpener();
}
+void TestRenderFrameHost::SendRendererResponseToNavigation(bool proceed,
nasko 2014/12/17 19:55:38 What's the difference between this method and Prep
clamy 2014/12/18 13:54:42 In PlzNavigate, this function gets the NavigationR
nasko 2014/12/18 15:53:34 I think the only call to SendRendererResponseToNav
clamy 2014/12/19 14:39:33 Done.
+ const GURL& url) {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ // PlzNavigate: if we are waiting for the renderer, send its response to the
+ // navigation request (if there was no live renderer at request time, then
+ // the request has already been sent to the IO thread).
+ NavigationRequest* request =
+ static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
+ ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
+ ASSERT_TRUE(request);
+ if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
+ SendBeginNavigationWithURL(url);
+ } else {
+ SendBeforeUnloadACK(proceed);
+ }
+}
+
+void TestRenderFrameHost::PrepareForCommit(const GURL& url) {
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ 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_);
+
+ // We are simulating a renderer-initiated navigation.
+ if (!request) {
+ SendBeginNavigationWithURL(url);
+ 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.
+ if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
+ SendBeginNavigationWithURL(url);
+
+ // We have already simulated the IO thread commit. Only the
+ // DidCommitProvisionalLoad from the renderer is missing.
+ if (request->state() == NavigationRequest::RESPONSE_STARTED)
+ return;
+
+ ASSERT_TRUE(request->state() == NavigationRequest::STARTED);
+ TestNavigationURLLoader* url_loader =
+ static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
+ ASSERT_TRUE(url_loader);
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ url_loader->CallOnResponseStarted(response, MakeEmptyStream());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698