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 9aacb49b0e91ef4143019bde521851eae795c131..1b4a48a9ec16b48d3c52fa57d853d75db51105b6 100644 |
| --- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| +++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| @@ -5397,4 +5397,120 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, PostViaOpenUrlMsg) { |
| EXPECT_EQ("text=value\n", body); |
| } |
| +// Tests that sending a PageState update from a named subframe does not get |
| +// incorrectly set on previously existing FrameNavigationEntry for the same |
| +// name. See https://crbug.com/628677. |
| +// TODO(nasko): Move this to NavigationControllerBrowserTest once the default |
| +// for UseSubframeNavigationEntries is set to true. |
|
Charlie Reis
2016/07/27 22:48:27
Interesting. I've just been making them normal te
nasko
2016/07/29 15:52:21
Sure. Makes sense. I was trying to ensure they run
|
| +IN_PROC_BROWSER_TEST_F(NavigationControllerOopifBrowserTest, |
| + PageStateMismatch) { |
| + WebContentsImpl* web_contents = |
| + static_cast<WebContentsImpl*>(shell()->web_contents()); |
| + FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| + |
| + GURL start_url(embedded_test_server()->GetURL("/title1.html")); |
| + EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| + |
| + std::string add_named_frame_script = |
| + "var f = document.createElement('iframe');" |
| + "f.name = 'foo';" |
| + "document.body.appendChild(f);"; |
| + EXPECT_TRUE(ExecuteScript(root, add_named_frame_script)); |
| + EXPECT_EQ(1U, root->child_count()); |
| + EXPECT_EQ("foo", root->child_at(0)->frame_name()); |
| + |
| + std::string remove_frame_script = |
| + "var f = document.querySelector('iframe');" |
| + "f.parentNode.removeChild(f);"; |
| + EXPECT_TRUE(ExecuteScript(root, remove_frame_script)); |
| + EXPECT_EQ(0U, root->child_count()); |
|
Charlie Reis
2016/07/27 22:48:27
Can you add an expectation after this that we stil
nasko
2016/07/29 15:52:21
Done.
|
| + |
| + std::string add_frame_script = |
| + "var f = document.createElement('iframe');" |
| + "document.body.appendChild(f);"; |
| + EXPECT_TRUE(ExecuteScript(root, add_frame_script)); |
| + EXPECT_EQ(1U, root->child_count()); |
| + EXPECT_NE("foo", root->child_at(0)->frame_name()); |
| + |
| + EXPECT_TRUE(ExecuteScript(root->child_at(0), add_named_frame_script)); |
|
Charlie Reis
2016/07/27 22:48:27
// Add a nested frame with the previously used nam
nasko
2016/07/29 15:52:19
Done.
|
| + EXPECT_EQ(1U, root->child_at(0)->child_count()); |
| + EXPECT_EQ("foo", root->child_at(0)->child_at(0)->frame_name()); |
|
Charlie Reis
2016/07/27 22:48:27
Let's verify the tree of FrameNavigationEntries he
nasko
2016/07/29 15:52:21
Done.
|
| + |
| + EXPECT_TRUE(ExecuteScript(root->child_at(0), remove_frame_script)); |
| + EXPECT_EQ(0U, root->child_at(0)->child_count()); |
|
Charlie Reis
2016/07/27 22:48:27
I assume this crashed due to your NOTREACHED?
nasko
2016/07/29 15:52:19
Indeed!
|
| +} |
| + |
| +// Tests that inserting a named subframe into the FrameTree clears any |
| +// previously existing FrameNavigationEntry objects for the same name. |
| +// See https://crbug.com/628677. |
| +// TODO(nasko): Move this to NavigationControllerBrowserTest once the default |
| +// for UseSubframeNavigationEntries is set to true. |
| +IN_PROC_BROWSER_TEST_F(NavigationControllerOopifBrowserTest, |
| + EnsureFrameNavigationEntriesClearedOnNameConflict) { |
|
Charlie Reis
2016/07/27 22:48:27
This seems better documented than the one above, a
nasko
2016/07/29 15:52:20
This one actually navigates the iframes to real UR
Charlie Reis
2016/07/29 17:21:35
Ah, that didn't come across from the comments or t
nasko
2016/08/01 20:42:15
Reordered and renamed to match a bit better.
Charlie Reis
2016/08/01 21:04:25
Yes. I'm curious how that works out, since I'd lo
|
| + WebContentsImpl* web_contents = |
| + static_cast<WebContentsImpl*>(shell()->web_contents()); |
| + NavigationControllerImpl& controller = web_contents->GetController(); |
| + FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| + |
| + // Start by navigating to a page with complex frame hierarchy. |
| + GURL start_url(embedded_test_server()->GetURL("/frame_tree/top.html")); |
| + EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| + EXPECT_EQ(3U, root->child_count()); |
| + EXPECT_EQ(2U, root->child_at(0)->child_count()); |
| + |
| + NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| + |
| + // Verify only the parts of the NavigationEntry affected by this test. |
| + { |
| + // * Main frame has 3 subframes. |
| + FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| + EXPECT_NE(nullptr, root_entry); |
| + EXPECT_EQ("", root_entry->frame_unique_name()); |
| + EXPECT_EQ(3U, entry->root_node()->children.size()); |
| + |
| + // * The first child of the main frame is named and has two more children. |
| + FrameTreeNode* frame = root->child_at(0); |
| + FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame); |
| + EXPECT_NE(nullptr, frame_entry); |
| + EXPECT_EQ("1-1-name", frame_entry->frame_unique_name()); |
| + EXPECT_EQ(2U, entry->root_node()->children[0]->children.size()); |
| + } |
| + |
| + // Removing the first child of the main frame should remove the corresponding |
| + // FrameTreeNode. |
| + std::string remove_frame_script = |
| + "var f = document.getElementById('1-1-id');" |
| + "f.parentNode.removeChild(f);"; |
| + EXPECT_TRUE(ExecuteScript(root, remove_frame_script)); |
| + EXPECT_EQ(2U, root->child_count()); |
| + |
| + // However, the FrameNavigationEntry objects for the frame that was removed |
| + // should still be around. |
| + { |
| + FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| + EXPECT_NE(nullptr, root_entry); |
| + EXPECT_EQ(3U, entry->root_node()->children.size()); |
| + EXPECT_EQ(2U, entry->root_node()->children[0]->children.size()); |
| + } |
| + |
| + // Now, insert a frame with the same name as the previously removed one |
| + // at a different layer of the frame tree. |
| + FrameTreeNode* subframe = root->child_at(1)->child_at(1)->child_at(0); |
| + EXPECT_EQ(2U, root->child_at(1)->child_count()); |
| + EXPECT_EQ(0U, subframe->child_count()); |
| + std::string add_named_frame_script = |
| + "var f = document.createElement('iframe');" |
| + "f.name = '1-1-name';" |
| + "document.body.appendChild(f);"; |
| + EXPECT_TRUE(ExecuteScript(subframe, add_named_frame_script)); |
| + EXPECT_EQ(1U, subframe->child_count()); |
| + |
| + // Verify that the FrameNavigationEntry for the original frame is now gone. |
| + { |
| + FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| + EXPECT_NE(nullptr, root_entry); |
| + EXPECT_EQ(2U, entry->root_node()->children.size()); |
| + } |
| +} |
| + |
| } // namespace content |