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

Unified Diff: content/test/test_web_contents.cc

Issue 730553002: PlzNavigate: Refactor unit test helper functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the test utils class Created 6 years, 1 month 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_navigation_url_loader_factory.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/test_web_contents.cc
diff --git a/content/test/test_web_contents.cc b/content/test/test_web_contents.cc
index f2ee15df13eecf5912deb8d52ad108142ab3f11c..5d46f61acd3f5eec56f2894790a13881cc899ebe 100644
--- a/content/test/test_web_contents.cc
+++ b/content/test/test_web_contents.cc
@@ -6,19 +6,25 @@
#include <utility>
+#include "base/command_line.h"
#include "content/browser/browser_url_handler_impl.h"
#include "content/browser/frame_host/cross_process_frame_connector.h"
#include "content/browser/frame_host/navigation_entry_impl.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/renderer_host/render_view_host_impl.h"
#include "content/browser/site_instance_impl.h"
-#include "content/common/frame_messages.h"
#include "content/common/view_messages.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/stream_handle.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/page_state.h"
#include "content/public/test/mock_render_process_host.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 "ui/base/page_transition_types.h"
@@ -123,6 +129,7 @@ WebContents* TestWebContents::Clone() {
}
void TestWebContents::NavigateAndCommit(const GURL& url) {
+ bool has_live_renderer = GetMainFrame()->IsRenderFrameLive();
GetController().LoadURL(
url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
GURL loaded_url(url);
@@ -130,6 +137,27 @@ void TestWebContents::NavigateAndCommit(const GURL& url) {
BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
&loaded_url, GetBrowserContext(), &reverse_on_redirect);
+ // PlzNavigate
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ // Simulate the renderer response if there was a live renderer when the
+ // navigation started. Otherwise, it will have been sent directly to the
+ // network stack.
+ if (has_live_renderer)
+ GetMainFrame()->SendBeginNavigationWithURL(url);
+
+ // Now simulate the network stack commit without any redirects. This will
+ // cause the navigation to commit at the same url.
+ FrameTreeNode* frame_tree_node = GetMainFrame()->frame_tree_node();
+ NavigationRequest* request =
+ static_cast<NavigatorImpl*>(frame_tree_node->navigator())
+ ->GetNavigationRequestForNodeForTesting(frame_tree_node);
+ TestNavigationURLLoader* url_loader =
+ static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ url_loader->CallOnResponseStarted(response, MakeEmptyStream());
+ }
+
// LoadURL created a navigation entry, now simulate the RenderView sending
// a notification that it actually navigated.
CommitPendingNavigation();
« no previous file with comments | « content/test/test_navigation_url_loader_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698