OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/browser/frame_host/cross_site_transferring_request.h" | 9 #include "content/browser/frame_host/cross_site_transferring_request.h" |
10 #include "content/browser/frame_host/navigation_before_commit_info.h" | 10 #include "content/browser/frame_host/navigation_before_commit_info.h" |
11 #include "content/browser/frame_host/navigation_controller_impl.h" | 11 #include "content/browser/frame_host/navigation_controller_impl.h" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 13 #include "content/browser/frame_host/navigation_parameters.h" |
13 #include "content/browser/frame_host/navigation_request.h" | 14 #include "content/browser/frame_host/navigation_request.h" |
14 #include "content/browser/frame_host/navigator.h" | 15 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/navigator_impl.h" | 16 #include "content/browser/frame_host/navigator_impl.h" |
16 #include "content/browser/frame_host/render_frame_host_manager.h" | 17 #include "content/browser/frame_host/render_frame_host_manager.h" |
17 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 19 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
19 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_widget_host_iterator.h" | 26 #include "content/public/browser/render_widget_host_iterator.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/browser/web_contents_observer.h" | 28 #include "content/public/browser/web_contents_observer.h" |
28 #include "content/public/browser/web_ui_controller.h" | 29 #include "content/public/browser/web_ui_controller.h" |
29 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
30 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
31 #include "content/public/common/javascript_message_type.h" | 32 #include "content/public/common/javascript_message_type.h" |
32 #include "content/public/common/page_transition_types.h" | 33 #include "content/public/common/page_transition_types.h" |
33 #include "content/public/common/url_constants.h" | 34 #include "content/public/common/url_constants.h" |
34 #include "content/public/common/url_utils.h" | 35 #include "content/public/common/url_utils.h" |
35 #include "content/public/test/mock_render_process_host.h" | 36 #include "content/public/test/mock_render_process_host.h" |
36 #include "content/public/test/test_notification_tracker.h" | 37 #include "content/public/test/test_notification_tracker.h" |
37 #include "content/test/test_content_browser_client.h" | 38 #include "content/test/test_content_browser_client.h" |
38 #include "content/test/test_content_client.h" | 39 #include "content/test/test_content_client.h" |
39 #include "content/test/test_render_frame_host.h" | 40 #include "content/test/test_render_frame_host.h" |
40 #include "content/test/test_render_view_host.h" | 41 #include "content/test/test_render_view_host.h" |
41 #include "content/test/test_web_contents.h" | 42 #include "content/test/test_web_contents.h" |
| 43 #include "net/base/load_flags.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
43 | 45 |
44 namespace content { | 46 namespace content { |
45 namespace { | 47 namespace { |
46 | 48 |
47 class RenderFrameHostManagerTestWebUIControllerFactory | 49 class RenderFrameHostManagerTestWebUIControllerFactory |
48 : public WebUIControllerFactory { | 50 : public WebUIControllerFactory { |
49 public: | 51 public: |
50 RenderFrameHostManagerTestWebUIControllerFactory() | 52 RenderFrameHostManagerTestWebUIControllerFactory() |
51 : should_create_webui_(false) { | 53 : should_create_webui_(false) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 382 |
381 NavigationRequest* GetNavigationRequestForRenderFrameManager( | 383 NavigationRequest* GetNavigationRequestForRenderFrameManager( |
382 RenderFrameHostManager* manager) const { | 384 RenderFrameHostManager* manager) const { |
383 return manager->navigation_request_for_testing(); | 385 return manager->navigation_request_for_testing(); |
384 } | 386 } |
385 | 387 |
386 void EnableBrowserSideNavigation() { | 388 void EnableBrowserSideNavigation() { |
387 CommandLine::ForCurrentProcess()->AppendSwitch( | 389 CommandLine::ForCurrentProcess()->AppendSwitch( |
388 switches::kEnableBrowserSideNavigation); | 390 switches::kEnableBrowserSideNavigation); |
389 } | 391 } |
| 392 |
| 393 void SendRequestNavigation(const GURL& url, |
| 394 FrameTreeNode* node) { |
| 395 SendRequestNavigationWithParameters( |
| 396 url, node, Referrer(), PAGE_TRANSITION_LINK, |
| 397 NavigationController::NO_RELOAD); |
| 398 } |
| 399 |
| 400 void SendRequestNavigationWithParameters( |
| 401 const GURL& url, |
| 402 FrameTreeNode* node, |
| 403 const Referrer& referrer, |
| 404 PageTransition transition_type, |
| 405 NavigationController::ReloadType reload_type) { |
| 406 scoped_ptr<NavigationEntryImpl> entry( |
| 407 NavigationEntryImpl::FromNavigationEntry( |
| 408 NavigationController::CreateNavigationEntry( |
| 409 url, referrer, transition_type, false, std::string(), |
| 410 controller().GetBrowserContext()))); |
| 411 NavigatorImpl* navigator = static_cast<NavigatorImpl*>(node->navigator()); |
| 412 node->render_manager()->RequestNavigation( |
| 413 scoped_ptr<NavigationParameters>( |
| 414 navigator->MakeNavigationParametersForTest(*entry, reload_type))); |
| 415 } |
| 416 |
| 417 NavigationParameters* GetNavigationParams( |
| 418 RenderFrameHostManager* manager) { |
| 419 return manager->navigation_parameters_.get(); |
| 420 } |
| 421 |
390 private: | 422 private: |
391 RenderFrameHostManagerTestWebUIControllerFactory factory_; | 423 RenderFrameHostManagerTestWebUIControllerFactory factory_; |
392 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; | 424 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; |
393 }; | 425 }; |
394 | 426 |
395 // Tests that when you navigate from a chrome:// url to another page, and | 427 // Tests that when you navigate from a chrome:// url to another page, and |
396 // then do that same thing in another tab, that the two resulting pages have | 428 // then do that same thing in another tab, that the two resulting pages have |
397 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 429 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
398 // a regression test for bug 9364. | 430 // a regression test for bug 9364. |
399 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 431 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 | 1719 |
1688 contents()->GetMainFrame()->OnMessageReceived( | 1720 contents()->GetMainFrame()->OnMessageReceived( |
1689 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1721 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1690 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1722 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1691 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1723 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
1692 } | 1724 } |
1693 } | 1725 } |
1694 | 1726 |
1695 // PlzNavigate: Test that a proper NavigationRequest is created by | 1727 // PlzNavigate: Test that a proper NavigationRequest is created by |
1696 // BeginNavigation. | 1728 // BeginNavigation. |
| 1729 // Note that all PlzNavigate methods on the browser side require the use of the |
| 1730 // flag kEnableBrowserSideNavigation. |
1697 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1731 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1698 const GURL kUrl1("http://www.google.com/"); | 1732 const GURL kUrl1("http://www.google.com/"); |
1699 const GURL kUrl2("http://www.chromium.org/"); | 1733 const GURL kUrl2("http://www.chromium.org/"); |
1700 const GURL kUrl3("http://www.gmail.com/"); | 1734 const GURL kUrl3("http://www.gmail.com/"); |
1701 | 1735 |
1702 // TODO(clamy): we should be enabling browser side navigations here | 1736 // TODO(clamy): we should be enabling browser side navigations here |
1703 // when CommitNavigation is properly implemented. | 1737 // when CommitNavigation is properly implemented. |
1704 // Navigate to the first page. | 1738 // Navigate to the first page. |
1705 contents()->NavigateAndCommit(kUrl1); | 1739 contents()->NavigateAndCommit(kUrl1); |
1706 | 1740 |
1707 EnableBrowserSideNavigation(); | 1741 EnableBrowserSideNavigation(); |
1708 // Add a subframe. | 1742 // Add a subframe. |
1709 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 1743 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
1710 contents()->GetFrameTree()->AddFrame( | 1744 contents()->GetFrameTree()->AddFrame( |
1711 contents()->GetFrameTree()->root(), 14, "Child")); | 1745 contents()->GetFrameTree()->root(), 14, "Child")); |
1712 | 1746 |
| 1747 RenderFrameHostManager* subframe_manager = |
| 1748 subframe_rfh->frame_tree_node()->render_manager(); |
| 1749 SendRequestNavigation(kUrl2, subframe_rfh->frame_tree_node()); |
1713 // Simulate a BeginNavigation IPC on the subframe. | 1750 // Simulate a BeginNavigation IPC on the subframe. |
1714 subframe_rfh->SendBeginNavigationWithURL(kUrl2); | 1751 subframe_rfh->SendBeginNavigationWithURL(kUrl2); |
1715 NavigationRequest* subframe_request = | 1752 NavigationRequest* subframe_request = |
1716 GetNavigationRequestForRenderFrameManager( | 1753 GetNavigationRequestForRenderFrameManager(subframe_manager); |
1717 subframe_rfh->frame_tree_node()->render_manager()); | |
1718 ASSERT_TRUE(subframe_request); | 1754 ASSERT_TRUE(subframe_request); |
1719 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); | 1755 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); |
1720 // First party for cookies url should be that of the main frame. | 1756 // First party for cookies url should be that of the main frame. |
1721 EXPECT_EQ( | 1757 EXPECT_EQ( |
1722 kUrl1, subframe_request->info().first_party_for_cookies); | 1758 kUrl1, subframe_request->info().first_party_for_cookies); |
1723 EXPECT_FALSE(subframe_request->info().is_main_frame); | 1759 EXPECT_FALSE(subframe_request->info().is_main_frame); |
1724 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); | 1760 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); |
1725 | 1761 |
| 1762 RenderFrameHostManager* main_frame_manager = |
| 1763 contents()->GetMainFrame()->frame_tree_node()->render_manager(); |
| 1764 SendRequestNavigation( |
| 1765 kUrl2, contents()->GetMainFrame()->frame_tree_node()); |
1726 // Simulate a BeginNavigation IPC on the main frame. | 1766 // Simulate a BeginNavigation IPC on the main frame. |
1727 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); | 1767 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); |
1728 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( | 1768 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( |
1729 contents()->GetMainFrame()->frame_tree_node()->render_manager()); | 1769 main_frame_manager); |
1730 ASSERT_TRUE(main_request); | 1770 ASSERT_TRUE(main_request); |
1731 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); | 1771 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); |
1732 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); | 1772 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); |
1733 EXPECT_TRUE(main_request->info().is_main_frame); | 1773 EXPECT_TRUE(main_request->info().is_main_frame); |
1734 EXPECT_FALSE(main_request->info().parent_is_main_frame); | 1774 EXPECT_FALSE(main_request->info().parent_is_main_frame); |
1735 } | 1775 } |
1736 | 1776 |
1737 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 1777 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
1738 // RenderFrameHost is not modified when the navigation commits. | 1778 // RenderFrameHost is not modified when the navigation commits. |
1739 TEST_F(RenderFrameHostManagerTest, | 1779 TEST_F(RenderFrameHostManagerTest, |
1740 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 1780 BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
1741 const GURL kUrl("http://www.google.com/"); | 1781 const GURL kUrl("http://www.google.com/"); |
1742 | 1782 |
1743 EnableBrowserSideNavigation(); | 1783 EnableBrowserSideNavigation(); |
1744 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1784 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1745 contents()->GetController().LoadURL( | |
1746 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1747 RenderFrameHostManager* render_manager = | 1785 RenderFrameHostManager* render_manager = |
1748 main_test_rfh()->frame_tree_node()->render_manager(); | 1786 main_test_rfh()->frame_tree_node()->render_manager(); |
| 1787 SendRequestNavigation(kUrl, main_test_rfh()->frame_tree_node()); |
1749 NavigationRequest* main_request = | 1788 NavigationRequest* main_request = |
1750 GetNavigationRequestForRenderFrameManager(render_manager); | 1789 GetNavigationRequestForRenderFrameManager(render_manager); |
1751 // A NavigationRequest should have been generated. | 1790 // A NavigationRequest should have been generated. |
1752 EXPECT_TRUE(main_request != NULL); | 1791 EXPECT_TRUE(main_request != NULL); |
1753 RenderFrameHostImpl* rfh = main_test_rfh(); | 1792 RenderFrameHostImpl* rfh = main_test_rfh(); |
1754 | 1793 |
1755 // Now commit the same url. | 1794 // Now commit the same url. |
1756 NavigationBeforeCommitInfo commit_info; | 1795 NavigationBeforeCommitInfo commit_info; |
1757 commit_info.navigation_url = kUrl; | 1796 commit_info.navigation_url = kUrl; |
1758 render_manager->CommitNavigation(commit_info); | 1797 render_manager->CommitNavigation(commit_info); |
(...skipping 17 matching lines...) Expand all Loading... |
1776 // Navigate to the first page. | 1815 // Navigate to the first page. |
1777 contents()->NavigateAndCommit(kUrl1); | 1816 contents()->NavigateAndCommit(kUrl1); |
1778 TestRenderViewHost* rvh1 = test_rvh(); | 1817 TestRenderViewHost* rvh1 = test_rvh(); |
1779 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | 1818 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); |
1780 RenderFrameHostImpl* rfh = main_test_rfh(); | 1819 RenderFrameHostImpl* rfh = main_test_rfh(); |
1781 RenderFrameHostManager* render_manager = | 1820 RenderFrameHostManager* render_manager = |
1782 main_test_rfh()->frame_tree_node()->render_manager(); | 1821 main_test_rfh()->frame_tree_node()->render_manager(); |
1783 | 1822 |
1784 EnableBrowserSideNavigation(); | 1823 EnableBrowserSideNavigation(); |
1785 // Navigate to a different site. | 1824 // Navigate to a different site. |
| 1825 SendRequestNavigation(kUrl2, main_test_rfh()->frame_tree_node()); |
1786 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 1826 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
1787 NavigationRequest* main_request = | 1827 NavigationRequest* main_request = |
1788 GetNavigationRequestForRenderFrameManager(render_manager); | 1828 GetNavigationRequestForRenderFrameManager(render_manager); |
1789 ASSERT_TRUE(main_request); | 1829 ASSERT_TRUE(main_request); |
1790 | 1830 |
1791 NavigationBeforeCommitInfo commit_info; | 1831 NavigationBeforeCommitInfo commit_info; |
1792 commit_info.navigation_url = kUrl2; | 1832 commit_info.navigation_url = kUrl2; |
1793 render_manager->CommitNavigation(commit_info); | 1833 render_manager->CommitNavigation(commit_info); |
1794 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | 1834 main_request = GetNavigationRequestForRenderFrameManager(render_manager); |
1795 EXPECT_NE(main_test_rfh(), rfh); | 1835 EXPECT_NE(main_test_rfh(), rfh); |
1796 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1836 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1797 } | 1837 } |
1798 | 1838 |
| 1839 // PlzNavigate: Test that a reload navigation is properly signaled to the |
| 1840 // renderer when the navigation can commit. |
| 1841 TEST_F(RenderFrameHostManagerTest, |
| 1842 BrowserSideNavigationReload) { |
| 1843 const GURL kUrl("http://www.google.com/"); |
| 1844 contents()->NavigateAndCommit(kUrl); |
| 1845 |
| 1846 EnableBrowserSideNavigation(); |
| 1847 RenderFrameHostManager* render_manager = |
| 1848 main_test_rfh()->frame_tree_node()->render_manager(); |
| 1849 SendRequestNavigationWithParameters( |
| 1850 kUrl, main_test_rfh()->frame_tree_node(), Referrer(), |
| 1851 PAGE_TRANSITION_LINK, NavigationController::RELOAD); |
| 1852 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
| 1853 // A NavigationRequest should have been generated. |
| 1854 NavigationRequest* main_request = |
| 1855 GetNavigationRequestForRenderFrameManager(render_manager); |
| 1856 ASSERT_TRUE(main_request != NULL); |
| 1857 // Navigation parameters should have been generated. |
| 1858 NavigationParameters* navigation_parameters = |
| 1859 GetNavigationParams(render_manager); |
| 1860 ASSERT_TRUE(navigation_parameters != NULL); |
| 1861 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, |
| 1862 navigation_parameters->navigation_type_for_testing()); |
| 1863 int page_id = contents()->GetMaxPageIDForSiteInstance( |
| 1864 main_test_rfh()->GetSiteInstance()) + 1; |
| 1865 main_test_rfh()->SendNavigate(page_id, kUrl); |
| 1866 |
| 1867 // Now do a shift+reload. |
| 1868 SendRequestNavigationWithParameters( |
| 1869 kUrl, main_test_rfh()->frame_tree_node(), Referrer(), |
| 1870 PAGE_TRANSITION_LINK, NavigationController::RELOAD_IGNORING_CACHE); |
| 1871 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
| 1872 // A NavigationRequest should have been generated. |
| 1873 main_request = |
| 1874 GetNavigationRequestForRenderFrameManager(render_manager); |
| 1875 ASSERT_TRUE(main_request != NULL); |
| 1876 // Navigation parameters should have been generated. |
| 1877 navigation_parameters = |
| 1878 GetNavigationParams(render_manager); |
| 1879 ASSERT_TRUE(navigation_parameters != NULL); |
| 1880 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
| 1881 navigation_parameters->navigation_type_for_testing()); |
| 1882 page_id = contents()->GetMaxPageIDForSiteInstance( |
| 1883 main_test_rfh()->GetSiteInstance()) + 1; |
| 1884 main_test_rfh()->SendNavigate(page_id, kUrl); |
| 1885 } |
| 1886 |
1799 } // namespace content | 1887 } // namespace content |
OLD | NEW |