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

Unified Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 379143002: PlzNavigate: implement RequestNavigation in the no live renderer case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Charlie's comments Created 6 years, 4 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
Index: content/browser/frame_host/render_frame_host_manager_unittest.cc
diff --git a/content/browser/frame_host/render_frame_host_manager_unittest.cc b/content/browser/frame_host/render_frame_host_manager_unittest.cc
index 1a76c36d7c2a5e52d7b4df37ffbd402b8a628183..b7b2eb1f840e3a3f3e472a0eed926417f0b891b9 100644
--- a/content/browser/frame_host/render_frame_host_manager_unittest.cc
+++ b/content/browser/frame_host/render_frame_host_manager_unittest.cc
@@ -2,13 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#include "content/browser/frame_host/cross_site_transferring_request.h"
+#include "content/browser/frame_host/navigation_before_commit_info.h"
#include "content/browser/frame_host/navigation_controller_impl.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/frame_host/render_frame_host_manager.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/webui/web_ui_controller_factory_registry.h"
@@ -23,6 +27,7 @@
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/common/bindings_policy.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/javascript_message_type.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/common/url_constants.h"
@@ -363,11 +368,15 @@ class RenderFrameHostManagerTest
return ntp_rvh;
}
- NavigationRequest* NavigationRequestForRenderFrameManager(
+ NavigationRequest* GetNavigationRequestForRenderFrameManager(
RenderFrameHostManager* manager) const {
return manager->navigation_request_for_testing();
}
+ void EnableBrowserSideNavigation() {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableBrowserSideNavigation);
+ }
private:
RenderFrameHostManagerTestWebUIControllerFactory factory_;
scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_;
@@ -1850,18 +1859,21 @@ TEST_F(RenderFrameHostManagerTest,
}
}
-// Browser-side navigation: Test that a proper NavigationRequest is created by
+// PlzNavigate: Test that a proper NavigationRequest is created by
// BeginNavigation.
TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
const GURL kUrl1("http://www.google.com/");
const GURL kUrl2("http://www.chromium.org/");
const GURL kUrl3("http://www.gmail.com/");
+ // TODO(clamy): we should be enabling browser side navigations here
+ // when CommitNavigation is properly implemented.
// Navigate to the first page.
contents()->NavigateAndCommit(kUrl1);
TestRenderViewHost* rvh1 = test_rvh();
EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
+ EnableBrowserSideNavigation();
// Add a subframe.
TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
contents()->GetFrameTree()->AddFrame(
@@ -1870,7 +1882,7 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
// Simulate a BeginNavigation IPC on the subframe.
subframe_rfh->SendBeginNavigationWithURL(kUrl2);
NavigationRequest* subframe_request =
- NavigationRequestForRenderFrameManager(
+ GetNavigationRequestForRenderFrameManager(
subframe_rfh->frame_tree_node()->render_manager());
ASSERT_TRUE(subframe_request);
EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url);
@@ -1883,7 +1895,7 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
// Simulate a BeginNavigation IPC on the main frame.
main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
NavigationRequest* main_request =
- NavigationRequestForRenderFrameManager(
+ GetNavigationRequestForRenderFrameManager(
main_test_rfh()->frame_tree_node()->render_manager());
ASSERT_TRUE(main_request);
EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url);
@@ -1892,4 +1904,68 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame);
}
+// PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
+// RenderFrameHost is not modified when the navigation commits.
+TEST_F(RenderFrameHostManagerTest,
+ BrowserSideNavigationRequestNavigationNoLiveRenderer) {
+ const GURL kUrl("http://www.google.com/");
+
+ EnableBrowserSideNavigation();
+ EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
+ contents()->GetController().LoadURL(
+ kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
+ NavigationRequest* main_request =
+ GetNavigationRequestForRenderFrameManager(
+ main_test_rfh()->frame_tree_node()->render_manager());
nasko 2014/08/13 00:08:00 nit: two more spaces for indent
clamy 2014/08/13 13:27:24 Done.
+ // A NavigationRequest should have been generated.
+ EXPECT_TRUE(main_request != NULL);
+ RenderFrameHostImpl* rfh = main_test_rfh();
+
+ // Now commit the same url.
+ NavigationBeforeCommitInfo commit_info;
+ commit_info.navigation_url = kUrl;
+ main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
+ commit_info);
+ main_request = GetNavigationRequestForRenderFrameManager(
+ main_test_rfh()->frame_tree_node()->render_manager());
nasko 2014/08/13 00:08:00 nit: main_test_rfh()->frame_tree_node()->render_ma
clamy 2014/08/13 13:27:24 Done.
+
+ // The main rfh should not have been changed and we should not have a
nasko 2014/08/13 00:08:00 nit: capitalize rfh
clamy 2014/08/13 13:27:24 Done.
+ // navigation request anymore.
+ EXPECT_EQ(rfh, main_test_rfh());
+ EXPECT_TRUE(main_request == NULL);
+}
+
+// PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
+// site navigation.
+TEST_F(RenderFrameHostManagerTest,
+ BrowserSideNavigationCrossSiteNavigation) {
+ const GURL kUrl1("http://www.chromium.org/");
+ const GURL kUrl2("http://www.google.com/");
+
+ // TODO(clamy): we should be enabling browser side navigations here
+ // when CommitNavigation is properly implemented.
+ // Navigate to the first page.
+ contents()->NavigateAndCommit(kUrl1);
+ TestRenderViewHost* rvh1 = test_rvh();
+ EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
+ RenderFrameHostImpl* rfh = main_test_rfh();
+
+ EnableBrowserSideNavigation();
+ // Navigate to a different site.
+ main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
+ NavigationRequest* main_request =
+ GetNavigationRequestForRenderFrameManager(
+ main_test_rfh()->frame_tree_node()->render_manager());
+ ASSERT_TRUE(main_request);
+
+ NavigationBeforeCommitInfo commit_info;
+ commit_info.navigation_url = kUrl2;
+ main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
+ commit_info);
+ main_request = GetNavigationRequestForRenderFrameManager(
+ main_test_rfh()->frame_tree_node()->render_manager());
+ EXPECT_NE(main_test_rfh(), rfh);
+ EXPECT_TRUE(main_request == NULL);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698