Chromium Code Reviews| Index: content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| diff --git a/content/browser/frame_host/navigation_controller_impl_browsertest.cc b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| index 6cc541ef01a1ebc629e2985f6bbac94a1190f1bb..085b2ca4b91cbd5fd94f15e1920ca02699572b22 100644 |
| --- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| +++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| @@ -948,12 +948,19 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| } |
| } |
| -// Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME |
| -// commits. |
| +// Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME |
| +// and NAVIGATION_TYPE_AUTO_SUBFRAME commits. Steps: |
| +// 1. Create an iframe. |
| +// 2. Create a second iframe. |
| +// 3. Create a nested iframe in the second iframe. |
| +// 4. Navigate in the first iframe. |
| +// 5. Navigate in the nested subframe. |
| +// 6. Navigate in the second subframe, clearing its existing subtree. |
| +// |
| // TODO(creis): Test cross-site iframes. |
| // TODO(creis): Test updating entries for history auto subframe navigations. |
| IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| - FrameNavigationEntry_AutoSubframe) { |
| + FrameNavigationEntry_NewAndAutoSubframe) { |
| GURL main_url(embedded_test_server()->GetURL( |
| "/navigation_controller/simple_page_1.html")); |
| NavigateToURL(shell(), main_url); |
| @@ -964,7 +971,7 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| GetFrameTree()->root(); |
| - // Create an iframe. |
| + // 1. Create an iframe. |
| GURL frame_url(embedded_test_server()->GetURL( |
| "/navigation_controller/simple_page_2.html")); |
| { |
| @@ -997,7 +1004,7 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| EXPECT_EQ(0U, entry->root_node()->children.size()); |
| } |
| - // Create a second iframe. |
| + // 2. Create a second iframe. |
| { |
| LoadCommittedCapturer capturer(shell()->web_contents()); |
| std::string script = "var iframe = document.createElement('iframe');" |
| @@ -1028,7 +1035,7 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| EXPECT_EQ(0U, entry->root_node()->children.size()); |
| } |
| - // Create a nested iframe in the second subframe. |
| + // 3. Create a nested iframe in the second subframe. |
| { |
| LoadCommittedCapturer capturer(shell()->web_contents()); |
| std::string script = "var iframe = document.createElement('iframe');" |
| @@ -1060,6 +1067,113 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| // There are no subframe FrameNavigationEntries by default. |
| EXPECT_EQ(0U, entry->root_node()->children.size()); |
| } |
| + |
| + // 4. Navigate in the first subframe. |
| + GURL frame_url2(embedded_test_server()->GetURL( |
| + "/navigation_controller/page_with_links.html")); |
| + { |
| + FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| + NavigateFrameToURL(root->child_at(0), frame_url2); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| + capturer.params().transition); |
| + EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| + } |
| + |
| + // We should create a new NavigationEntry with the same main frame URL. |
| + EXPECT_EQ(2, controller.GetEntryCount()); |
| + EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| + NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| + EXPECT_NE(entry, entry2); |
| + EXPECT_EQ(main_url, entry2->GetURL()); |
| + FrameNavigationEntry* root_entry2 = entry2->root_node()->frame_entry.get(); |
| + EXPECT_EQ(main_url, root_entry2->url()); |
| + |
| + // Verify subframe entries if we're in --site-per-process mode. |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kSitePerProcess)) { |
| + // The entry should still have FrameNavigationEntries for all 3 subframes. |
| + ASSERT_EQ(2U, entry2->root_node()->children.size()); |
| + EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url()); |
| + EXPECT_EQ(frame_url, entry2->root_node()->children[1]->frame_entry->url()); |
| + ASSERT_EQ(1U, entry2->root_node()->children[1]->children.size()); |
| + EXPECT_EQ( |
| + frame_url, |
| + entry2->root_node()->children[1]->children[0]->frame_entry->url()); |
| + } else { |
| + // There are no subframe FrameNavigationEntries by default. |
| + EXPECT_EQ(0U, entry2->root_node()->children.size()); |
| + } |
| + |
| + // 5. Navigate in the nested subframe. |
| + { |
| + FrameNavigateParamsCapturer capturer(root->child_at(1)->child_at(0)); |
| + NavigateFrameToURL(root->child_at(1)->child_at(0), frame_url2); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| + capturer.params().transition); |
| + EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| + } |
| + |
| + // We should create a new NavigationEntry with the same main frame URL. |
|
Avi (use Gerrit)
2015/05/19 16:34:13
My preferred phrasing would be "We should have cre
Charlie Reis
2015/05/19 17:59:24
Done.
|
| + EXPECT_EQ(3, controller.GetEntryCount()); |
| + EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| + NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); |
| + EXPECT_NE(entry, entry3); |
| + EXPECT_EQ(main_url, entry3->GetURL()); |
| + FrameNavigationEntry* root_entry3 = entry3->root_node()->frame_entry.get(); |
| + EXPECT_EQ(main_url, root_entry3->url()); |
| + |
| + // Verify subframe entries if we're in --site-per-process mode. |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kSitePerProcess)) { |
| + // The entry should still have FrameNavigationEntries for all 3 subframes. |
| + ASSERT_EQ(2U, entry3->root_node()->children.size()); |
| + EXPECT_EQ(frame_url2, entry3->root_node()->children[0]->frame_entry->url()); |
| + EXPECT_EQ(frame_url, entry3->root_node()->children[1]->frame_entry->url()); |
| + ASSERT_EQ(1U, entry3->root_node()->children[1]->children.size()); |
| + EXPECT_EQ( |
| + frame_url2, |
| + entry3->root_node()->children[1]->children[0]->frame_entry->url()); |
| + } else { |
| + // There are no subframe FrameNavigationEntries by default. |
| + EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| + } |
| + |
| + // 6. Navigate in the second subframe, clearing its existing subtree. |
| + { |
| + FrameNavigateParamsCapturer capturer(root->child_at(1)); |
| + NavigateFrameToURL(root->child_at(1), frame_url2); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| + capturer.params().transition); |
| + EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| + } |
| + |
| + // We should create a new NavigationEntry with the same main frame URL. |
| + EXPECT_EQ(4, controller.GetEntryCount()); |
| + EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| + NavigationEntryImpl* entry4 = controller.GetLastCommittedEntry(); |
| + EXPECT_NE(entry, entry4); |
| + EXPECT_EQ(main_url, entry4->GetURL()); |
| + FrameNavigationEntry* root_entry4 = entry4->root_node()->frame_entry.get(); |
| + EXPECT_EQ(main_url, root_entry4->url()); |
| + |
| + // Verify subframe entries if we're in --site-per-process mode. |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kSitePerProcess)) { |
| + // The entry should now only have FrameNavigationEntries for 2 frames. |
| + ASSERT_EQ(2U, entry4->root_node()->children.size()); |
| + EXPECT_EQ(frame_url2, entry4->root_node()->children[0]->frame_entry->url()); |
| + EXPECT_EQ(frame_url2, entry4->root_node()->children[1]->frame_entry->url()); |
| + ASSERT_EQ(0U, entry4->root_node()->children[1]->children.size()); |
| + |
| + // The previous entry should be unchanged. |
| + EXPECT_EQ(frame_url, entry3->root_node()->children[1]->frame_entry->url()); |
| + } else { |
| + // There are no subframe FrameNavigationEntries by default. |
| + EXPECT_EQ(0U, entry4->root_node()->children.size()); |
| + } |
| } |
| namespace { |