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 c18ca9be21cbf1e05198a511ab574c94508f6803..bc1f89709a97fdb3ef9ac80686588c3c4592439d 100644 |
--- a/content/browser/frame_host/navigation_controller_impl_unittest.cc |
+++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc |
@@ -12,6 +12,7 @@ |
#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/frame_navigation_entry.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_entry_screenshot_manager.h" |
@@ -1598,14 +1599,9 @@ TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
main_test_rfh()->PrepareForCommit(); |
main_test_rfh()->SendNavigate(1, kUrl2); |
- // We know all the entries have the same site instance, so we can just grab |
- // a random one for looking up other entries. |
- SiteInstance* site_instance = |
- controller.GetLastCommittedEntry()->site_instance(); |
- |
// That second URL should be the last committed and it should have gotten the |
// new title. |
- EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
+ EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(1)->GetURL()); |
EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
@@ -1932,23 +1928,43 @@ TEST_F(NavigationControllerTest, NewSubframe) { |
RegisterForAllNavNotifications(¬ifications, &controller); |
const GURL url1("http://foo1"); |
- main_test_rfh()->SendNavigate(0, url1); |
+ main_test_rfh()->SendNavigate(-1, url1); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
+ EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID()); |
- const GURL url2("http://foo2"); |
+ // Add a subframe to navigate, with an initial page. |
+ main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
+ SandboxFlags::NONE); |
+ RenderFrameHostImpl* subframe = |
+ contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
+ { |
+ const GURL url2("http://foo2"); |
+ FrameHostMsg_DidCommitProvisionalLoad_Params params; |
+ params.page_id = 1; |
+ params.url = url2; |
+ params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
+ params.should_update_history = false; |
+ params.gesture = NavigationGestureUser; |
+ params.is_post = false; |
+ params.page_state = PageState::CreateFromURL(url2); |
+ LoadCommittedDetails details; |
+ EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
+ EXPECT_EQ(0U, notifications.size()); |
+ } |
+ |
+ const GURL url3("http://foo3"); |
FrameHostMsg_DidCommitProvisionalLoad_Params params; |
- params.page_id = 1; |
- params.url = url2; |
+ params.page_id = -1; |
+ params.url = url3; |
params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
params.should_update_history = false; |
params.gesture = NavigationGestureUser; |
params.is_post = false; |
- params.page_state = PageState::CreateFromURL(url2); |
+ params.page_state = PageState::CreateFromURL(url3); |
LoadCommittedDetails details; |
- EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
EXPECT_EQ(url1, details.previous_url); |
@@ -1958,10 +1974,19 @@ TEST_F(NavigationControllerTest, NewSubframe) { |
// The new entry should be appended. |
EXPECT_EQ(2, controller.GetEntryCount()); |
- // New entry should refer to the new page, but the old URL (entries only |
- // reflect the toplevel URL). |
- EXPECT_EQ(url1, details.entry->GetURL()); |
- EXPECT_EQ(params.page_id, details.entry->GetPageID()); |
+ // The new entry should have a page ID for the new page, but the entry's URL |
+ // is for the top level and shouldn't change. |
+ NavigationEntryImpl* entry = static_cast<NavigationEntryImpl*>(details.entry); |
+ EXPECT_EQ(url1, entry->GetURL()); |
+ EXPECT_EQ(2, entry->GetPageID()); |
+ FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
+ EXPECT_EQ(url1, root_entry->url()); |
+ |
+ // The subframe's FrameNavigationEntry should have the new URL. |
+ ASSERT_EQ(1U, entry->root_node()->children.size()); |
+ FrameNavigationEntry* frame_entry = |
+ entry->root_node()->children[0]->frame_entry.get(); |
+ EXPECT_EQ(url3, frame_entry->url()); |
} |
// Auto subframes are ones the page loads automatically like ads. They should |
@@ -1971,14 +1996,21 @@ TEST_F(NavigationControllerTest, AutoSubframe) { |
TestNotificationTracker notifications; |
RegisterForAllNavNotifications(¬ifications, &controller); |
- const GURL url1("http://foo1"); |
- main_test_rfh()->SendNavigate(0, url1); |
+ const GURL url1("http://foo/1"); |
+ main_test_rfh()->SendNavigate(-1, url1); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
+ EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID()); |
- const GURL url2("http://foo2"); |
+ // Add a subframe to navigate. |
+ main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
+ SandboxFlags::NONE); |
+ RenderFrameHostImpl* subframe = |
+ contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
+ |
+ const GURL url2("http://foo/2"); |
FrameHostMsg_DidCommitProvisionalLoad_Params params; |
- params.page_id = 0; |
+ params.page_id = 1; |
params.url = url2; |
params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
params.should_update_history = false; |
@@ -1988,12 +2020,22 @@ TEST_F(NavigationControllerTest, AutoSubframe) { |
// Navigating should do nothing. |
LoadCommittedDetails details; |
- EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(0U, notifications.size()); |
// There should still be only one entry. |
EXPECT_EQ(1, controller.GetEntryCount()); |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ EXPECT_EQ(url1, entry->GetURL()); |
+ EXPECT_EQ(1, entry->GetPageID()); |
+ |
+ // The entry should now have a subframe FrameNavigationEntry. |
+ FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
+ EXPECT_EQ(url1, root_entry->url()); |
+ ASSERT_EQ(1U, entry->root_node()->children.size()); |
+ FrameNavigationEntry* frame_entry = |
+ entry->root_node()->children[0]->frame_entry.get(); |
+ EXPECT_EQ(url2, frame_entry->url()); |
} |
// Tests navigation and then going back to a subframe navigation. |
@@ -2004,68 +2046,88 @@ TEST_F(NavigationControllerTest, BackSubframe) { |
// Main page. |
const GURL url1("http://foo1"); |
- main_test_rfh()->SendNavigate(0, url1); |
+ main_test_rfh()->SendNavigate(-1, url1); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
+ EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID()); |
+ |
+ // Add a subframe with an initial page to navigate. |
+ main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
+ SandboxFlags::NONE); |
+ RenderFrameHostImpl* subframe = |
+ contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
+ const GURL init_subframe_url("http://foo1/subframe"); |
+ FrameHostMsg_DidCommitProvisionalLoad_Params params; |
+ params.page_id = -1; |
+ params.url = init_subframe_url; |
+ params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
+ params.should_update_history = false; |
+ params.gesture = NavigationGestureUser; |
+ params.is_post = false; |
+ params.page_state = PageState::CreateFromURL(init_subframe_url); |
+ |
+ // This auto-subframe should not create a new entry. |
+ LoadCommittedDetails details; |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
+ EXPECT_EQ(1U, navigation_entry_committed_counter_); |
+ navigation_entry_committed_counter_ = 0; |
+ EXPECT_EQ(1, controller.GetEntryCount()); |
+ EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID()); |
// First manual subframe navigation. |
const GURL url2("http://foo2"); |
- FrameHostMsg_DidCommitProvisionalLoad_Params params; |
- params.page_id = 1; |
+ params.page_id = -1; |
params.url = url2; |
params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
- params.should_update_history = false; |
- params.gesture = NavigationGestureUser; |
- params.is_post = false; |
params.page_state = PageState::CreateFromURL(url2); |
// This should generate a new entry. |
- LoadCommittedDetails details; |
- EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
EXPECT_EQ(2, controller.GetEntryCount()); |
+ EXPECT_EQ(2, controller.GetLastCommittedEntry()->GetPageID()); |
// Second manual subframe navigation should also make a new entry. |
const GURL url3("http://foo3"); |
- params.page_id = 2; |
+ params.page_id = -1; |
params.url = url3; |
params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
- EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
EXPECT_EQ(3, controller.GetEntryCount()); |
EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
+ EXPECT_EQ(3, controller.GetLastCommittedEntry()->GetPageID()); |
// Go back one. |
controller.GoBack(); |
+ // TODO(creis): Verify shape of the pending entry's tree. |
params.page_id = 1; |
params.url = url2; |
params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
- EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
EXPECT_EQ(3, controller.GetEntryCount()); |
EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
EXPECT_FALSE(controller.GetPendingEntry()); |
+ EXPECT_EQ(2, controller.GetLastCommittedEntry()->GetPageID()); |
// Go back one more. |
controller.GoBack(); |
params.page_id = 0; |
params.url = url1; |
params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
- EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); |
EXPECT_EQ(1U, navigation_entry_committed_counter_); |
navigation_entry_committed_counter_ = 0; |
EXPECT_EQ(3, controller.GetEntryCount()); |
EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
EXPECT_FALSE(controller.GetPendingEntry()); |
+ EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID()); |
} |
TEST_F(NavigationControllerTest, LinkClick) { |
@@ -3281,29 +3343,43 @@ TEST_F(NavigationControllerTest, SameSubframe) { |
NavigationControllerImpl& controller = controller_impl(); |
// Navigate the main frame. |
const GURL url("http://www.google.com/"); |
- main_test_rfh()->SendNavigate(0, url); |
+ main_test_rfh()->SendNavigate(-1, url); |
// We should be at the first navigation entry. |
- EXPECT_EQ(controller.GetEntryCount(), 1); |
- EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
+ EXPECT_EQ(1, controller.GetEntryCount()); |
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
+ |
+ // Add a subframe to navigate. |
+ main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
+ SandboxFlags::NONE); |
+ RenderFrameHostImpl* subframe = |
+ contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
// Navigate a subframe that would normally count as in-page. |
- const GURL subframe("http://www.google.com/#"); |
+ const GURL subframe_url("http://www.google.com/#"); |
FrameHostMsg_DidCommitProvisionalLoad_Params params; |
- params.page_id = 0; |
- params.url = subframe; |
+ params.page_id = 1; |
+ params.url = subframe_url; |
params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
params.should_update_history = false; |
params.gesture = NavigationGestureAuto; |
params.is_post = false; |
- params.page_state = PageState::CreateFromURL(subframe); |
+ params.page_state = PageState::CreateFromURL(subframe_url); |
LoadCommittedDetails details; |
- EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
- &details)); |
+ EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
- // Nothing should have changed. |
- EXPECT_EQ(controller.GetEntryCount(), 1); |
- EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
+ // Nothing should have changed at the top level. |
+ EXPECT_EQ(1, controller.GetEntryCount()); |
+ EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
+ |
+ // The entry should now have a subframe FrameNavigationEntry. |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
+ EXPECT_EQ(url, root_entry->url()); |
+ ASSERT_EQ(1U, entry->root_node()->children.size()); |
+ FrameNavigationEntry* frame_entry = |
+ entry->root_node()->children[0]->frame_entry.get(); |
+ EXPECT_EQ(subframe_url, frame_entry->url()); |
} |
// Make sure that on cloning a WebContentsImpl and going back needs_reload is |