Chromium Code Reviews

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 SubframeOnEmptyPage Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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...)
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) {
Charlie Reis 2016/05/02 22:35:34 Sorry, had to move this test below so it could use
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...)
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 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
640 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
alexmos 2016/05/03 22:07:51 While we're here - the wait doesn't seem necessary
Charlie Reis 2016/05/03 23:43:05 Done.
641 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
642 ->GetFrameTree()
643 ->root();
644
645 // Pop open a new window with no last committed entry.
646 ShellAddedObserver new_shell_observer;
647 {
648 std::string script = "window.open()";
649 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
650 }
651 Shell* new_shell = new_shell_observer.GetShell();
652 ASSERT_NE(new_shell->web_contents(), shell()->web_contents());
653 FrameTreeNode* new_root =
654 static_cast<WebContentsImpl*>(new_shell->web_contents())
655 ->GetFrameTree()
656 ->root();
657 EXPECT_FALSE(
658 new_shell->web_contents()->GetController().GetLastCommittedEntry());
659
660 // Make a new iframe in it.
661 NoNavigationsObserver observer(new_shell->web_contents());
662 {
663 LoadCommittedCapturer capturer(new_shell->web_contents());
664 std::string script = "var iframe = document.createElement('iframe');"
665 "iframe.src = 'data:text/html,<p>some page</p>';"
666 "document.body.appendChild(iframe);";
667 EXPECT_TRUE(ExecuteScript(new_root->current_frame_host(), script));
668 capturer.Wait();
669 }
670 ASSERT_EQ(1U, new_root->child_count());
671 ASSERT_NE(nullptr, new_root->child_at(0));
672
673 // Navigate it cross-site.
674 GURL frame_url = embedded_test_server()->GetURL(
675 "foo.com", "/navigation_controller/simple_page_2.html");
676 {
677 LoadCommittedCapturer capturer(new_shell->web_contents());
678 std::string script = "location.assign('" + frame_url.spec() + "')";
679 EXPECT_TRUE(
680 ExecuteScript(new_root->child_at(0)->current_frame_host(), script));
681 capturer.Wait();
682 }
683
684 // Success is not crashing, and not navigating.
685 EXPECT_EQ(nullptr,
686 new_shell->web_contents()->GetController().GetLastCommittedEntry());
687
688 // A nested iframe with a cross-site URL should also be able to commit.
689 GURL grandchild_url(embedded_test_server()->GetURL(
690 "bar.com", "/navigation_controller/simple_page_1.html"));
691 {
692 LoadCommittedCapturer capturer(new_shell->web_contents());
693 std::string script = "var iframe = document.createElement('iframe');"
694 "iframe.src = '" + grandchild_url.spec() + "';"
695 "document.body.appendChild(iframe);";
696 EXPECT_TRUE(
697 ExecuteScript(new_root->child_at(0)->current_frame_host(), script));
698 capturer.Wait();
699 }
700 ASSERT_EQ(1U, new_root->child_at(0)->child_count());
701 EXPECT_EQ(grandchild_url, new_root->child_at(0)->child_at(0)->current_url());
702 }
703
683 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 704 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
684 ErrorPageReplacement) { 705 ErrorPageReplacement) {
685 NavigationController& controller = shell()->web_contents()->GetController(); 706 NavigationController& controller = shell()->web_contents()->GetController();
686 GURL error_url( 707 GURL error_url(
687 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); 708 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET));
688 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 709 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
689 base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); 710 base::Bind(&net::URLRequestFailedJob::AddUrlHandler));
690 711
691 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 712 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
692 EXPECT_EQ(1, controller.GetEntryCount()); 713 EXPECT_EQ(1, controller.GetEntryCount());
(...skipping 871 matching lines...)
1564 " Site A ------------ proxies for B\n" 1585 " Site A ------------ proxies for B\n"
1565 " |--Site A ------- proxies for B\n" 1586 " |--Site A ------- proxies for B\n"
1566 " | +--Site A -- proxies for B\n" 1587 " | +--Site A -- proxies for B\n"
1567 " +--Site B ------- proxies for A\n" 1588 " +--Site B ------- proxies for A\n"
1568 "Where A = http://127.0.0.1/\n" 1589 "Where A = http://127.0.0.1/\n"
1569 " B = http://foo.com/", 1590 " B = http://foo.com/",
1570 visualizer.DepictFrameTree(root)); 1591 visualizer.DepictFrameTree(root));
1571 } 1592 }
1572 } 1593 }
1573 1594
1595 // Verify the tree of FrameNavigationEntries when a nested iframe commits inside
1596 // the initial blank page of a loading iframe.
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 NavigateToURL(shell(), main_url);
alexmos 2016/05/03 22:07:51 nit: EXPECT_TRUE (in all tests)
Charlie Reis 2016/05/03 23:43:05 Done.
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.
1640 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1641 FrameNavigationEntry_NoCommitNestedAutoSubframe) {
1642 GURL main_url(embedded_test_server()->GetURL(
1643 "/navigation_controller/simple_page_1.html"));
1644 NavigateToURL(shell(), main_url);
1645 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1646 ->GetFrameTree()
1647 ->root();
1648
1649 // 1. Create a iframe with a URL that doesn't commit.
1650 GURL no_commit_url(embedded_test_server()->GetURL("/nocontent"));
1651 {
1652 std::string script = "var iframe = document.createElement('iframe');"
1653 "iframe.src = '" + no_commit_url.spec() + "';"
1654 "document.body.appendChild(iframe);";
1655 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1656 }
1657 EXPECT_EQ(GURL(), root->child_at(0)->current_url());
1658
1659 // 2. A nested iframe with a cross-site URL should be able to commit.
1660 GURL foo_url(embedded_test_server()->GetURL(
1661 "foo.com", "/navigation_controller/simple_page_1.html"));
1662 {
1663 LoadCommittedCapturer capturer(shell()->web_contents());
1664 std::string script = "var iframe = document.createElement('iframe');"
1665 "iframe.src = '" + foo_url.spec() + "';"
1666 "document.body.appendChild(iframe);";
1667 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1668 capturer.Wait();
1669 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1670 }
1671
1672 // TODO(creis): Check subframe entries once we create them in this case.
1673 // See https://crbug.com/608402.
1674 EXPECT_EQ(foo_url, root->child_at(0)->child_at(0)->current_url());
1675 }
1676
1677 // Verify the tree of FrameNavigationEntries when a nested iframe commits after
1678 // going back in-page, in which case its parent might not have been in the
1679 // NavigationEntry.
1680 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1681 FrameNavigationEntry_BackNestedAutoSubframe) {
1682 GURL main_url(embedded_test_server()->GetURL(
1683 "/navigation_controller/simple_page_1.html"));
1684 NavigateToURL(shell(), main_url);
1685 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1686 ->GetFrameTree()
1687 ->root();
1688
1689 // 1. Navigate in-page.
1690 {
1691 FrameNavigateParamsCapturer capturer(root);
1692 std::string script = "history.pushState({}, 'foo', 'foo')";
1693 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1694 capturer.Wait();
1695 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
1696 EXPECT_TRUE(capturer.details().is_in_page);
1697 }
1698
1699 // 2. Create an iframe.
1700 GURL child_url(embedded_test_server()->GetURL(
1701 "/navigation_controller/simple_page_2.html"));
1702 {
1703 LoadCommittedCapturer capturer(shell()->web_contents());
1704 std::string script = "var iframe = document.createElement('iframe');"
1705 "iframe.src = '" + child_url.spec() + "';"
1706 "document.body.appendChild(iframe);";
1707 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1708 capturer.Wait();
1709 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1710 }
1711
1712 // 3. Go back in-page.
1713 {
1714 TestNavigationObserver back_load_observer(shell()->web_contents());
1715 shell()->web_contents()->GetController().GoBack();
1716 back_load_observer.Wait();
1717 }
1718
1719 // 4. A nested iframe with a cross-site URL should be able to commit.
1720 GURL grandchild_url(embedded_test_server()->GetURL(
1721 "foo.com", "/navigation_controller/simple_page_1.html"));
1722 {
1723 LoadCommittedCapturer capturer(shell()->web_contents());
1724 std::string script = "var iframe = document.createElement('iframe');"
1725 "iframe.src = '" + grandchild_url.spec() + "';"
1726 "document.body.appendChild(iframe);";
1727 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1728 capturer.Wait();
1729 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1730 }
1731
1732 // TODO(creis): Check subframe entries once we create them in this case.
1733 // See https://crbug.com/608402.
1734 EXPECT_EQ(grandchild_url, root->child_at(0)->child_at(0)->current_url());
1735 }
1736
1737 // Verify the tree of FrameNavigationEntries when a nested iframe commits after
1738 // its parent changes its name, in which case we might not find the parent
1739 // FrameNavigationEntry.
alexmos 2016/05/03 22:07:51 Would it be useful to also reference the crash bug
Charlie Reis 2016/05/03 23:43:05 Yep. 603245 was due to the back/forward CL and is
1740 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1741 FrameNavigationEntry_RenameNestedAutoSubframe) {
1742 GURL main_url(embedded_test_server()->GetURL(
1743 "/navigation_controller/simple_page_1.html"));
1744 NavigateToURL(shell(), main_url);
1745 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1746 ->GetFrameTree()
1747 ->root();
1748
1749 // 1. Create an iframe.
1750 GURL child_url(embedded_test_server()->GetURL(
1751 "/navigation_controller/simple_page_2.html"));
1752 {
1753 LoadCommittedCapturer capturer(shell()->web_contents());
1754 std::string script = "var iframe = document.createElement('iframe');"
1755 "iframe.src = '" + child_url.spec() + "';"
1756 "document.body.appendChild(iframe);";
1757 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
1758 capturer.Wait();
1759 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1760 }
1761
1762 // 2. Change the iframe's name.
1763 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(),
1764 "window.name = 'foo';"));
1765
1766 // 3. A nested iframe with a cross-site URL should be able to commit.
1767 GURL bar_url(embedded_test_server()->GetURL(
1768 "bar.com", "/navigation_controller/simple_page_1.html"));
1769 {
1770 LoadCommittedCapturer capturer(shell()->web_contents());
1771 std::string script = "var iframe = document.createElement('iframe');"
1772 "iframe.src = '" + bar_url.spec() + "';"
1773 "document.body.appendChild(iframe);";
1774 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
1775
1776 capturer.Wait();
alexmos 2016/05/03 22:07:51 There are a lot of these create-frame-and-wait blo
Charlie Reis 2016/05/03 23:43:05 Yeah, it's a bit of a tradeoff. I tried switching
alexmos 2016/05/03 23:52:40 Acknowledged.
1777 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1778 }
1779
1780 // TODO(creis): Check subframe entries once we create them in this case.
1781 // See https://crbug.com/608402.
1782 EXPECT_EQ(bar_url, root->child_at(0)->child_at(0)->current_url());
1783 }
1784
1574 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME 1785 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME
1575 // commits. 1786 // commits.
1576 // TODO(creis): Test updating entries for history auto subframe navigations. 1787 // TODO(creis): Test updating entries for history auto subframe navigations.
1577 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 1788 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1578 FrameNavigationEntry_AutoSubframe) { 1789 FrameNavigationEntry_AutoSubframe) {
1579 GURL main_url(embedded_test_server()->GetURL( 1790 GURL main_url(embedded_test_server()->GetURL(
1580 "/navigation_controller/simple_page_1.html")); 1791 "/navigation_controller/simple_page_1.html"));
1581 NavigateToURL(shell(), main_url); 1792 NavigateToURL(shell(), main_url);
1582 const NavigationControllerImpl& controller = 1793 const NavigationControllerImpl& controller =
1583 static_cast<const NavigationControllerImpl&>( 1794 static_cast<const NavigationControllerImpl&>(
(...skipping 2273 matching lines...)
3857 // TODO(clamy): Check the post id as well when PlzNavigate handles it 4068 // TODO(clamy): Check the post id as well when PlzNavigate handles it
3858 // properly. 4069 // properly.
3859 if (!IsBrowserSideNavigationEnabled()) 4070 if (!IsBrowserSideNavigationEnabled())
3860 EXPECT_NE(-1, frame_entry->post_id()); 4071 EXPECT_NE(-1, frame_entry->post_id());
3861 EXPECT_FALSE(entry->GetHasPostData()); 4072 EXPECT_FALSE(entry->GetHasPostData());
3862 EXPECT_EQ(-1, entry->GetPostID()); 4073 EXPECT_EQ(-1, entry->GetPostID());
3863 } 4074 }
3864 } 4075 }
3865 4076
3866 } // namespace content 4077 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_impl.cc » ('j') | content/browser/frame_host/navigator_impl.cc » ('J')

Powered by Google App Engine