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" | |
11 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
13 #include "content/browser/frame_host/navigation_request.h" | 12 #include "content/browser/frame_host/navigation_request.h" |
14 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/navigator_impl.h" | 14 #include "content/browser/frame_host/navigator_impl.h" |
16 #include "content/browser/frame_host/render_frame_host_manager.h" | 15 #include "content/browser/frame_host/render_frame_host_manager.h" |
16 #include "content/browser/loader/navigation_url_loader.h" | |
17 #include "content/browser/loader/navigation_url_loader_factory.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" |
27 #include "content/public/browser/stream_handle.h" | |
26 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
28 #include "content/public/browser/web_ui_controller.h" | 30 #include "content/public/browser/web_ui_controller.h" |
29 #include "content/public/common/bindings_policy.h" | 31 #include "content/public/common/bindings_policy.h" |
30 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
31 #include "content/public/common/javascript_message_type.h" | 33 #include "content/public/common/javascript_message_type.h" |
32 #include "content/public/common/page_transition_types.h" | 34 #include "content/public/common/page_transition_types.h" |
35 #include "content/public/common/resource_response.h" | |
33 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
34 #include "content/public/common/url_utils.h" | 37 #include "content/public/common/url_utils.h" |
35 #include "content/public/test/mock_render_process_host.h" | 38 #include "content/public/test/mock_render_process_host.h" |
36 #include "content/public/test/test_notification_tracker.h" | 39 #include "content/public/test/test_notification_tracker.h" |
37 #include "content/test/test_content_browser_client.h" | 40 #include "content/test/test_content_browser_client.h" |
38 #include "content/test/test_content_client.h" | 41 #include "content/test/test_content_client.h" |
39 #include "content/test/test_render_frame_host.h" | 42 #include "content/test/test_render_frame_host.h" |
40 #include "content/test/test_render_view_host.h" | 43 #include "content/test/test_render_view_host.h" |
41 #include "content/test/test_web_contents.h" | 44 #include "content/test/test_web_contents.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 return base::StringPrintf( | 249 return base::StringPrintf( |
247 "(%d, %d -> %s )", | 250 "(%d, %d -> %s )", |
248 render_frame_host->GetProcess()->GetID(), | 251 render_frame_host->GetProcess()->GetID(), |
249 render_frame_host->GetRoutingID(), | 252 render_frame_host->GetRoutingID(), |
250 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); | 253 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); |
251 } | 254 } |
252 std::set<std::pair<int, int> > live_routes_; | 255 std::set<std::pair<int, int> > live_routes_; |
253 std::set<std::pair<int, int> > deleted_routes_; | 256 std::set<std::pair<int, int> > deleted_routes_; |
254 }; | 257 }; |
255 | 258 |
259 class TestNavigationURLLoader : public NavigationURLLoader { | |
260 public: | |
261 TestNavigationURLLoader(BrowserContext* browser_context, | |
262 int64 frame_tree_node_id, | |
263 const NavigationRequestInfo& request_info, | |
264 ResourceRequestBody* request_body, | |
265 NavigationURLLoader::Delegate* delegate) | |
266 : delegate_(delegate) { | |
267 } | |
268 | |
269 virtual ~TestNavigationURLLoader() { | |
270 // Record the number of times a loader was canceled before ResponseStarted | |
271 // or RequestFailed was returned. | |
272 if (delegate_) | |
273 cancel_count_++; | |
274 } | |
275 | |
276 // NavigationURLLoader implementation. | |
277 virtual void FollowRedirect() OVERRIDE { } | |
278 | |
279 void CallOnResponseStarted(ResourceResponse* response, | |
280 scoped_ptr<StreamHandle> body) { | |
281 delegate_->OnResponseStarted(response, body.Pass()); | |
282 delegate_ = NULL; | |
283 } | |
284 | |
285 static int cancel_count() { return cancel_count_; } | |
286 | |
287 private: | |
288 static int cancel_count_; | |
289 NavigationURLLoader::Delegate* delegate_; | |
290 }; | |
291 | |
292 int TestNavigationURLLoader::cancel_count_ = 0; | |
293 | |
294 class TestNavigationURLLoaderFactory : public NavigationURLLoaderFactory { | |
295 public: | |
296 // NavigationURLLoaderFactory implementation. | |
297 virtual NavigationURLLoader* CreateLoader( | |
298 BrowserContext* browser_context, | |
299 int64 frame_tree_node_id, | |
300 const NavigationRequestInfo& request_info, | |
301 ResourceRequestBody* request_body, | |
302 NavigationURLLoader::Delegate* delegate) OVERRIDE { | |
303 return new TestNavigationURLLoader( | |
304 browser_context, frame_tree_node_id, request_info, request_body, | |
305 delegate); | |
306 } | |
307 }; | |
308 | |
256 } // namespace | 309 } // namespace |
257 | 310 |
258 class RenderFrameHostManagerTest | 311 class RenderFrameHostManagerTest |
259 : public RenderViewHostImplTestHarness { | 312 : public RenderViewHostImplTestHarness { |
260 public: | 313 public: |
261 virtual void SetUp() OVERRIDE { | 314 virtual void SetUp() OVERRIDE { |
262 RenderViewHostImplTestHarness::SetUp(); | 315 RenderViewHostImplTestHarness::SetUp(); |
263 WebUIControllerFactory::RegisterFactory(&factory_); | 316 WebUIControllerFactory::RegisterFactory(&factory_); |
264 lifetime_checker_.reset(new FrameLifetimeConsistencyChecker(contents())); | 317 lifetime_checker_.reset(new FrameLifetimeConsistencyChecker(contents())); |
318 loader_factory_.reset(new TestNavigationURLLoaderFactory); | |
319 NavigationURLLoader::SetFactoryForTesting(loader_factory_.get()); | |
265 } | 320 } |
266 | 321 |
267 virtual void TearDown() OVERRIDE { | 322 virtual void TearDown() OVERRIDE { |
323 NavigationURLLoader::SetFactoryForTesting(NULL); | |
324 loader_factory_.reset(); | |
268 lifetime_checker_.reset(); | 325 lifetime_checker_.reset(); |
269 RenderViewHostImplTestHarness::TearDown(); | 326 RenderViewHostImplTestHarness::TearDown(); |
270 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 327 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
271 } | 328 } |
272 | 329 |
273 void set_should_create_webui(bool should_create_webui) { | 330 void set_should_create_webui(bool should_create_webui) { |
274 factory_.set_should_create_webui(should_create_webui); | 331 factory_.set_should_create_webui(should_create_webui); |
275 } | 332 } |
276 | 333 |
277 void NavigateActiveAndCommit(const GURL& url) { | 334 void NavigateActiveAndCommit(const GURL& url) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 433 |
377 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut()); | 434 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut()); |
378 return ntp_rfh->GetRenderViewHost(); | 435 return ntp_rfh->GetRenderViewHost(); |
379 } | 436 } |
380 | 437 |
381 NavigationRequest* GetNavigationRequestForRenderFrameManager( | 438 NavigationRequest* GetNavigationRequestForRenderFrameManager( |
382 RenderFrameHostManager* manager) const { | 439 RenderFrameHostManager* manager) const { |
383 return manager->navigation_request_for_testing(); | 440 return manager->navigation_request_for_testing(); |
384 } | 441 } |
385 | 442 |
443 TestNavigationURLLoader* GetLoaderForNavigationRequest( | |
444 NavigationRequest* request) const { | |
445 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
446 } | |
447 | |
386 void EnableBrowserSideNavigation() { | 448 void EnableBrowserSideNavigation() { |
387 CommandLine::ForCurrentProcess()->AppendSwitch( | 449 CommandLine::ForCurrentProcess()->AppendSwitch( |
388 switches::kEnableBrowserSideNavigation); | 450 switches::kEnableBrowserSideNavigation); |
389 } | 451 } |
390 private: | 452 private: |
391 RenderFrameHostManagerTestWebUIControllerFactory factory_; | 453 RenderFrameHostManagerTestWebUIControllerFactory factory_; |
392 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; | 454 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; |
455 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; | |
393 }; | 456 }; |
394 | 457 |
395 // Tests that when you navigate from a chrome:// url to another page, and | 458 // 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 | 459 // then do that same thing in another tab, that the two resulting pages have |
397 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 460 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
398 // a regression test for bug 9364. | 461 // a regression test for bug 9364. |
399 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 462 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
400 set_should_create_webui(true); | 463 set_should_create_webui(true); |
401 const GURL kChromeUrl("chrome://foo"); | 464 const GURL kChromeUrl("chrome://foo"); |
402 const GURL kDestUrl("http://www.google.com/"); | 465 const GURL kDestUrl("http://www.google.com/"); |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1691 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1754 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
1692 } | 1755 } |
1693 } | 1756 } |
1694 | 1757 |
1695 // PlzNavigate: Test that a proper NavigationRequest is created by | 1758 // PlzNavigate: Test that a proper NavigationRequest is created by |
1696 // BeginNavigation. | 1759 // BeginNavigation. |
1697 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1760 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1698 const GURL kUrl1("http://www.google.com/"); | 1761 const GURL kUrl1("http://www.google.com/"); |
1699 const GURL kUrl2("http://www.chromium.org/"); | 1762 const GURL kUrl2("http://www.chromium.org/"); |
1700 const GURL kUrl3("http://www.gmail.com/"); | 1763 const GURL kUrl3("http://www.gmail.com/"); |
1701 const int64 kFirstNavRequestID = 1; | |
1702 | 1764 |
1703 // TODO(clamy): we should be enabling browser side navigations here | 1765 // TODO(clamy): we should be enabling browser side navigations here |
1704 // when CommitNavigation is properly implemented. | 1766 // when CommitNavigation is properly implemented. |
1705 // Navigate to the first page. | 1767 // Navigate to the first page. |
1706 contents()->NavigateAndCommit(kUrl1); | 1768 contents()->NavigateAndCommit(kUrl1); |
1707 | 1769 |
1708 EnableBrowserSideNavigation(); | 1770 EnableBrowserSideNavigation(); |
1709 // Add a subframe. | 1771 // Add a subframe. |
1710 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 1772 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
1711 contents()->GetFrameTree()->AddFrame( | 1773 contents()->GetFrameTree()->AddFrame( |
1712 contents()->GetFrameTree()->root(), 14, "Child")); | 1774 contents()->GetFrameTree()->root(), 14, "Child")); |
1713 | 1775 |
1714 // Simulate a BeginNavigation IPC on the subframe. | 1776 // Simulate a BeginNavigation IPC on the subframe. |
1715 subframe_rfh->SendBeginNavigationWithURL(kUrl2); | 1777 subframe_rfh->SendBeginNavigationWithURL(kUrl2); |
1716 NavigationRequest* subframe_request = | 1778 NavigationRequest* subframe_request = |
1717 GetNavigationRequestForRenderFrameManager( | 1779 GetNavigationRequestForRenderFrameManager( |
1718 subframe_rfh->frame_tree_node()->render_manager()); | 1780 subframe_rfh->frame_tree_node()->render_manager()); |
1719 ASSERT_TRUE(subframe_request); | 1781 ASSERT_TRUE(subframe_request); |
1720 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); | 1782 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); |
1721 // First party for cookies url should be that of the main frame. | 1783 // First party for cookies url should be that of the main frame. |
1722 EXPECT_EQ( | 1784 EXPECT_EQ( |
1723 kUrl1, subframe_request->info().first_party_for_cookies); | 1785 kUrl1, subframe_request->info().first_party_for_cookies); |
1724 EXPECT_FALSE(subframe_request->info().is_main_frame); | 1786 EXPECT_FALSE(subframe_request->info().is_main_frame); |
1725 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); | 1787 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); |
1726 EXPECT_EQ(kFirstNavRequestID, subframe_request->navigation_request_id()); | |
1727 | 1788 |
1728 // Simulate a BeginNavigation IPC on the main frame. | 1789 // Simulate a BeginNavigation IPC on the main frame. |
1729 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); | 1790 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); |
1730 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( | 1791 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( |
1731 contents()->GetMainFrame()->frame_tree_node()->render_manager()); | 1792 contents()->GetMainFrame()->frame_tree_node()->render_manager()); |
1732 ASSERT_TRUE(main_request); | 1793 ASSERT_TRUE(main_request); |
1733 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); | 1794 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); |
1734 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); | 1795 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); |
1735 EXPECT_TRUE(main_request->info().is_main_frame); | 1796 EXPECT_TRUE(main_request->info().is_main_frame); |
1736 EXPECT_FALSE(main_request->info().parent_is_main_frame); | 1797 EXPECT_FALSE(main_request->info().parent_is_main_frame); |
1737 EXPECT_EQ(kFirstNavRequestID + 1, main_request->navigation_request_id()); | |
1738 } | 1798 } |
1739 | 1799 |
1740 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 1800 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
1741 // RenderFrameHost is not modified when the navigation commits. | 1801 // RenderFrameHost is not modified when the navigation commits. |
1742 TEST_F(RenderFrameHostManagerTest, | 1802 TEST_F(RenderFrameHostManagerTest, |
1743 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 1803 BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
1744 const GURL kUrl("http://www.google.com/"); | 1804 const GURL kUrl("http://www.google.com/"); |
1745 | 1805 |
1746 EnableBrowserSideNavigation(); | 1806 EnableBrowserSideNavigation(); |
1747 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1807 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1748 contents()->GetController().LoadURL( | 1808 contents()->GetController().LoadURL( |
1749 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1809 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
1750 RenderFrameHostManager* render_manager = | 1810 RenderFrameHostManager* render_manager = |
1751 main_test_rfh()->frame_tree_node()->render_manager(); | 1811 main_test_rfh()->frame_tree_node()->render_manager(); |
1752 NavigationRequest* main_request = | 1812 NavigationRequest* main_request = |
1753 GetNavigationRequestForRenderFrameManager(render_manager); | 1813 GetNavigationRequestForRenderFrameManager(render_manager); |
1754 // A NavigationRequest should have been generated. | 1814 // A NavigationRequest should have been generated. |
1755 EXPECT_TRUE(main_request != NULL); | 1815 EXPECT_TRUE(main_request != NULL); |
1756 RenderFrameHostImpl* rfh = main_test_rfh(); | 1816 RenderFrameHostImpl* rfh = main_test_rfh(); |
1757 | 1817 |
1758 // Now commit the same url. | 1818 // Now commit the same url. |
1759 NavigationBeforeCommitInfo commit_info; | 1819 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
1760 commit_info.navigation_url = kUrl; | 1820 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
1761 commit_info.navigation_request_id = main_request->navigation_request_id(); | 1821 response.get(), scoped_ptr<StreamHandle>()); |
1762 render_manager->CommitNavigation(commit_info); | |
1763 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | |
1764 | 1822 |
1765 // The main RFH should not have been changed, and the renderer should have | 1823 // The main RFH should not have been changed, and the renderer should have |
1766 // been initialized. | 1824 // been initialized. |
1767 EXPECT_EQ(rfh, main_test_rfh()); | 1825 EXPECT_EQ(rfh, main_test_rfh()); |
1768 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1826 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1769 } | 1827 } |
1770 | 1828 |
1771 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 1829 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
1772 // site navigation. | 1830 // site navigation. |
1773 TEST_F(RenderFrameHostManagerTest, | 1831 TEST_F(RenderFrameHostManagerTest, |
(...skipping 11 matching lines...) Expand all Loading... | |
1785 RenderFrameHostManager* render_manager = | 1843 RenderFrameHostManager* render_manager = |
1786 main_test_rfh()->frame_tree_node()->render_manager(); | 1844 main_test_rfh()->frame_tree_node()->render_manager(); |
1787 | 1845 |
1788 EnableBrowserSideNavigation(); | 1846 EnableBrowserSideNavigation(); |
1789 // Navigate to a different site. | 1847 // Navigate to a different site. |
1790 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 1848 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
1791 NavigationRequest* main_request = | 1849 NavigationRequest* main_request = |
1792 GetNavigationRequestForRenderFrameManager(render_manager); | 1850 GetNavigationRequestForRenderFrameManager(render_manager); |
1793 ASSERT_TRUE(main_request); | 1851 ASSERT_TRUE(main_request); |
1794 | 1852 |
1795 NavigationBeforeCommitInfo commit_info; | 1853 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
1796 commit_info.navigation_url = kUrl2; | 1854 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
1797 commit_info.navigation_request_id = main_request->navigation_request_id(); | 1855 response.get(), scoped_ptr<StreamHandle>()); |
1798 render_manager->CommitNavigation(commit_info); | |
1799 EXPECT_NE(main_test_rfh(), rfh); | 1856 EXPECT_NE(main_test_rfh(), rfh); |
1800 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1857 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1801 } | 1858 } |
1802 | 1859 |
1803 // PlzNavigate: Test that a navigation commit is ignored if another request has | 1860 // PlzNavigate: Test that a navigation is cancelled if another request has been |
1804 // been issued in the meantime. | 1861 // issued in the meantime. |
1805 // TODO(carlosk): add checks to assert that the cancel call was sent to | |
1806 // ResourceDispatcherHost in the IO thread by extending | |
1807 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc | |
1808 // and plugin_browsertest.cc). | |
1809 TEST_F(RenderFrameHostManagerTest, | 1862 TEST_F(RenderFrameHostManagerTest, |
1810 BrowserSideNavigationIgnoreStaleNavigationCommit) { | 1863 BrowserSideNavigationReplacePendingNavigation) { |
1811 const GURL kUrl0("http://www.wikipedia.org/"); | 1864 const GURL kUrl0("http://www.wikipedia.org/"); |
1812 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); | 1865 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
1813 const GURL kUrl1("http://www.chromium.org/"); | 1866 const GURL kUrl1("http://www.chromium.org/"); |
1814 const GURL kUrl2("http://www.google.com/"); | 1867 const GURL kUrl2("http://www.google.com/"); |
1815 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); | 1868 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); |
1816 | 1869 |
1817 // Initialization. | 1870 // Initialization. |
1818 contents()->NavigateAndCommit(kUrl0); | 1871 contents()->NavigateAndCommit(kUrl0); |
1819 RenderFrameHostManager* render_manager = | 1872 RenderFrameHostManager* render_manager = |
1820 main_test_rfh()->frame_tree_node()->render_manager(); | 1873 main_test_rfh()->frame_tree_node()->render_manager(); |
1821 EnableBrowserSideNavigation(); | 1874 EnableBrowserSideNavigation(); |
1822 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1875 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1823 | 1876 |
1824 // Request navigation to the 1st URL and gather data. | 1877 // Request navigation to the 1st URL and gather data. |
1825 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); | 1878 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
1826 NavigationRequest* request1 = | 1879 NavigationRequest* request1 = |
1827 GetNavigationRequestForRenderFrameManager(render_manager); | 1880 GetNavigationRequestForRenderFrameManager(render_manager); |
1828 ASSERT_TRUE(request1); | 1881 ASSERT_TRUE(request1); |
1829 int64 request_id1 = request1->navigation_request_id(); | 1882 int cancel_count = TestNavigationURLLoader::cancel_count(); |
1830 | 1883 |
1831 // Request navigation to the 2nd URL and gather more data. | 1884 // Request navigation to the 2nd URL and gather more data. |
1832 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 1885 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
1833 NavigationRequest* request2 = | 1886 NavigationRequest* request2 = |
1834 GetNavigationRequestForRenderFrameManager(render_manager); | 1887 GetNavigationRequestForRenderFrameManager(render_manager); |
1835 ASSERT_TRUE(request2); | 1888 ASSERT_TRUE(request2); |
1836 int64 request_id2 = request2->navigation_request_id(); | |
1837 EXPECT_NE(request_id1, request_id2); | |
1838 | 1889 |
1839 // Confirms that a stale commit is ignored by the RHFM. | 1890 // Confirm that the first request got canceled. |
1840 NavigationBeforeCommitInfo nbc_info; | 1891 EXPECT_EQ(cancel_count + 1, TestNavigationURLLoader::cancel_count()); |
clamy
2014/09/12 20:51:25
We do not test anymore that a call to OnResponseSt
davidben
2014/09/19 18:30:49
That's true. It got split over two tests. This tes
| |
1841 nbc_info.navigation_url = kUrl1; | |
1842 nbc_info.navigation_request_id = request_id1; | |
1843 render_manager->CommitNavigation(nbc_info); | |
1844 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | |
1845 | 1892 |
1846 // Confirms that a valid, request-matching commit is correctly processed. | 1893 // Confirms that a valid, request-matching commit is correctly processed. |
1847 nbc_info.navigation_url = kUrl2; | 1894 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
1848 nbc_info.navigation_request_id = request_id2; | 1895 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( |
1849 render_manager->CommitNavigation(nbc_info); | 1896 response.get(), scoped_ptr<StreamHandle>()); |
1850 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1897 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1851 } | 1898 } |
1852 | 1899 |
1853 } // namespace content | 1900 } // namespace content |
OLD | NEW |