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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 1871293002: Don't use pending NavigationEntries for navigation transfers (try #2). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review comments. Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 : WebContentsObserver(web_contents) {} 462 : WebContentsObserver(web_contents) {}
463 463
464 private: 464 private:
465 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, 465 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
466 const LoadCommittedDetails& details, 466 const LoadCommittedDetails& details,
467 const FrameNavigateParams& params) override { 467 const FrameNavigateParams& params) override {
468 FAIL() << "No navigations should occur"; 468 FAIL() << "No navigations should occur";
469 } 469 }
470 }; 470 };
471 471
472 } // namespace
473
474 // Some pages create a popup, then write an iframe into it. This causes a
475 // subframe navigation without having any committed entry. Such navigations
476 // just get thrown on the ground, but we shouldn't crash.
477 //
478 // This test actually hits NAVIGATION_TYPE_NAV_IGNORE three times. Two of them,
479 // the initial window.open() and the iframe creation, don't try to create
480 // navigation entries, and the third, the new navigation, tries to.
481 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) {
482 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
483 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
484
485 FrameTreeNode* root =
486 static_cast<WebContentsImpl*>(shell()->web_contents())->
487 GetFrameTree()->root();
488
489 // Pop open a new window.
490 ShellAddedObserver new_shell_observer;
491 std::string script = "window.open()";
492 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
493 Shell* new_shell = new_shell_observer.GetShell();
494 ASSERT_NE(new_shell->web_contents(), shell()->web_contents());
495 FrameTreeNode* new_root =
496 static_cast<WebContentsImpl*>(new_shell->web_contents())->
497 GetFrameTree()->root();
498
499 // Make a new iframe in it.
500 NoNavigationsObserver observer(new_shell->web_contents());
501 script = "var iframe = document.createElement('iframe');"
502 "iframe.src = 'data:text/html,<p>some page</p>';"
503 "document.body.appendChild(iframe);";
504 EXPECT_TRUE(ExecuteScript(new_root->current_frame_host(), script));
505 // The success check is of the last-committed entry, and there is none.
506 WaitForLoadStopWithoutSuccessCheck(new_shell->web_contents());
507
508 ASSERT_EQ(1U, new_root->child_count());
509 ASSERT_NE(nullptr, new_root->child_at(0));
510
511 // Navigate it.
512 GURL frame_url = embedded_test_server()->GetURL(
513 "/navigation_controller/simple_page_2.html");
514 script = "location.assign('" + frame_url.spec() + "')";
515 EXPECT_TRUE(
516 ExecuteScript(new_root->child_at(0)->current_frame_host(), script));
517
518 // Success is not crashing, and not navigating.
519 EXPECT_EQ(nullptr,
520 new_shell->web_contents()->GetController().GetLastCommittedEntry());
521 }
522
523 namespace {
524
525 class FrameNavigateParamsCapturer : public WebContentsObserver { 472 class FrameNavigateParamsCapturer : public WebContentsObserver {
526 public: 473 public:
527 // Observes navigation for the specified |node|. 474 // Observes navigation for the specified |node|.
528 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) 475 explicit FrameNavigateParamsCapturer(FrameTreeNode* node)
529 : WebContentsObserver( 476 : WebContentsObserver(
530 node->current_frame_host()->delegate()->GetAsWebContents()), 477 node->current_frame_host()->delegate()->GetAsWebContents()),
531 frame_tree_node_id_(node->frame_tree_node_id()), 478 frame_tree_node_id_(node->frame_tree_node_id()),
532 navigations_remaining_(1), 479 navigations_remaining_(1),
533 wait_for_load_(true), 480 wait_for_load_(true),
534 message_loop_runner_(new MessageLoopRunner) {} 481 message_loop_runner_(new MessageLoopRunner) {}
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 620
674 // The transition_type of the last navigation. 621 // The transition_type of the last navigation.
675 ui::PageTransition transition_type_; 622 ui::PageTransition transition_type_;
676 623
677 // The MessageLoopRunner used to spin the message loop. 624 // The MessageLoopRunner used to spin the message loop.
678 scoped_refptr<MessageLoopRunner> message_loop_runner_; 625 scoped_refptr<MessageLoopRunner> message_loop_runner_;
679 }; 626 };
680 627
681 } // namespace 628 } // namespace
682 629
630 // Some pages create a popup, then write an iframe into it. This causes a
631 // subframe navigation without having any committed entry. Such navigations
632 // just get thrown on the ground, but we shouldn't crash.
633 //
634 // This test actually hits NAVIGATION_TYPE_NAV_IGNORE four times. Two of them,
635 // the initial window.open() and the iframe creation, don't try to create
636 // navigation entries, and the third and fourth, the new navigations, try to.
637 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) {
638 // Navigate to a page to force the renderer process to start.
639 EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL)));
640 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
641 ->GetFrameTree()
642 ->root();
643
644 // Pop open a new window with no last committed entry.
645 ShellAddedObserver new_shell_observer;
646 {
647 std::string script = "window.open()";
648 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
649 }
650 Shell* new_shell = new_shell_observer.GetShell();
651 ASSERT_NE(new_shell->web_contents(), shell()->web_contents());
652 FrameTreeNode* new_root =
653 static_cast<WebContentsImpl*>(new_shell->web_contents())
654 ->GetFrameTree()
655 ->root();
656 EXPECT_FALSE(
657 new_shell->web_contents()->GetController().GetLastCommittedEntry());
658
659 // Make a new iframe in it.
660 NoNavigationsObserver observer(new_shell->web_contents());
661 {
662 LoadCommittedCapturer capturer(new_shell->web_contents());
663 std::string script = "var iframe = document.createElement('iframe');"
664 "iframe.src = 'data:text/html,<p>some page</p>';"
665 "document.body.appendChild(iframe);";
666 EXPECT_TRUE(ExecuteScript(new_root->current_frame_host(), script));
667 capturer.Wait();
668 }
669 ASSERT_EQ(1U, new_root->child_count());
670 ASSERT_NE(nullptr, new_root->child_at(0));
671
672 // Navigate it cross-site.
673 GURL frame_url = embedded_test_server()->GetURL(
674 "foo.com", "/navigation_controller/simple_page_2.html");
675 {
676 LoadCommittedCapturer capturer(new_shell->web_contents());
677 std::string script = "location.assign('" + frame_url.spec() + "')";
678 EXPECT_TRUE(
679 ExecuteScript(new_root->child_at(0)->current_frame_host(), script));
680 capturer.Wait();
681 }
682
683 // Success is not crashing, and not navigating.
684 EXPECT_EQ(nullptr,
685 new_shell->web_contents()->GetController().GetLastCommittedEntry());
686
687 // A nested iframe with a cross-site URL should also be able to commit.
688 GURL grandchild_url(embedded_test_server()->GetURL(
689 "bar.com", "/navigation_controller/simple_page_1.html"));
690 {
691 LoadCommittedCapturer capturer(new_shell->web_contents());
692 std::string script = "var iframe = document.createElement('iframe');"
693 "iframe.src = '" + grandchild_url.spec() + "';"
694 "document.body.appendChild(iframe);";
695 EXPECT_TRUE(
696 ExecuteScript(new_root->child_at(0)->current_frame_host(), script));
697 capturer.Wait();
698 }
699 ASSERT_EQ(1U, new_root->child_at(0)->child_count());
700 EXPECT_EQ(grandchild_url, new_root->child_at(0)->child_at(0)->current_url());
701 }
702
683 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 703 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
684 ErrorPageReplacement) { 704 ErrorPageReplacement) {
685 NavigationController& controller = shell()->web_contents()->GetController(); 705 NavigationController& controller = shell()->web_contents()->GetController();
686 GURL error_url( 706 GURL error_url(
687 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); 707 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET));
688 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 708 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
689 base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); 709 base::Bind(&net::URLRequestFailedJob::AddUrlHandler));
690 710
691 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 711 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
692 EXPECT_EQ(1, controller.GetEntryCount()); 712 EXPECT_EQ(1, controller.GetEntryCount());
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 " Site A ------------ proxies for B\n" 1584 " Site A ------------ proxies for B\n"
1565 " |--Site A ------- proxies for B\n" 1585 " |--Site A ------- proxies for B\n"
1566 " | +--Site A -- proxies for B\n" 1586 " | +--Site A -- proxies for B\n"
1567 " +--Site B ------- proxies for A\n" 1587 " +--Site B ------- proxies for A\n"
1568 "Where A = http://127.0.0.1/\n" 1588 "Where A = http://127.0.0.1/\n"
1569 " B = http://foo.com/", 1589 " B = http://foo.com/",
1570 visualizer.DepictFrameTree(root)); 1590 visualizer.DepictFrameTree(root));
1571 } 1591 }
1572 } 1592 }
1573 1593
1594 // Verify the tree of FrameNavigationEntries when a nested iframe commits inside
1595 // the initial blank page of a loading iframe. Prevents regression of
1596 // https://crbug.com/600743.
1597 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1598 FrameNavigationEntry_SlowNestedAutoSubframe) {
1599 GURL main_url(embedded_test_server()->GetURL(
1600 "/navigation_controller/simple_page_1.html"));
1601 EXPECT_TRUE(NavigateToURL(shell(), main_url));
1602 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1603 ->GetFrameTree()
1604 ->root();
1605
1606 // 1. Create a iframe with a URL that doesn't commit.
1607 GURL slow_url(embedded_test_server()->GetURL(
1608 "/navigation_controller/simple_page_2.html"));
1609 TestNavigationManager subframe_delayer(shell()->web_contents(), slow_url);
1610 {
1611 std::string script = "var iframe = document.createElement('iframe');"
1612 "iframe.src = '" + slow_url.spec() + "';"
1613 "document.body.appendChild(iframe);";
1614 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1615 }
1616 subframe_delayer.WaitForWillStartRequest();
1617
1618 // Stop the request so that we can wait for load stop below, without ending up
1619 // with a commit for this frame.
1620 shell()->web_contents()->Stop();
1621
1622 // 2. A nested iframe with a cross-site URL should be able to commit.
1623 GURL foo_url(embedded_test_server()->GetURL(
1624 "foo.com", "/navigation_controller/simple_page_1.html"));
1625 {
1626 std::string script = "var iframe = document.createElement('iframe');"
1627 "iframe.src = '" + foo_url.spec() + "';"
1628 "document.body.appendChild(iframe);";
1629 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1630 WaitForLoadStopWithoutSuccessCheck(shell()->web_contents());
1631 }
1632
1633 // TODO(creis): Check subframe entries once we create them in this case.
1634 // See https://crbug.com/608402.
1635 EXPECT_EQ(foo_url, root->child_at(0)->child_at(0)->current_url());
1636 }
1637
1638 // Verify the tree of FrameNavigationEntries when a nested iframe commits inside
1639 // the initial blank page of an iframe with no committed entry. Prevents
1640 // regression of https://crbug.com/600743.
1641 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1642 FrameNavigationEntry_NoCommitNestedAutoSubframe) {
1643 GURL main_url(embedded_test_server()->GetURL(
1644 "/navigation_controller/simple_page_1.html"));
1645 EXPECT_TRUE(NavigateToURL(shell(), main_url));
1646 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1647 ->GetFrameTree()
1648 ->root();
1649
1650 // 1. Create a iframe with a URL that doesn't commit.
1651 GURL no_commit_url(embedded_test_server()->GetURL("/nocontent"));
1652 {
1653 std::string script = "var iframe = document.createElement('iframe');"
1654 "iframe.src = '" + no_commit_url.spec() + "';"
1655 "document.body.appendChild(iframe);";
1656 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1657 }
1658 EXPECT_EQ(GURL(), root->child_at(0)->current_url());
1659
1660 // 2. A nested iframe with a cross-site URL should be able to commit.
1661 GURL foo_url(embedded_test_server()->GetURL(
1662 "foo.com", "/navigation_controller/simple_page_1.html"));
1663 {
1664 LoadCommittedCapturer capturer(shell()->web_contents());
1665 std::string script = "var iframe = document.createElement('iframe');"
1666 "iframe.src = '" + foo_url.spec() + "';"
1667 "document.body.appendChild(iframe);";
1668 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1669 capturer.Wait();
1670 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1671 }
1672
1673 // TODO(creis): Check subframe entries once we create them in this case.
1674 // See https://crbug.com/608402.
1675 EXPECT_EQ(foo_url, root->child_at(0)->child_at(0)->current_url());
1676 }
1677
1678 // Verify the tree of FrameNavigationEntries when a nested iframe commits after
1679 // going back in-page, in which case its parent might not have been in the
1680 // NavigationEntry. Prevents regression of https://crbug.com/600743.
1681 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1682 FrameNavigationEntry_BackNestedAutoSubframe) {
1683 GURL main_url(embedded_test_server()->GetURL(
1684 "/navigation_controller/simple_page_1.html"));
1685 EXPECT_TRUE(NavigateToURL(shell(), main_url));
1686 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1687 ->GetFrameTree()
1688 ->root();
1689
1690 // 1. Navigate in-page.
1691 {
1692 FrameNavigateParamsCapturer capturer(root);
1693 std::string script = "history.pushState({}, 'foo', 'foo')";
1694 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1695 capturer.Wait();
1696 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
1697 EXPECT_TRUE(capturer.details().is_in_page);
1698 }
1699
1700 // 2. Create an iframe.
1701 GURL child_url(embedded_test_server()->GetURL(
1702 "/navigation_controller/simple_page_2.html"));
1703 {
1704 LoadCommittedCapturer capturer(shell()->web_contents());
1705 std::string script = "var iframe = document.createElement('iframe');"
1706 "iframe.src = '" + child_url.spec() + "';"
1707 "document.body.appendChild(iframe);";
1708 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1709 capturer.Wait();
1710 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1711 }
1712
1713 // 3. Go back in-page.
1714 {
1715 TestNavigationObserver back_load_observer(shell()->web_contents());
1716 shell()->web_contents()->GetController().GoBack();
1717 back_load_observer.Wait();
1718 }
1719
1720 // 4. A nested iframe with a cross-site URL should be able to commit.
1721 GURL grandchild_url(embedded_test_server()->GetURL(
1722 "foo.com", "/navigation_controller/simple_page_1.html"));
1723 {
1724 LoadCommittedCapturer capturer(shell()->web_contents());
1725 std::string script = "var iframe = document.createElement('iframe');"
1726 "iframe.src = '" + grandchild_url.spec() + "';"
1727 "document.body.appendChild(iframe);";
1728 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1729 capturer.Wait();
1730 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1731 }
1732
1733 // TODO(creis): Check subframe entries once we create them in this case.
1734 // See https://crbug.com/608402.
1735 EXPECT_EQ(grandchild_url, root->child_at(0)->child_at(0)->current_url());
1736 }
1737
1738 // Verify the tree of FrameNavigationEntries when a nested iframe commits after
1739 // its parent changes its name, in which case we might not find the parent
1740 // FrameNavigationEntry. Prevents regression of https://crbug.com/600743.
1741 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1742 FrameNavigationEntry_RenameNestedAutoSubframe) {
1743 GURL main_url(embedded_test_server()->GetURL(
1744 "/navigation_controller/simple_page_1.html"));
1745 EXPECT_TRUE(NavigateToURL(shell(), main_url));
1746 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1747 ->GetFrameTree()
1748 ->root();
1749
1750 // 1. Create an iframe.
1751 GURL child_url(embedded_test_server()->GetURL(
1752 "/navigation_controller/simple_page_2.html"));
1753 {
1754 LoadCommittedCapturer capturer(shell()->web_contents());
1755 std::string script = "var iframe = document.createElement('iframe');"
1756 "iframe.src = '" + child_url.spec() + "';"
1757 "document.body.appendChild(iframe);";
1758 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1759 capturer.Wait();
1760 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1761 }
1762
1763 // 2. Change the iframe's name.
1764 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(),
1765 "window.name = 'foo';"));
1766
1767 // 3. A nested iframe with a cross-site URL should be able to commit.
1768 GURL bar_url(embedded_test_server()->GetURL(
1769 "bar.com", "/navigation_controller/simple_page_1.html"));
1770 {
1771 LoadCommittedCapturer capturer(shell()->web_contents());
1772 std::string script = "var iframe = document.createElement('iframe');"
1773 "iframe.src = '" + bar_url.spec() + "';"
1774 "document.body.appendChild(iframe);";
1775 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1776
1777 capturer.Wait();
1778 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1779 }
1780
1781 // TODO(creis): Check subframe entries once we create them in this case.
1782 // See https://crbug.com/608402.
1783 EXPECT_EQ(bar_url, root->child_at(0)->child_at(0)->current_url());
1784 }
1785
1574 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME 1786 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME
1575 // commits. 1787 // commits.
1576 // TODO(creis): Test updating entries for history auto subframe navigations. 1788 // TODO(creis): Test updating entries for history auto subframe navigations.
1577 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 1789 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1578 FrameNavigationEntry_AutoSubframe) { 1790 FrameNavigationEntry_AutoSubframe) {
1579 GURL main_url(embedded_test_server()->GetURL( 1791 GURL main_url(embedded_test_server()->GetURL(
1580 "/navigation_controller/simple_page_1.html")); 1792 "/navigation_controller/simple_page_1.html"));
1581 NavigateToURL(shell(), main_url); 1793 NavigateToURL(shell(), main_url);
1582 const NavigationControllerImpl& controller = 1794 const NavigationControllerImpl& controller =
1583 static_cast<const NavigationControllerImpl&>( 1795 static_cast<const NavigationControllerImpl&>(
(...skipping 2273 matching lines...) Expand 10 before | Expand all | Expand 10 after
3857 // TODO(clamy): Check the post id as well when PlzNavigate handles it 4069 // TODO(clamy): Check the post id as well when PlzNavigate handles it
3858 // properly. 4070 // properly.
3859 if (!IsBrowserSideNavigationEnabled()) 4071 if (!IsBrowserSideNavigationEnabled())
3860 EXPECT_NE(-1, frame_entry->post_id()); 4072 EXPECT_NE(-1, frame_entry->post_id());
3861 EXPECT_FALSE(entry->GetHasPostData()); 4073 EXPECT_FALSE(entry->GetHasPostData());
3862 EXPECT_EQ(-1, entry->GetPostID()); 4074 EXPECT_EQ(-1, entry->GetPostID());
3863 } 4075 }
3864 } 4076 }
3865 4077
3866 } // namespace content 4078 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698