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

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

Issue 1309323004: Create a NavigationEntry for the initial blank page. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GetEntryCount, more tests Created 5 years, 2 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/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 4be1b1a8d392ac16a7ec41d1c5ef52ac9c496fb1..7594f289eb855d4077336e0177bc02028505b180 100644
--- a/content/browser/frame_host/navigation_controller_impl_unittest.cc
+++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc
@@ -298,11 +298,12 @@ TEST_F(NavigationControllerTest, Defaults) {
NavigationControllerImpl& controller = controller_impl();
EXPECT_FALSE(controller.GetPendingEntry());
- EXPECT_FALSE(controller.GetVisibleEntry());
- EXPECT_FALSE(controller.GetLastCommittedEntry());
+ EXPECT_TRUE(controller.IsInitialNavigation());
+ EXPECT_TRUE(controller.GetVisibleEntry());
+ EXPECT_TRUE(controller.GetLastCommittedEntry());
+ EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
+ EXPECT_EQ(controller.GetEntryCount(), 1);
EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
- EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
- EXPECT_EQ(controller.GetEntryCount(), 0);
EXPECT_FALSE(controller.CanGoBack());
EXPECT_FALSE(controller.CanGoForward());
}
@@ -388,6 +389,11 @@ TEST_F(NavigationControllerTest, LoadURL) {
const GURL url1("http://foo1");
const GURL url2("http://foo2");
+ // We start with an entry for the initial blank page.
+ EXPECT_EQ(controller.GetEntryCount(), 1);
+ EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
+ EXPECT_TRUE(controller.GetLastCommittedEntry());
+
controller.LoadURL(
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
int entry_id = controller.GetPendingEntry()->GetUniqueID();
@@ -396,10 +402,7 @@ TEST_F(NavigationControllerTest, LoadURL) {
EXPECT_EQ(0U, notifications.size());
// The load should now be pending.
- EXPECT_EQ(controller.GetEntryCount(), 0);
- EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
- EXPECT_FALSE(controller.GetLastCommittedEntry());
ASSERT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
EXPECT_FALSE(controller.CanGoBack());
@@ -418,7 +421,7 @@ TEST_F(NavigationControllerTest, LoadURL) {
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
- // The load should now be committed.
+ // The load should now be committed, replacing the initial entry.
EXPECT_EQ(controller.GetEntryCount(), 1);
EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
@@ -1008,7 +1011,8 @@ TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) {
EXPECT_EQ(0U, notifications.size());
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_TRUE(controller.GetPendingEntry());
- EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
+ EXPECT_TRUE(controller.IsInitialNavigation());
EXPECT_EQ(1, delegate->navigation_state_change_count());
// Before that commits, a document.write and location.reload can cause the
@@ -1021,7 +1025,8 @@ TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) {
// change, so that we do not keep displaying kNewURL.
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_FALSE(controller.GetPendingEntry());
- EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
+ EXPECT_TRUE(controller.IsInitialNavigation());
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation))
EXPECT_EQ(4, delegate->navigation_state_change_count());
@@ -1052,7 +1057,8 @@ TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) {
EXPECT_EQ(0U, notifications.size());
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_TRUE(controller.GetPendingEntry());
- EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
+ EXPECT_TRUE(controller.IsInitialNavigation());
EXPECT_EQ(1, delegate->navigation_state_change_count());
// It may abort before committing, if it's a download or due to a stop or
@@ -1070,7 +1076,8 @@ TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) {
// change, so that we keep displaying kNewURL (until the user clears it).
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_TRUE(controller.GetPendingEntry());
- EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
+ EXPECT_TRUE(controller.IsInitialNavigation());
EXPECT_EQ(1, delegate->navigation_state_change_count());
NavigationEntry* pending_entry = controller.GetPendingEntry();
@@ -1079,7 +1086,8 @@ TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) {
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(pending_entry, controller.GetPendingEntry());
- EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
+ EXPECT_TRUE(controller.IsInitialNavigation());
contents()->SetDelegate(NULL);
}
@@ -2646,9 +2654,9 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
}
}
-TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
+TEST_F(NavigationControllerTest, PushStateWithoutCommittedEntry)
{
- ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
+ ASSERT_TRUE(controller_impl().IsInitialNavigation());
FrameHostMsg_DidCommitProvisionalLoad_Params params;
GURL url("http://foo");
params.page_id = 1;
@@ -3396,7 +3404,10 @@ TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) {
// we must revert to showing about:blank to avoid a URL spoof.
main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0));
EXPECT_TRUE(contents()->HasAccessedInitialDocument());
- EXPECT_FALSE(controller.GetVisibleEntry());
+ EXPECT_TRUE(controller.IsInitialNavigation());
+ EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry());
+ EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry());
+ EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL());
EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
notifications.Reset();
@@ -3446,7 +3457,10 @@ TEST_F(NavigationControllerTest, ShowBrowserURLAfterFailUntilModified) {
// we must revert to showing about:blank to avoid a URL spoof.
main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0));
EXPECT_TRUE(contents()->HasAccessedInitialDocument());
- EXPECT_FALSE(controller.GetVisibleEntry());
+ EXPECT_TRUE(controller.IsInitialNavigation());
+ EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry());
+ EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry());
+ EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL());
EXPECT_FALSE(controller.GetPendingEntry());
notifications.Reset();
@@ -3494,7 +3508,10 @@ TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) {
// we must revert to showing about:blank to avoid a URL spoof.
main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0));
EXPECT_TRUE(contents()->HasAccessedInitialDocument());
- EXPECT_FALSE(controller.GetVisibleEntry());
+ EXPECT_TRUE(controller.IsInitialNavigation());
+ EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry());
+ EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry());
+ EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL());
EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
notifications.Reset();
@@ -3764,9 +3781,11 @@ TEST_F(NavigationControllerTest, LazyReload) {
// Test requesting and triggering a lazy reload without any committed entry nor
// pending entry.
+// TODO(creis): Does this test make sense anymore?
TEST_F(NavigationControllerTest, LazyReloadWithoutCommittedEntry) {
NavigationControllerImpl& controller = controller_impl();
- ASSERT_EQ(-1, controller.GetLastCommittedEntryIndex());
+ ASSERT_EQ(0, controller.GetLastCommittedEntryIndex());
+ ASSERT_TRUE(controller.IsInitialNavigation());
EXPECT_FALSE(controller.NeedsReload());
controller.SetNeedsReload();
EXPECT_TRUE(controller.NeedsReload());
@@ -4561,6 +4580,7 @@ TEST_F(NavigationControllerTest, IsInitialNavigation) {
// Initial state.
EXPECT_TRUE(controller.IsInitialNavigation());
+ EXPECT_TRUE(controller.IsInitialBlankNavigation());
// After commit, it stays false.
const GURL url1("http://foo1");
@@ -4568,11 +4588,20 @@ TEST_F(NavigationControllerTest, IsInitialNavigation) {
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
EXPECT_FALSE(controller.IsInitialNavigation());
+ EXPECT_FALSE(controller.IsInitialBlankNavigation());
// After starting a new navigation, it stays false.
const GURL url2("http://foo2");
controller.LoadURL(
url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
+ EXPECT_FALSE(controller.IsInitialNavigation());
+ EXPECT_FALSE(controller.IsInitialBlankNavigation());
+
+ // For cloned tabs, IsInitialNavigationShould be true but
+ // IsInitialBlankNavigation should be false.
+ scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone());
+ EXPECT_TRUE(clone->GetController().IsInitialNavigation());
+ EXPECT_FALSE(clone->GetController().IsInitialBlankNavigation());
}
// Check that the favicon is not reused across a client redirect.
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl_browsertest.cc ('k') | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698