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

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

Issue 519533002: Initial PlzNavigate RDH-side logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
OLDNEW
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"
34 #include "content/public/common/resource_response.h"
32 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
33 #include "content/public/common/url_utils.h" 36 #include "content/public/common/url_utils.h"
34 #include "content/public/test/mock_render_process_host.h" 37 #include "content/public/test/mock_render_process_host.h"
35 #include "content/public/test/test_notification_tracker.h" 38 #include "content/public/test/test_notification_tracker.h"
36 #include "content/test/test_content_browser_client.h" 39 #include "content/test/test_content_browser_client.h"
37 #include "content/test/test_content_client.h" 40 #include "content/test/test_content_client.h"
38 #include "content/test/test_render_frame_host.h" 41 #include "content/test/test_render_frame_host.h"
39 #include "content/test/test_render_view_host.h" 42 #include "content/test/test_render_view_host.h"
40 #include "content/test/test_web_contents.h" 43 #include "content/test/test_web_contents.h"
41 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 434
378 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut()); 435 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->IsSwappedOut());
379 return ntp_rfh->GetRenderViewHost(); 436 return ntp_rfh->GetRenderViewHost();
380 } 437 }
381 438
382 NavigationRequest* GetNavigationRequestForRenderFrameManager( 439 NavigationRequest* GetNavigationRequestForRenderFrameManager(
383 RenderFrameHostManager* manager) const { 440 RenderFrameHostManager* manager) const {
384 return manager->navigation_request_for_testing(); 441 return manager->navigation_request_for_testing();
385 } 442 }
386 443
444 TestNavigationURLLoader* GetLoaderForNavigationRequest(
445 NavigationRequest* request) const {
446 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
447 }
448
387 void EnableBrowserSideNavigation() { 449 void EnableBrowserSideNavigation() {
388 CommandLine::ForCurrentProcess()->AppendSwitch( 450 CommandLine::ForCurrentProcess()->AppendSwitch(
389 switches::kEnableBrowserSideNavigation); 451 switches::kEnableBrowserSideNavigation);
390 } 452 }
391 private: 453 private:
392 RenderFrameHostManagerTestWebUIControllerFactory factory_; 454 RenderFrameHostManagerTestWebUIControllerFactory factory_;
393 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; 455 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_;
456 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_;
394 }; 457 };
395 458
396 // Tests that when you navigate from a chrome:// url to another page, and 459 // Tests that when you navigate from a chrome:// url to another page, and
397 // then do that same thing in another tab, that the two resulting pages have 460 // then do that same thing in another tab, that the two resulting pages have
398 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 461 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
399 // a regression test for bug 9364. 462 // a regression test for bug 9364.
400 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { 463 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
401 set_should_create_webui(true); 464 set_should_create_webui(true);
402 const GURL kChromeUrl("chrome://foo"); 465 const GURL kChromeUrl("chrome://foo");
403 const GURL kDestUrl("http://www.google.com/"); 466 const GURL kDestUrl("http://www.google.com/");
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 EXPECT_FALSE(rvh_deleted_observer.deleted()); 1764 EXPECT_FALSE(rvh_deleted_observer.deleted());
1702 } 1765 }
1703 } 1766 }
1704 1767
1705 // PlzNavigate: Test that a proper NavigationRequest is created by 1768 // PlzNavigate: Test that a proper NavigationRequest is created by
1706 // BeginNavigation. 1769 // BeginNavigation.
1707 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { 1770 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
1708 const GURL kUrl1("http://www.google.com/"); 1771 const GURL kUrl1("http://www.google.com/");
1709 const GURL kUrl2("http://www.chromium.org/"); 1772 const GURL kUrl2("http://www.chromium.org/");
1710 const GURL kUrl3("http://www.gmail.com/"); 1773 const GURL kUrl3("http://www.gmail.com/");
1711 const int64 kFirstNavRequestID = 1;
1712 1774
1713 // TODO(clamy): we should be enabling browser side navigations here 1775 // TODO(clamy): we should be enabling browser side navigations here
1714 // when CommitNavigation is properly implemented. 1776 // when CommitNavigation is properly implemented.
1715 // Navigate to the first page. 1777 // Navigate to the first page.
1716 contents()->NavigateAndCommit(kUrl1); 1778 contents()->NavigateAndCommit(kUrl1);
1717 1779
1718 EnableBrowserSideNavigation(); 1780 EnableBrowserSideNavigation();
1719 // Add a subframe. 1781 // Add a subframe.
1720 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 1782 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
1721 contents()->GetFrameTree()->AddFrame( 1783 contents()->GetFrameTree()->AddFrame(
1722 contents()->GetFrameTree()->root(), 14, "Child")); 1784 contents()->GetFrameTree()->root(), 14, "Child"));
1723 1785
1724 // Simulate a BeginNavigation IPC on the subframe. 1786 // Simulate a BeginNavigation IPC on the subframe.
1725 subframe_rfh->SendBeginNavigationWithURL(kUrl2); 1787 subframe_rfh->SendBeginNavigationWithURL(kUrl2);
1726 NavigationRequest* subframe_request = 1788 NavigationRequest* subframe_request =
1727 GetNavigationRequestForRenderFrameManager( 1789 GetNavigationRequestForRenderFrameManager(
1728 subframe_rfh->frame_tree_node()->render_manager()); 1790 subframe_rfh->frame_tree_node()->render_manager());
1729 ASSERT_TRUE(subframe_request); 1791 ASSERT_TRUE(subframe_request);
1730 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); 1792 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url);
1731 // First party for cookies url should be that of the main frame. 1793 // First party for cookies url should be that of the main frame.
1732 EXPECT_EQ( 1794 EXPECT_EQ(
1733 kUrl1, subframe_request->info().first_party_for_cookies); 1795 kUrl1, subframe_request->info().first_party_for_cookies);
1734 EXPECT_FALSE(subframe_request->info().is_main_frame); 1796 EXPECT_FALSE(subframe_request->info().is_main_frame);
1735 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); 1797 EXPECT_TRUE(subframe_request->info().parent_is_main_frame);
1736 EXPECT_EQ(kFirstNavRequestID, subframe_request->navigation_request_id());
1737 1798
1738 // Simulate a BeginNavigation IPC on the main frame. 1799 // Simulate a BeginNavigation IPC on the main frame.
1739 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); 1800 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
1740 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( 1801 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager(
1741 contents()->GetMainFrame()->frame_tree_node()->render_manager()); 1802 contents()->GetMainFrame()->frame_tree_node()->render_manager());
1742 ASSERT_TRUE(main_request); 1803 ASSERT_TRUE(main_request);
1743 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); 1804 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url);
1744 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); 1805 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies);
1745 EXPECT_TRUE(main_request->info().is_main_frame); 1806 EXPECT_TRUE(main_request->info().is_main_frame);
1746 EXPECT_FALSE(main_request->info().parent_is_main_frame); 1807 EXPECT_FALSE(main_request->info().parent_is_main_frame);
1747 EXPECT_EQ(kFirstNavRequestID + 1, main_request->navigation_request_id());
1748 } 1808 }
1749 1809
1750 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that 1810 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
1751 // RenderFrameHost is not modified when the navigation commits. 1811 // RenderFrameHost is not modified when the navigation commits.
1752 TEST_F(RenderFrameHostManagerTest, 1812 TEST_F(RenderFrameHostManagerTest,
1753 BrowserSideNavigationRequestNavigationNoLiveRenderer) { 1813 BrowserSideNavigationRequestNavigationNoLiveRenderer) {
1754 const GURL kUrl("http://www.google.com/"); 1814 const GURL kUrl("http://www.google.com/");
1755 1815
1756 EnableBrowserSideNavigation(); 1816 EnableBrowserSideNavigation();
1757 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 1817 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
1758 contents()->GetController().LoadURL( 1818 contents()->GetController().LoadURL(
1759 kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1819 kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1760 RenderFrameHostManager* render_manager = 1820 RenderFrameHostManager* render_manager =
1761 main_test_rfh()->frame_tree_node()->render_manager(); 1821 main_test_rfh()->frame_tree_node()->render_manager();
1762 NavigationRequest* main_request = 1822 NavigationRequest* main_request =
1763 GetNavigationRequestForRenderFrameManager(render_manager); 1823 GetNavigationRequestForRenderFrameManager(render_manager);
1764 // A NavigationRequest should have been generated. 1824 // A NavigationRequest should have been generated.
1765 EXPECT_TRUE(main_request != NULL); 1825 EXPECT_TRUE(main_request != NULL);
1766 RenderFrameHostImpl* rfh = main_test_rfh(); 1826 RenderFrameHostImpl* rfh = main_test_rfh();
1767 1827
1768 // Now commit the same url. 1828 // Now commit the same url.
nasko 2014/09/24 21:15:34 It is now non-obvious that the following code will
davidben 2014/10/03 16:27:52 Done.
1769 NavigationBeforeCommitInfo commit_info; 1829 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1770 commit_info.navigation_url = kUrl; 1830 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
1771 commit_info.navigation_request_id = main_request->navigation_request_id(); 1831 response.get(), scoped_ptr<StreamHandle>());
1772 render_manager->CommitNavigation(commit_info);
1773 main_request = GetNavigationRequestForRenderFrameManager(render_manager);
1774 1832
1775 // The main RFH should not have been changed, and the renderer should have 1833 // The main RFH should not have been changed, and the renderer should have
1776 // been initialized. 1834 // been initialized.
1777 EXPECT_EQ(rfh, main_test_rfh()); 1835 EXPECT_EQ(rfh, main_test_rfh());
1778 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 1836 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
1779 } 1837 }
1780 1838
1781 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross 1839 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
1782 // site navigation. 1840 // site navigation.
1783 TEST_F(RenderFrameHostManagerTest, 1841 TEST_F(RenderFrameHostManagerTest,
(...skipping 11 matching lines...) Expand all
1795 RenderFrameHostManager* render_manager = 1853 RenderFrameHostManager* render_manager =
1796 main_test_rfh()->frame_tree_node()->render_manager(); 1854 main_test_rfh()->frame_tree_node()->render_manager();
1797 1855
1798 EnableBrowserSideNavigation(); 1856 EnableBrowserSideNavigation();
1799 // Navigate to a different site. 1857 // Navigate to a different site.
1800 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 1858 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1801 NavigationRequest* main_request = 1859 NavigationRequest* main_request =
1802 GetNavigationRequestForRenderFrameManager(render_manager); 1860 GetNavigationRequestForRenderFrameManager(render_manager);
1803 ASSERT_TRUE(main_request); 1861 ASSERT_TRUE(main_request);
1804 1862
1805 NavigationBeforeCommitInfo commit_info; 1863 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1806 commit_info.navigation_url = kUrl2; 1864 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
1807 commit_info.navigation_request_id = main_request->navigation_request_id(); 1865 response.get(), scoped_ptr<StreamHandle>());
1808 render_manager->CommitNavigation(commit_info);
1809 EXPECT_NE(main_test_rfh(), rfh); 1866 EXPECT_NE(main_test_rfh(), rfh);
1810 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 1867 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
1811 } 1868 }
1812 1869
1813 // PlzNavigate: Test that a navigation commit is ignored if another request has 1870 // PlzNavigate: Test that a navigation is cancelled if another request has been
1814 // been issued in the meantime. 1871 // issued in the meantime.
1815 // TODO(carlosk): add checks to assert that the cancel call was sent to
1816 // ResourceDispatcherHost in the IO thread by extending
1817 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc
1818 // and plugin_browsertest.cc).
1819 TEST_F(RenderFrameHostManagerTest, 1872 TEST_F(RenderFrameHostManagerTest,
1820 BrowserSideNavigationIgnoreStaleNavigationCommit) { 1873 BrowserSideNavigationReplacePendingNavigation) {
1821 const GURL kUrl0("http://www.wikipedia.org/"); 1874 const GURL kUrl0("http://www.wikipedia.org/");
1822 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); 1875 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
1823 const GURL kUrl1("http://www.chromium.org/"); 1876 const GURL kUrl1("http://www.chromium.org/");
1824 const GURL kUrl2("http://www.google.com/"); 1877 const GURL kUrl2("http://www.google.com/");
1825 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 1878 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
1826 1879
1827 // Initialization. 1880 // Initialization.
1828 contents()->NavigateAndCommit(kUrl0); 1881 contents()->NavigateAndCommit(kUrl0);
1829 RenderFrameHostManager* render_manager = 1882 RenderFrameHostManager* render_manager =
1830 main_test_rfh()->frame_tree_node()->render_manager(); 1883 main_test_rfh()->frame_tree_node()->render_manager();
1831 EnableBrowserSideNavigation(); 1884 EnableBrowserSideNavigation();
1832 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 1885 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
1833 1886
1834 // Request navigation to the 1st URL and gather data. 1887 // Request navigation to the 1st URL and gather data.
1835 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 1888 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
1836 NavigationRequest* request1 = 1889 NavigationRequest* request1 =
1837 GetNavigationRequestForRenderFrameManager(render_manager); 1890 GetNavigationRequestForRenderFrameManager(render_manager);
1838 ASSERT_TRUE(request1); 1891 ASSERT_TRUE(request1);
1839 int64 request_id1 = request1->navigation_request_id(); 1892 int cancel_count = TestNavigationURLLoader::cancel_count();
1840 1893
1841 // Request navigation to the 2nd URL and gather more data. 1894 // Request navigation to the 2nd URL and gather more data.
1842 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 1895 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1843 NavigationRequest* request2 = 1896 NavigationRequest* request2 =
1844 GetNavigationRequestForRenderFrameManager(render_manager); 1897 GetNavigationRequestForRenderFrameManager(render_manager);
1845 ASSERT_TRUE(request2); 1898 ASSERT_TRUE(request2);
1846 int64 request_id2 = request2->navigation_request_id();
1847 EXPECT_NE(request_id1, request_id2);
1848 1899
1849 // Confirms that a stale commit is ignored by the RHFM. 1900 // Confirm that the first request got canceled.
1850 NavigationBeforeCommitInfo nbc_info; 1901 EXPECT_EQ(cancel_count + 1, TestNavigationURLLoader::cancel_count());
1851 nbc_info.navigation_url = kUrl1;
1852 nbc_info.navigation_request_id = request_id1;
1853 render_manager->CommitNavigation(nbc_info);
1854 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
1855 1902
1856 // Confirms that a valid, request-matching commit is correctly processed. 1903 // Confirms that a valid, request-matching commit is correctly processed.
1857 nbc_info.navigation_url = kUrl2; 1904 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1858 nbc_info.navigation_request_id = request_id2; 1905 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
1859 render_manager->CommitNavigation(nbc_info); 1906 response.get(), scoped_ptr<StreamHandle>());
1860 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 1907 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
nasko 2014/09/24 21:15:34 Why not check the cancel count here again? Just to
davidben 2014/10/03 16:27:52 Done.
1861 } 1908 }
1862 1909
1863 } // namespace content 1910 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698