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

Unified Diff: content/browser/frame_host/navigation_controller_impl_unittest.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: 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
« no previous file with comments | « no previous file | content/test/test_web_contents.h » ('j') | content/test/test_web_contents.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigation_controller_impl_unittest.cc
diff --git a/content/browser/frame_host/navigation_controller_impl_unittest.cc b/content/browser/frame_host/navigation_controller_impl_unittest.cc
index 0ca6ae59ea2ee50b04e417da156d51d974589360..d0961924440cebc6523e9789c5d7f68a9ae0262c 100644
--- a/content/browser/frame_host/navigation_controller_impl_unittest.cc
+++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc
@@ -4,6 +4,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
@@ -25,6 +26,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/page_state.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/mock_render_process_host.h"
@@ -374,7 +376,7 @@ TEST_F(NavigationControllerTest, LoadURL) {
// We should have gotten no notifications from the preceeding checks.
EXPECT_EQ(0U, notifications.size());
- main_test_rfh()->SendNavigate(0, url1);
+ contents()->CommitNavigationWithPageID(0, url1, false);
nasko 2014/12/11 00:51:45 Why do we have false in this case?
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
@@ -414,8 +416,7 @@ TEST_F(NavigationControllerTest, LoadURL) {
// Simulate the beforeunload ack for the cross-site transition, and then the
// commit.
- main_test_rfh()->SendBeforeUnloadACK(true);
- contents()->GetPendingMainFrame()->SendNavigate(1, url2);
+ contents()->CommitNavigationWithPageID(1, url2, true);
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
@@ -741,7 +742,7 @@ TEST_F(NavigationControllerTest, LoadURL_NewPending) {
const GURL kExistingURL1("http://eh");
controller.LoadURL(
kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
- main_test_rfh()->SendNavigate(0, kExistingURL1);
+ contents()->CommitPendingNavigation();
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
@@ -752,9 +753,9 @@ TEST_F(NavigationControllerTest, LoadURL_NewPending) {
EXPECT_EQ(0U, notifications.size());
// After the beforeunload but before it commits, do a new navigation.
- main_test_rfh()->SendBeforeUnloadACK(true);
+ contents()->ProceedNavigationWithRendererResponse(kExistingURL2);
const GURL kNewURL("http://see");
- contents()->GetPendingMainFrame()->SendNavigate(3, kNewURL);
+ contents()->SimulateRendererInitiatedNavigation(3, kNewURL);
// There should no longer be any pending entry, and the third navigation we
// just made should be committed.
@@ -822,8 +823,7 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
controller.LoadURL(
kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
// Pretend it has bindings so we can tell if we incorrectly copy it.
- main_test_rfh()->GetRenderViewHost()->AllowBindings(2);
- main_test_rfh()->SendNavigate(0, kExistingURL1);
+ contents()->CommitPendingNavigationWithBindings(2, false);
nasko 2014/12/11 00:51:45 As I'm reading through these changes, it seems lik
clamy 2014/12/15 17:01:39 Done.
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
@@ -831,16 +831,14 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
const GURL kExistingURL2("http://foo/eh");
controller.LoadURL(
kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
- main_test_rfh()->SendBeforeUnloadACK(true);
- TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame();
- foo_rfh->SendNavigate(1, kExistingURL2);
+ contents()->CommitPendingNavigation();
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
// Now make a pending back/forward navigation to a privileged entry.
// The zeroth entry should be pending.
controller.GoBack();
- foo_rfh->SendBeforeUnloadACK(true);
+ contents()->ProceedNavigationWithRendererResponse(kExistingURL1);
EXPECT_EQ(0U, notifications.size());
EXPECT_EQ(0, controller.GetPendingEntryIndex());
EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
@@ -850,7 +848,7 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
// Before that commits, do a new navigation.
const GURL kNewURL("http://foo/bee");
LoadCommittedDetails details;
- foo_rfh->SendNavigate(3, kNewURL);
+ contents()->SimulateRendererInitiatedNavigation(3, kNewURL);
// There should no longer be any pending entry, and the third navigation we
// just made should be committed.
@@ -1085,7 +1083,7 @@ TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
// Commit.
TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
- orig_rfh->SendNavigate(0, url1);
+ contents()->CommitPendingNavigationNoLiveRenderer();
EXPECT_EQ(controller.GetEntryCount(), 1);
EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
@@ -1102,10 +1100,7 @@ TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
// privileged url.
controller.LoadURL(
url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
- orig_rfh->SendBeforeUnloadACK(true);
- TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame();
- new_rfh->GetRenderViewHost()->AllowBindings(1);
- new_rfh->SendNavigate(1, url2);
+ contents()->CommitPendingNavigationWithBindings(1, true);
// The second load should be committed, and bindings should be remembered.
EXPECT_EQ(controller.GetEntryCount(), 2);
@@ -1116,8 +1111,7 @@ TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
// Going back, the first entry should still appear unprivileged.
controller.GoBack();
- new_rfh->SendBeforeUnloadACK(true);
- orig_rfh->SendNavigate(0, url1);
+ contents()->CommitPendingNavigation();
EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
controller.GetLastCommittedEntry())->bindings());
@@ -3878,7 +3872,7 @@ TEST_F(NavigationControllerTest, CopyRestoredStateAndNavigate) {
&entries);
ASSERT_EQ(0u, entries.size());
source_controller.LoadIfNecessary();
- source_contents->CommitPendingNavigation();
+ source_contents->CommitPendingNavigationNoLiveRenderer();
// Load a page, then copy state from |source_contents|.
NavigateAndCommit(kInitialUrl);
@@ -3917,20 +3911,33 @@ TEST_F(NavigationControllerTest, HistoryNavigate) {
NavigateAndCommit(url3);
controller.GoBack();
contents()->CommitPendingNavigation();
+ process()->sink().ClearMessages();
// Simulate the page calling history.back(). It should create a pending entry.
contents()->OnGoToEntryAtOffset(-1);
EXPECT_EQ(0, controller.GetPendingEntryIndex());
// The actual cross-navigation is suspended until the current RVH tells us
// it unloaded, simulate that.
- contents()->ProceedWithCrossSiteNavigation();
+ contents()->ProceedNavigationWithRendererResponse(url1);
// Also make sure we told the page to navigate.
- const IPC::Message* message =
- process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
- ASSERT_TRUE(message != NULL);
- Tuple1<FrameMsg_Navigate_Params> nav_params;
- FrameMsg_Navigate::Read(message, &nav_params);
- EXPECT_EQ(url1, nav_params.a.common_params.url);
+ GURL nav_url;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ const IPC::Message* message = process()->sink().GetFirstMessageMatching(
+ FrameMsg_RequestNavigation::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple2<CommonNavigationParams, RequestNavigationParams> nav_params;
+ FrameMsg_RequestNavigation::Read(message, &nav_params);
+ nav_url = nav_params.a.url;
+ } else {
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple1<FrameMsg_Navigate_Params> nav_params;
+ FrameMsg_Navigate::Read(message, &nav_params);
+ nav_url = nav_params.a.common_params.url;
+ }
+ EXPECT_EQ(url1, nav_url);
process()->sink().ClearMessages();
// Now test history.forward()
@@ -3938,11 +3945,24 @@ TEST_F(NavigationControllerTest, HistoryNavigate) {
EXPECT_EQ(2, controller.GetPendingEntryIndex());
// The actual cross-navigation is suspended until the current RVH tells us
// it unloaded, simulate that.
- contents()->ProceedWithCrossSiteNavigation();
- message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
- ASSERT_TRUE(message != NULL);
- FrameMsg_Navigate::Read(message, &nav_params);
- EXPECT_EQ(url3, nav_params.a.common_params.url);
+ contents()->ProceedNavigationWithRendererResponse(url3);
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ const IPC::Message* message = process()->sink().GetFirstMessageMatching(
+ FrameMsg_RequestNavigation::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple2<CommonNavigationParams, RequestNavigationParams> nav_params;
+ FrameMsg_RequestNavigation::Read(message, &nav_params);
+ nav_url = nav_params.a.url;
+ } else {
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple1<FrameMsg_Navigate_Params> nav_params;
+ FrameMsg_Navigate::Read(message, &nav_params);
+ nav_url = nav_params.a.common_params.url;
+ }
+ EXPECT_EQ(url3, nav_url);
process()->sink().ClearMessages();
controller.DiscardNonCommittedEntries();
@@ -3950,8 +3970,16 @@ TEST_F(NavigationControllerTest, HistoryNavigate) {
// Make sure an extravagant history.go() doesn't break.
contents()->OnGoToEntryAtOffset(120); // Out of bounds.
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
- message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
- EXPECT_TRUE(message == NULL);
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation)) {
+ const IPC::Message* message = process()->sink().GetFirstMessageMatching(
+ FrameMsg_RequestNavigation::ID);
+ EXPECT_TRUE(message == NULL);
+ } else {
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
+ EXPECT_TRUE(message == NULL);
+ }
}
// Test call to PruneAllButLastCommitted for the only entry.
@@ -4344,9 +4372,7 @@ TEST_F(NavigationControllerTest, ClearHistoryList) {
EXPECT_TRUE(entry->should_clear_history_list());
// Assume that the RF correctly cleared its history and commit the navigation.
- contents()->GetPendingMainFrame()->
- set_simulate_history_list_was_cleared(true);
- contents()->CommitPendingNavigation();
+ contents()->CommitPendingNavigationWithHistoryCleared(true, true);
// Verify that the NavigationController's session history was correctly
// cleared.
« no previous file with comments | « no previous file | content/test/test_web_contents.h » ('j') | content/test/test_web_contents.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698