OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 5408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5419 // the body of the page. | 5419 // the body of the page. |
5420 std::string body; | 5420 std::string body; |
5421 EXPECT_TRUE(ExecuteScriptAndExtractString( | 5421 EXPECT_TRUE(ExecuteScriptAndExtractString( |
5422 shell()->web_contents(), | 5422 shell()->web_contents(), |
5423 "window.domAutomationController.send(" | 5423 "window.domAutomationController.send(" |
5424 "document.getElementsByTagName('pre')[0].innerText);", | 5424 "document.getElementsByTagName('pre')[0].innerText);", |
5425 &body)); | 5425 &body)); |
5426 EXPECT_EQ("text=value\n", body); | 5426 EXPECT_EQ("text=value\n", body); |
5427 } | 5427 } |
5428 | 5428 |
| 5429 // Tests that sending a PageState update from a named subframe does not get |
| 5430 // incorrectly set on previously existing FrameNavigationEntry for the same |
| 5431 // name. See https://crbug.com/628677. |
| 5432 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, PageStateMismatch) { |
| 5433 WebContentsImpl* web_contents = |
| 5434 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 5435 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 5436 |
| 5437 GURL start_url(embedded_test_server()->GetURL("/title1.html")); |
| 5438 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 5439 NavigationEntryImpl* nav_entry = |
| 5440 web_contents->GetController().GetLastCommittedEntry(); |
| 5441 |
| 5442 std::string add_named_frame_script = |
| 5443 "var f = document.createElement('iframe');" |
| 5444 "f.name = 'foo';" |
| 5445 "document.body.appendChild(f);"; |
| 5446 EXPECT_TRUE(ExecuteScript(root, add_named_frame_script)); |
| 5447 EXPECT_EQ(1U, root->child_count()); |
| 5448 EXPECT_EQ("foo", root->child_at(0)->frame_name()); |
| 5449 |
| 5450 std::string remove_frame_script = |
| 5451 "var f = document.querySelector('iframe');" |
| 5452 "f.parentNode.removeChild(f);"; |
| 5453 EXPECT_TRUE(ExecuteScript(root, remove_frame_script)); |
| 5454 EXPECT_EQ(0U, root->child_count()); |
| 5455 |
| 5456 // When a frame is removed from the page, the corresponding |
| 5457 // FrameNavigationEntry is not removed. This is done intentionally to support |
| 5458 // back-forward navigations in subframes and more intuitive UX on tab restore. |
| 5459 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5460 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); |
| 5461 FrameNavigationEntry* frame_entry = |
| 5462 nav_entry->root_node()->children[0]->frame_entry.get(); |
| 5463 EXPECT_EQ("foo", frame_entry->frame_unique_name()); |
| 5464 } |
| 5465 |
| 5466 std::string add_frame_script = |
| 5467 "var f = document.createElement('iframe');" |
| 5468 "document.body.appendChild(f);"; |
| 5469 EXPECT_TRUE(ExecuteScript(root, add_frame_script)); |
| 5470 EXPECT_EQ(1U, root->child_count()); |
| 5471 EXPECT_NE("foo", root->child_at(0)->frame_name()); |
| 5472 |
| 5473 // Add a nested frame with the previously used name. |
| 5474 EXPECT_TRUE(ExecuteScript(root->child_at(0), add_named_frame_script)); |
| 5475 EXPECT_EQ(1U, root->child_at(0)->child_count()); |
| 5476 EXPECT_EQ("foo", root->child_at(0)->child_at(0)->frame_name()); |
| 5477 |
| 5478 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5479 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); |
| 5480 |
| 5481 NavigationEntryImpl::TreeNode* tree_node = |
| 5482 nav_entry->root_node()->children[0]; |
| 5483 EXPECT_EQ(1U, tree_node->children.size()); |
| 5484 |
| 5485 tree_node = tree_node->children[0]; |
| 5486 EXPECT_EQ(0U, tree_node->children.size()); |
| 5487 EXPECT_EQ("foo", tree_node->frame_entry->frame_unique_name()); |
| 5488 } |
| 5489 |
| 5490 EXPECT_TRUE(ExecuteScript(root->child_at(0), remove_frame_script)); |
| 5491 EXPECT_EQ(0U, root->child_at(0)->child_count()); |
| 5492 } |
| 5493 |
| 5494 // Tests that inserting a named subframe into the FrameTree clears any |
| 5495 // previously existing FrameNavigationEntry objects for the same name. |
| 5496 // See https://crbug.com/628677. |
| 5497 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5498 EnsureFrameNavigationEntriesClearedOnNameConflict) { |
| 5499 WebContentsImpl* web_contents = |
| 5500 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 5501 NavigationControllerImpl& controller = web_contents->GetController(); |
| 5502 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 5503 |
| 5504 // Start by navigating to a page with complex frame hierarchy. |
| 5505 GURL start_url(embedded_test_server()->GetURL("/frame_tree/top.html")); |
| 5506 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 5507 EXPECT_EQ(3U, root->child_count()); |
| 5508 EXPECT_EQ(2U, root->child_at(0)->child_count()); |
| 5509 |
| 5510 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 5511 |
| 5512 // Verify only the parts of the NavigationEntry affected by this test. |
| 5513 { |
| 5514 // * Main frame has 3 subframes. |
| 5515 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| 5516 EXPECT_NE(nullptr, root_entry); |
| 5517 EXPECT_EQ("", root_entry->frame_unique_name()); |
| 5518 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5519 EXPECT_EQ(3U, entry->root_node()->children.size()); |
| 5520 |
| 5521 // * The first child of the main frame is named and has two more children. |
| 5522 FrameTreeNode* frame = root->child_at(0); |
| 5523 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame); |
| 5524 EXPECT_NE(nullptr, frame_entry); |
| 5525 EXPECT_EQ("1-1-name", frame_entry->frame_unique_name()); |
| 5526 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size()); |
| 5527 } |
| 5528 } |
| 5529 |
| 5530 // Removing the first child of the main frame should remove the corresponding |
| 5531 // FrameTreeNode. |
| 5532 std::string remove_frame_script = |
| 5533 "var f = document.getElementById('1-1-id');" |
| 5534 "f.parentNode.removeChild(f);"; |
| 5535 EXPECT_TRUE(ExecuteScript(root, remove_frame_script)); |
| 5536 EXPECT_EQ(2U, root->child_count()); |
| 5537 |
| 5538 // However, the FrameNavigationEntry objects for the frame that was removed |
| 5539 // should still be around. |
| 5540 { |
| 5541 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| 5542 EXPECT_NE(nullptr, root_entry); |
| 5543 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5544 EXPECT_EQ(3U, entry->root_node()->children.size()); |
| 5545 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size()); |
| 5546 } |
| 5547 } |
| 5548 |
| 5549 // Now, insert a frame with the same name as the previously removed one |
| 5550 // at a different layer of the frame tree. |
| 5551 FrameTreeNode* subframe = root->child_at(1)->child_at(1)->child_at(0); |
| 5552 EXPECT_EQ(2U, root->child_at(1)->child_count()); |
| 5553 EXPECT_EQ(0U, subframe->child_count()); |
| 5554 std::string add_named_frame_script = |
| 5555 "var f = document.createElement('iframe');" |
| 5556 "f.name = '1-1-name';" |
| 5557 "document.body.appendChild(f);"; |
| 5558 EXPECT_TRUE(ExecuteScript(subframe, add_named_frame_script)); |
| 5559 EXPECT_EQ(1U, subframe->child_count()); |
| 5560 |
| 5561 // Verify that the FrameNavigationEntry for the original frame is now gone. |
| 5562 { |
| 5563 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root); |
| 5564 EXPECT_NE(nullptr, root_entry); |
| 5565 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5566 EXPECT_EQ(2U, entry->root_node()->children.size()); |
| 5567 } |
| 5568 } |
| 5569 } |
| 5570 |
5429 } // namespace content | 5571 } // namespace content |
OLD | NEW |