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/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 void set_should_create_webui(bool should_create_webui) { | 254 void set_should_create_webui(bool should_create_webui) { |
255 factory_.set_should_create_webui(should_create_webui); | 255 factory_.set_should_create_webui(should_create_webui); |
256 } | 256 } |
257 | 257 |
258 void NavigateActiveAndCommit(const GURL& url) { | 258 void NavigateActiveAndCommit(const GURL& url) { |
259 // Note: we navigate the active RenderFrameHost because previous navigations | 259 // Note: we navigate the active RenderFrameHost because previous navigations |
260 // won't have committed yet, so NavigateAndCommit does the wrong thing | 260 // won't have committed yet, so NavigateAndCommit does the wrong thing |
261 // for us. | 261 // for us. |
262 controller().LoadURL( | 262 controller().LoadURL( |
263 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 263 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
264 | |
265 // Simulate the BeforeUnload_ACK that is received from the current renderer | |
266 // for a cross-site navigation. | |
267 // PlzNavigate: it is necessary to call PrepareForCommit before getting the | |
268 // main and the pending frame because when we are trying to navigate to a | |
269 // webui from a new tab, a RenderFrameHost is created to display it that is | |
nasko
2015/01/21 00:41:32
nit: s/webui/WebUI/
clamy
2015/01/21 13:22:11
Done.
| |
270 // committed immediately (since it is a new tab). Therefore the main frame | |
nasko
2015/01/21 00:41:32
Is this only the case for new tab with WebUI? What
clamy
2015/01/21 13:22:11
For this to happen, you need the current renderer
| |
271 // is replaced without a pending frame being created, and we don't get the | |
272 // right values for the RFH to navigate: we try to use the old one that has | |
273 // been deleted in the meantime. | |
274 contents()->GetMainFrame()->PrepareForCommit(url); | |
275 | |
264 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); | 276 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); |
265 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() | 277 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() |
266 ? contents()->GetPendingMainFrame() | 278 ? contents()->GetPendingMainFrame() |
267 : old_rfh; | 279 : old_rfh; |
268 | 280 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); |
269 // Simulate the BeforeUnload_ACK that is received from the current renderer | |
270 // for a cross-site navigation. | |
271 if (old_rfh != active_rfh) { | |
272 old_rfh->SendBeforeUnloadACK(true); | |
273 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); | |
274 } | |
275 | 281 |
276 // Commit the navigation with a new page ID. | 282 // Commit the navigation with a new page ID. |
277 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 283 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
278 active_rfh->GetSiteInstance()); | 284 active_rfh->GetSiteInstance()); |
279 | 285 |
280 // Use an observer to avoid accessing a deleted renderer later on when the | 286 // Use an observer to avoid accessing a deleted renderer later on when the |
281 // state is being checked. | 287 // state is being checked. |
282 RenderFrameHostDeletedObserver rfh_observer(old_rfh); | 288 RenderFrameHostDeletedObserver rfh_observer(old_rfh); |
283 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); | 289 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); |
284 active_rfh->SendNavigate(max_page_id + 1, url); | 290 active_rfh->SendNavigate(max_page_id + 1, url); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 const GURL kChromeURL("chrome://foo"); | 343 const GURL kChromeURL("chrome://foo"); |
338 const GURL kDestUrl("http://www.google.com/"); | 344 const GURL kDestUrl("http://www.google.com/"); |
339 | 345 |
340 // Navigate our first tab to a chrome url and then to the destination. | 346 // Navigate our first tab to a chrome url and then to the destination. |
341 NavigateActiveAndCommit(kChromeURL); | 347 NavigateActiveAndCommit(kChromeURL); |
342 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 348 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
343 | 349 |
344 // Navigate to a cross-site URL. | 350 // Navigate to a cross-site URL. |
345 contents()->GetController().LoadURL( | 351 contents()->GetController().LoadURL( |
346 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 352 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
353 contents()->GetMainFrame()->PrepareForCommit(kDestUrl); | |
347 EXPECT_TRUE(contents()->cross_navigation_pending()); | 354 EXPECT_TRUE(contents()->cross_navigation_pending()); |
348 | 355 |
349 // Manually increase the number of active frames in the | 356 // Manually increase the number of active frames in the |
350 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 357 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
351 // destroyed when it gets swapped out. | 358 // destroyed when it gets swapped out. |
352 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 359 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
353 | 360 |
354 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 361 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
355 CHECK(dest_rfh); | 362 CHECK(dest_rfh); |
356 EXPECT_NE(ntp_rfh, dest_rfh); | 363 EXPECT_NE(ntp_rfh, dest_rfh); |
357 | 364 |
358 // BeforeUnload finishes. | 365 // BeforeUnload finishes. |
359 ntp_rfh->SendBeforeUnloadACK(true); | 366 ntp_rfh->SendBeforeUnloadACK(true); |
360 | 367 |
361 dest_rfh->SendNavigate(101, kDestUrl); | 368 dest_rfh->SendNavigate(101, kDestUrl); |
362 ntp_rfh->OnSwappedOut(); | 369 ntp_rfh->OnSwappedOut(); |
363 | 370 |
364 EXPECT_TRUE(ntp_rfh->is_swapped_out()); | 371 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
365 return ntp_rfh; | 372 return ntp_rfh; |
366 } | 373 } |
367 | 374 |
375 // Returns the RenderFrameHost that should be used in the navigation to | |
376 // |entry|. | |
377 RenderFrameHostImpl* GetFrameHostForNavigation( | |
carlosk
2015/01/20 15:38:02
Oh, I see what you did here! Initially I didn't li
| |
378 RenderFrameHostManager* manager, | |
379 const NavigationEntryImpl& entry) { | |
380 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
381 switches::kEnableBrowserSideNavigation)) { | |
382 return manager->GetFrameHostForNavigation( | |
383 entry.GetURL(), entry.GetTransitionType()); | |
384 } | |
385 return manager->Navigate(entry); | |
386 } | |
387 | |
388 // Returns the pending RenderFrameHost. | |
389 // PlzNavigate: returns the speculative RenderFrameHost. | |
390 RenderFrameHostImpl* GetPendingFrameHost( | |
carlosk
2015/01/20 15:38:02
Thinking about the future again, maybe here we sho
clamy
2015/01/21 13:22:11
I was trying to match what is done with the TestWe
| |
391 RenderFrameHostManager* manager) { | |
392 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
393 switches::kEnableBrowserSideNavigation)) { | |
394 return manager->speculative_render_frame_host_.get(); | |
395 } | |
396 return manager->pending_frame_host(); | |
397 } | |
398 | |
368 private: | 399 private: |
369 RenderFrameHostManagerTestWebUIControllerFactory factory_; | 400 RenderFrameHostManagerTestWebUIControllerFactory factory_; |
370 }; | 401 }; |
371 | 402 |
372 // Tests that when you navigate from a chrome:// url to another page, and | 403 // Tests that when you navigate from a chrome:// url to another page, and |
373 // then do that same thing in another tab, that the two resulting pages have | 404 // then do that same thing in another tab, that the two resulting pages have |
374 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 405 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
375 // a regression test for bug 9364. | 406 // a regression test for bug 9364. |
376 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 407 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
377 set_should_create_webui(true); | 408 set_should_create_webui(true); |
(...skipping 10 matching lines...) Expand all Loading... | |
388 | 419 |
389 // Make a second tab. | 420 // Make a second tab. |
390 scoped_ptr<TestWebContents> contents2( | 421 scoped_ptr<TestWebContents> contents2( |
391 TestWebContents::Create(browser_context(), NULL)); | 422 TestWebContents::Create(browser_context(), NULL)); |
392 | 423 |
393 // Load the two URLs in the second tab. Note that the first navigation creates | 424 // Load the two URLs in the second tab. Note that the first navigation creates |
394 // a RFH that's not pending (since there is no cross-site transition), so | 425 // a RFH that's not pending (since there is no cross-site transition), so |
395 // we use the committed one. | 426 // we use the committed one. |
396 contents2->GetController().LoadURL( | 427 contents2->GetController().LoadURL( |
397 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 428 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
429 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); | |
398 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 430 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
399 EXPECT_FALSE(contents2->cross_navigation_pending()); | 431 EXPECT_FALSE(contents2->cross_navigation_pending()); |
400 ntp_rfh2->SendNavigate(100, kChromeUrl); | 432 ntp_rfh2->SendNavigate(100, kChromeUrl); |
401 | 433 |
402 // The second one is the opposite, creating a cross-site transition and | 434 // The second one is the opposite, creating a cross-site transition and |
403 // requiring a beforeunload ack. | 435 // requiring a beforeunload ack. |
404 contents2->GetController().LoadURL( | 436 contents2->GetController().LoadURL( |
405 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 437 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
438 contents2->GetMainFrame()->PrepareForCommit(kDestUrl); | |
406 EXPECT_TRUE(contents2->cross_navigation_pending()); | 439 EXPECT_TRUE(contents2->cross_navigation_pending()); |
407 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 440 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
408 ASSERT_TRUE(dest_rfh2); | 441 ASSERT_TRUE(dest_rfh2); |
409 | 442 |
410 ntp_rfh2->SendBeforeUnloadACK(true); | |
411 dest_rfh2->SendNavigate(101, kDestUrl); | 443 dest_rfh2->SendNavigate(101, kDestUrl); |
412 | 444 |
413 // The two RFH's should be different in every way. | 445 // The two RFH's should be different in every way. |
414 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 446 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
415 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 447 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
416 dest_rfh2->GetSiteInstance()); | 448 dest_rfh2->GetSiteInstance()); |
417 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 449 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
418 contents()->GetMainFrame()->GetSiteInstance())); | 450 contents()->GetMainFrame()->GetSiteInstance())); |
419 | 451 |
420 // Navigate both to the new tab page, and verify that they share a | 452 // Navigate both to the new tab page, and verify that they share a |
421 // RenderProcessHost (not a SiteInstance). | 453 // RenderProcessHost (not a SiteInstance). |
422 NavigateActiveAndCommit(kChromeUrl); | 454 NavigateActiveAndCommit(kChromeUrl); |
423 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 455 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
424 | 456 |
425 contents2->GetController().LoadURL( | 457 contents2->GetController().LoadURL( |
426 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 458 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
427 dest_rfh2->SendBeforeUnloadACK(true); | 459 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); |
428 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 460 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
429 | 461 |
430 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 462 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
431 contents2->GetMainFrame()->GetSiteInstance()); | 463 contents2->GetMainFrame()->GetSiteInstance()); |
432 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 464 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
433 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 465 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
434 } | 466 } |
435 | 467 |
436 // Ensure that the browser ignores most IPC messages that arrive from a | 468 // Ensure that the browser ignores most IPC messages that arrive from a |
437 // RenderViewHost that has been swapped out. We do not want to take | 469 // RenderViewHost that has been swapped out. We do not want to take |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 // one will create a new SiteInstance. Because current_instance and | 784 // one will create a new SiteInstance. Because current_instance and |
753 // new_instance will be different, a new RenderViewHost will be created for | 785 // new_instance will be different, a new RenderViewHost will be created for |
754 // the second navigation. We have to avoid this in order to exercise the | 786 // the second navigation. We have to avoid this in order to exercise the |
755 // target code patch. | 787 // target code patch. |
756 NavigateActiveAndCommit(kChromeUrl); | 788 NavigateActiveAndCommit(kChromeUrl); |
757 | 789 |
758 // Navigate. | 790 // Navigate. |
759 controller().LoadURL( | 791 controller().LoadURL( |
760 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 792 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
761 // Simulate response from RenderFrame for DispatchBeforeUnload. | 793 // Simulate response from RenderFrame for DispatchBeforeUnload. |
762 base::TimeTicks now = base::TimeTicks::Now(); | 794 contents()->GetMainFrame()->PrepareForCommit(kUrl); |
763 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK( | |
764 contents()->GetMainFrame()->GetRoutingID(), true, now, now)); | |
765 ASSERT_TRUE(contents()->GetPendingMainFrame()) | 795 ASSERT_TRUE(contents()->GetPendingMainFrame()) |
766 << "Expected new pending RenderFrameHost to be created."; | 796 << "Expected new pending RenderFrameHost to be created."; |
767 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); | 797 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); |
768 int32 new_id = | 798 int32 new_id = |
769 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; | 799 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; |
770 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); | 800 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); |
771 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 801 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
772 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 802 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
773 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 803 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
774 EXPECT_FALSE(controller().GetPendingEntry()); | 804 EXPECT_FALSE(controller().GetPendingEntry()); |
775 // Because we're using TestWebContents and TestRenderViewHost in this | 805 // Because we're using TestWebContents and TestRenderViewHost in this |
776 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no | 806 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no |
777 // EnableViewSourceMode message, here. | 807 // EnableViewSourceMode message, here. |
778 | 808 |
779 // Clear queued messages before load. | 809 // Clear queued messages before load. |
780 process()->sink().ClearMessages(); | 810 process()->sink().ClearMessages(); |
781 // Navigate, again. | 811 // Navigate, again. |
782 controller().LoadURL( | 812 controller().LoadURL( |
783 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 813 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
814 contents()->GetMainFrame()->PrepareForCommit(kUrl); | |
784 // The same RenderViewHost should be reused. | 815 // The same RenderViewHost should be reused. |
785 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 816 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
786 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); | 817 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); |
787 // Navigate using the returned page_id. | 818 // Navigate using the returned page_id. |
788 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); | 819 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); |
789 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 820 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
790 EXPECT_FALSE(controller().GetPendingEntry()); | 821 EXPECT_FALSE(controller().GetPendingEntry()); |
791 // New message should be sent out to make sure to enter view-source mode. | 822 // New message should be sent out to make sure to enter view-source mode. |
792 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 823 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
793 ViewMsg_EnableViewSourceMode::ID)); | 824 ViewMsg_EnableViewSourceMode::ID)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 | 861 |
831 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 862 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
832 RenderFrameHostImpl* host = NULL; | 863 RenderFrameHostImpl* host = NULL; |
833 | 864 |
834 // 1) The first navigation. -------------------------- | 865 // 1) The first navigation. -------------------------- |
835 const GURL kUrl1("http://www.google.com/"); | 866 const GURL kUrl1("http://www.google.com/"); |
836 NavigationEntryImpl entry1( | 867 NavigationEntryImpl entry1( |
837 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 868 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
838 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 869 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
839 false /* is_renderer_init */); | 870 false /* is_renderer_init */); |
840 host = manager->Navigate(entry1); | 871 host = GetFrameHostForNavigation(manager, entry1); |
841 | 872 |
842 // The RenderFrameHost created in Init will be reused. | 873 // The RenderFrameHost created in Init will be reused. |
843 EXPECT_TRUE(host == manager->current_frame_host()); | 874 EXPECT_TRUE(host == manager->current_frame_host()); |
844 EXPECT_FALSE(manager->pending_frame_host()); | 875 EXPECT_FALSE(GetPendingFrameHost(manager)); |
845 | 876 |
846 // Commit. | 877 // Commit. |
847 manager->DidNavigateFrame(host, true); | 878 manager->DidNavigateFrame(host, true); |
848 // Commit to SiteInstance should be delayed until RenderFrame commit. | 879 // Commit to SiteInstance should be delayed until RenderFrame commit. |
849 EXPECT_TRUE(host == manager->current_frame_host()); | 880 EXPECT_TRUE(host == manager->current_frame_host()); |
850 ASSERT_TRUE(host); | 881 ASSERT_TRUE(host); |
851 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 882 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
852 host->GetSiteInstance()->SetSite(kUrl1); | 883 host->GetSiteInstance()->SetSite(kUrl1); |
853 | 884 |
854 // 2) Navigate to next site. ------------------------- | 885 // 2) Navigate to next site. ------------------------- |
855 const GURL kUrl2("http://www.google.com/foo"); | 886 const GURL kUrl2("http://www.google.com/foo"); |
856 NavigationEntryImpl entry2( | 887 NavigationEntryImpl entry2( |
857 NULL /* instance */, -1 /* page_id */, kUrl2, | 888 NULL /* instance */, -1 /* page_id */, kUrl2, |
858 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 889 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
859 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 890 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
860 true /* is_renderer_init */); | 891 true /* is_renderer_init */); |
861 host = manager->Navigate(entry2); | 892 host = GetFrameHostForNavigation(manager, entry2); |
862 | 893 |
863 // The RenderFrameHost created in Init will be reused. | 894 // The RenderFrameHost created in Init will be reused. |
864 EXPECT_TRUE(host == manager->current_frame_host()); | 895 EXPECT_TRUE(host == manager->current_frame_host()); |
865 EXPECT_FALSE(manager->pending_frame_host()); | 896 EXPECT_FALSE(GetPendingFrameHost(manager)); |
866 | 897 |
867 // Commit. | 898 // Commit. |
868 manager->DidNavigateFrame(host, true); | 899 manager->DidNavigateFrame(host, true); |
869 EXPECT_TRUE(host == manager->current_frame_host()); | 900 EXPECT_TRUE(host == manager->current_frame_host()); |
870 ASSERT_TRUE(host); | 901 ASSERT_TRUE(host); |
871 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 902 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
872 | 903 |
873 // 3) Cross-site navigate to next site. -------------- | 904 // 3) Cross-site navigate to next site. -------------- |
874 const GURL kUrl3("http://webkit.org/"); | 905 const GURL kUrl3("http://webkit.org/"); |
875 NavigationEntryImpl entry3( | 906 NavigationEntryImpl entry3( |
876 NULL /* instance */, -1 /* page_id */, kUrl3, | 907 NULL /* instance */, -1 /* page_id */, kUrl3, |
877 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 908 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
878 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 909 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
879 false /* is_renderer_init */); | 910 false /* is_renderer_init */); |
880 host = manager->Navigate(entry3); | 911 host = GetFrameHostForNavigation(manager, entry3); |
881 | 912 |
882 // A new RenderFrameHost should be created. | 913 // A new RenderFrameHost should be created. |
883 EXPECT_TRUE(manager->pending_frame_host()); | 914 EXPECT_TRUE(GetPendingFrameHost(manager)); |
884 ASSERT_EQ(host, manager->pending_frame_host()); | 915 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
885 | 916 |
886 notifications.Reset(); | 917 notifications.Reset(); |
887 | 918 |
888 // Commit. | 919 // Commit. |
889 manager->DidNavigateFrame(manager->pending_frame_host(), true); | 920 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); |
890 EXPECT_TRUE(host == manager->current_frame_host()); | 921 EXPECT_TRUE(host == manager->current_frame_host()); |
891 ASSERT_TRUE(host); | 922 ASSERT_TRUE(host); |
892 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 923 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
893 // Check the pending RenderFrameHost has been committed. | 924 // Check the pending RenderFrameHost has been committed. |
894 EXPECT_FALSE(manager->pending_frame_host()); | 925 EXPECT_FALSE(GetPendingFrameHost(manager)); |
895 | 926 |
896 // We should observe a notification. | 927 // We should observe a notification. |
897 EXPECT_TRUE( | 928 EXPECT_TRUE( |
898 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 929 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
899 } | 930 } |
900 | 931 |
901 // Tests WebUI creation. | 932 // Tests WebUI creation. |
902 TEST_F(RenderFrameHostManagerTest, WebUI) { | 933 TEST_F(RenderFrameHostManagerTest, WebUI) { |
903 set_should_create_webui(true); | 934 set_should_create_webui(true); |
904 SiteInstance* instance = SiteInstance::Create(browser_context()); | 935 SiteInstance* instance = SiteInstance::Create(browser_context()); |
905 | 936 |
906 scoped_ptr<TestWebContents> web_contents( | 937 scoped_ptr<TestWebContents> web_contents( |
907 TestWebContents::Create(browser_context(), instance)); | 938 TestWebContents::Create(browser_context(), instance)); |
908 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 939 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
909 | 940 |
910 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 941 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
911 | 942 |
912 const GURL kUrl("chrome://foo"); | 943 const GURL kUrl("chrome://foo"); |
913 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 944 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
914 Referrer(), base::string16() /* title */, | 945 Referrer(), base::string16() /* title */, |
915 ui::PAGE_TRANSITION_TYPED, | 946 ui::PAGE_TRANSITION_TYPED, |
916 false /* is_renderer_init */); | 947 false /* is_renderer_init */); |
917 RenderFrameHostImpl* host = manager->Navigate(entry); | 948 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry); |
918 | 949 |
919 // We commit the pending RenderFrameHost immediately because the previous | 950 // We commit the pending RenderFrameHost immediately because the previous |
920 // RenderFrameHost was not live. We test a case where it is live in | 951 // RenderFrameHost was not live. We test a case where it is live in |
921 // WebUIInNewTab. | 952 // WebUIInNewTab. |
922 EXPECT_TRUE(host); | 953 EXPECT_TRUE(host); |
923 EXPECT_EQ(host, manager->current_frame_host()); | 954 EXPECT_EQ(host, manager->current_frame_host()); |
924 EXPECT_FALSE(manager->pending_frame_host()); | 955 EXPECT_FALSE(GetPendingFrameHost(manager)); |
925 | 956 |
926 // It's important that the site instance get set on the Web UI page as soon | 957 // It's important that the site instance get set on the Web UI page as soon |
927 // as the navigation starts, rather than lazily after it commits, so we don't | 958 // as the navigation starts, rather than lazily after it commits, so we don't |
928 // try to re-use the SiteInstance/process for non Web UI things that may | 959 // try to re-use the SiteInstance/process for non Web UI things that may |
929 // get loaded in between. | 960 // get loaded in between. |
930 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 961 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
931 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 962 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
932 | 963 |
933 // The Web UI is committed immediately because the RenderViewHost has not been | 964 // The Web UI is committed immediately because the RenderViewHost has not been |
934 // used yet. UpdateStateForNavigate() took the short cut path. | 965 // used yet. UpdateStateForNavigate() took the short cut path. |
(...skipping 22 matching lines...) Expand all Loading... | |
957 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 988 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
958 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); | 989 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); |
959 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); | 990 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); |
960 | 991 |
961 // Navigate to a WebUI page. | 992 // Navigate to a WebUI page. |
962 const GURL kUrl1("chrome://foo"); | 993 const GURL kUrl1("chrome://foo"); |
963 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 994 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
964 Referrer(), base::string16() /* title */, | 995 Referrer(), base::string16() /* title */, |
965 ui::PAGE_TRANSITION_TYPED, | 996 ui::PAGE_TRANSITION_TYPED, |
966 false /* is_renderer_init */); | 997 false /* is_renderer_init */); |
967 RenderFrameHostImpl* host1 = manager1->Navigate(entry1); | 998 RenderFrameHostImpl* host1 = GetFrameHostForNavigation(manager1, entry1); |
968 | 999 |
969 // We should have a pending navigation to the WebUI RenderViewHost. | 1000 // We should have a pending navigation to the WebUI RenderViewHost. |
970 // It should already have bindings. | 1001 // It should already have bindings. |
971 EXPECT_EQ(host1, manager1->pending_frame_host()); | 1002 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); |
972 EXPECT_NE(host1, manager1->current_frame_host()); | 1003 EXPECT_NE(host1, manager1->current_frame_host()); |
973 EXPECT_TRUE( | 1004 EXPECT_TRUE( |
974 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1005 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
975 | 1006 |
976 // Commit and ensure we still have bindings. | 1007 // Commit and ensure we still have bindings. |
977 manager1->DidNavigateFrame(host1, true); | 1008 manager1->DidNavigateFrame(host1, true); |
978 SiteInstance* webui_instance = host1->GetSiteInstance(); | 1009 SiteInstance* webui_instance = host1->GetSiteInstance(); |
979 EXPECT_EQ(host1, manager1->current_frame_host()); | 1010 EXPECT_EQ(host1, manager1->current_frame_host()); |
980 EXPECT_TRUE( | 1011 EXPECT_TRUE( |
981 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1012 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
982 | 1013 |
983 // Now simulate clicking a link that opens in a new tab. | 1014 // Now simulate clicking a link that opens in a new tab. |
984 scoped_ptr<TestWebContents> web_contents2( | 1015 scoped_ptr<TestWebContents> web_contents2( |
985 TestWebContents::Create(browser_context(), webui_instance)); | 1016 TestWebContents::Create(browser_context(), webui_instance)); |
986 RenderFrameHostManager* manager2 = | 1017 RenderFrameHostManager* manager2 = |
987 web_contents2->GetRenderManagerForTesting(); | 1018 web_contents2->GetRenderManagerForTesting(); |
988 // Make sure the new RVH is considered live. This is usually done in | 1019 // Make sure the new RVH is considered live. This is usually done in |
989 // RenderWidgetHost::Init when opening a new tab from a link. | 1020 // RenderWidgetHost::Init when opening a new tab from a link. |
990 manager2->current_host()->CreateRenderView( | 1021 manager2->current_host()->CreateRenderView( |
991 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 1022 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
992 | 1023 |
993 const GURL kUrl2("chrome://foo/bar"); | 1024 const GURL kUrl2("chrome://foo/bar"); |
994 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1025 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
995 Referrer(), base::string16() /* title */, | 1026 Referrer(), base::string16() /* title */, |
996 ui::PAGE_TRANSITION_LINK, | 1027 ui::PAGE_TRANSITION_LINK, |
997 true /* is_renderer_init */); | 1028 true /* is_renderer_init */); |
998 RenderFrameHostImpl* host2 = manager2->Navigate(entry2); | 1029 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager2, entry2); |
999 | 1030 |
1000 // No cross-process transition happens because we are already in the right | 1031 // No cross-process transition happens because we are already in the right |
1001 // SiteInstance. We should grant bindings immediately. | 1032 // SiteInstance. We should grant bindings immediately. |
1002 EXPECT_EQ(host2, manager2->current_frame_host()); | 1033 EXPECT_EQ(host2, manager2->current_frame_host()); |
1003 EXPECT_TRUE( | 1034 EXPECT_TRUE( |
1004 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1035 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1005 | 1036 |
1006 manager2->DidNavigateFrame(host2, true); | 1037 manager2->DidNavigateFrame(host2, true); |
1007 } | 1038 } |
1008 | 1039 |
1009 // Tests that we don't end up in an inconsistent state if a page does a back and | 1040 // Tests that we don't end up in an inconsistent state if a page does a back and |
1010 // then reload. http://crbug.com/51680 | 1041 // then reload. http://crbug.com/51680 |
1011 // Also tests that only user-gesture navigations can interrupt cross-process | 1042 // Also tests that only user-gesture navigations can interrupt cross-process |
1012 // navigations. http://crbug.com/75195 | 1043 // navigations. http://crbug.com/75195 |
1013 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { | 1044 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { |
1014 const GURL kUrl1("http://www.google.com/"); | 1045 const GURL kUrl1("http://www.google.com/"); |
1015 const GURL kUrl2("http://www.evil-site.com/"); | 1046 const GURL kUrl2("http://www.evil-site.com/"); |
1016 | 1047 |
1017 // Navigate to a safe site, then an evil site. | 1048 // Navigate to a safe site, then an evil site. |
1018 // This will switch RenderFrameHosts. We cannot assert that the first and | 1049 // This will switch RenderFrameHosts. We cannot assert that the first and |
1019 // second RFHs are different, though, because the first one may be promptly | 1050 // second RFHs are different, though, because the first one may be promptly |
1020 // deleted. | 1051 // deleted. |
1021 contents()->NavigateAndCommit(kUrl1); | 1052 contents()->NavigateAndCommit(kUrl1); |
1022 contents()->NavigateAndCommit(kUrl2); | 1053 contents()->NavigateAndCommit(kUrl2); |
1023 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); | 1054 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); |
1024 | 1055 |
1025 // Now let's simulate the evil page calling history.back(). | 1056 // Now let's simulate the evil page calling history.back(). |
1026 contents()->OnGoToEntryAtOffset(-1); | 1057 contents()->OnGoToEntryAtOffset(-1); |
1058 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | |
1027 // We should have a new pending RFH. | 1059 // We should have a new pending RFH. |
1028 // Note that in this case, the navigation has not committed, so evil_rfh will | 1060 // Note that in this case, the navigation has not committed, so evil_rfh will |
1029 // not be deleted yet. | 1061 // not be deleted yet. |
1030 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); | 1062 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); |
1031 EXPECT_NE(evil_rfh->GetRenderViewHost(), | 1063 EXPECT_NE(evil_rfh->GetRenderViewHost(), |
1032 contents()->GetPendingMainFrame()->GetRenderViewHost()); | 1064 contents()->GetPendingMainFrame()->GetRenderViewHost()); |
1033 | 1065 |
1034 // Before that RFH has committed, the evil page reloads itself. | 1066 // Before that RFH has committed, the evil page reloads itself. |
1035 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1067 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1036 params.page_id = 1; | 1068 params.page_id = 1; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1132 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1101 | 1133 |
1102 contents()->NavigateAndCommit(kUrl2); | 1134 contents()->NavigateAndCommit(kUrl2); |
1103 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1135 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1104 rfh2->GetSiteInstance()->increment_active_frame_count(); | 1136 rfh2->GetSiteInstance()->increment_active_frame_count(); |
1105 | 1137 |
1106 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1138 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
1107 // happen, but we have seen it when going back quickly across many entries | 1139 // happen, but we have seen it when going back quickly across many entries |
1108 // (http://crbug.com/93427). | 1140 // (http://crbug.com/93427). |
1109 contents()->GetController().GoBack(); | 1141 contents()->GetController().GoBack(); |
1110 EXPECT_TRUE(rfh2->is_waiting_for_beforeunload_ack()); | 1142 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); |
1111 contents()->ProceedWithCrossSiteNavigation(); | 1143 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1112 EXPECT_FALSE(rfh2->is_waiting_for_beforeunload_ack()); | 1144 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); |
1113 | 1145 |
1114 // The back navigation commits. | 1146 // The back navigation commits. |
1115 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1147 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1116 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1148 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
1117 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1149 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
1118 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1150 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
1119 | 1151 |
1120 // We should be able to navigate forward. | 1152 // We should be able to navigate forward. |
1121 contents()->GetController().GoForward(); | 1153 contents()->GetController().GoForward(); |
1122 contents()->ProceedWithCrossSiteNavigation(); | 1154 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1123 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1155 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
1124 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1156 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
1125 EXPECT_EQ(rfh2, main_test_rfh()); | 1157 EXPECT_EQ(rfh2, main_test_rfh()); |
1126 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1158 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1127 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1159 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1128 rfh1->OnSwappedOut(); | 1160 rfh1->OnSwappedOut(); |
1129 EXPECT_TRUE(rfh1->is_swapped_out()); | 1161 EXPECT_TRUE(rfh1->is_swapped_out()); |
1130 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); | 1162 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
1131 } | 1163 } |
1132 | 1164 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 EXPECT_TRUE(contents()->HasOpener()); | 1315 EXPECT_TRUE(contents()->HasOpener()); |
1284 | 1316 |
1285 // Navigate to a cross-site URL (different SiteInstance but same | 1317 // Navigate to a cross-site URL (different SiteInstance but same |
1286 // BrowsingInstance). | 1318 // BrowsingInstance). |
1287 contents()->NavigateAndCommit(kUrl2); | 1319 contents()->NavigateAndCommit(kUrl2); |
1288 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1320 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1289 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1321 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1290 | 1322 |
1291 // Start a back navigation so that rfh1 becomes the pending RFH. | 1323 // Start a back navigation so that rfh1 becomes the pending RFH. |
1292 contents()->GetController().GoBack(); | 1324 contents()->GetController().GoBack(); |
1293 contents()->ProceedWithCrossSiteNavigation(); | 1325 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1294 | 1326 |
1295 // Disown the opener from rfh2. | 1327 // Disown the opener from rfh2. |
1296 rfh2->DidDisownOpener(); | 1328 rfh2->DidDisownOpener(); |
1297 | 1329 |
1298 // Ensure the opener is cleared. | 1330 // Ensure the opener is cleared. |
1299 EXPECT_FALSE(contents()->HasOpener()); | 1331 EXPECT_FALSE(contents()->HasOpener()); |
1300 | 1332 |
1301 // The back navigation commits. | 1333 // The back navigation commits. |
1302 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1334 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1303 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1335 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
(...skipping 20 matching lines...) Expand all Loading... | |
1324 | 1356 |
1325 // Navigate to a cross-site URL (different SiteInstance but same | 1357 // Navigate to a cross-site URL (different SiteInstance but same |
1326 // BrowsingInstance). | 1358 // BrowsingInstance). |
1327 contents()->NavigateAndCommit(kUrl2); | 1359 contents()->NavigateAndCommit(kUrl2); |
1328 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1360 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1329 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1361 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1330 | 1362 |
1331 // Commit a back navigation before the DidDisownOpener message arrives. | 1363 // Commit a back navigation before the DidDisownOpener message arrives. |
1332 // rfh1 will be kept alive because of the opener tab. | 1364 // rfh1 will be kept alive because of the opener tab. |
1333 contents()->GetController().GoBack(); | 1365 contents()->GetController().GoBack(); |
1334 contents()->ProceedWithCrossSiteNavigation(); | 1366 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1335 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1367 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1336 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1368 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
1337 | 1369 |
1338 // Disown the opener from rfh2. | 1370 // Disown the opener from rfh2. |
1339 rfh2->DidDisownOpener(); | 1371 rfh2->DidDisownOpener(); |
1340 EXPECT_FALSE(contents()->HasOpener()); | 1372 EXPECT_FALSE(contents()->HasOpener()); |
1341 } | 1373 } |
1342 | 1374 |
1343 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1375 // Test that we clean up swapped out RenderViewHosts when a process hosting |
1344 // those associated RenderViews crashes. http://crbug.com/258993 | 1376 // those associated RenderViews crashes. http://crbug.com/258993 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1380 Details<RenderProcessHost::RendererClosedDetails>(&details)); | 1412 Details<RenderProcessHost::RendererClosedDetails>(&details)); |
1381 rvh1->set_render_view_created(false); | 1413 rvh1->set_render_view_created(false); |
1382 | 1414 |
1383 // Ensure that the swapped out RenderViewHost has been deleted. | 1415 // Ensure that the swapped out RenderViewHost has been deleted. |
1384 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 1416 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
1385 rvh1->GetSiteInstance())); | 1417 rvh1->GetSiteInstance())); |
1386 | 1418 |
1387 // Reload the initial tab. This should recreate the opener's swapped out RVH | 1419 // Reload the initial tab. This should recreate the opener's swapped out RVH |
1388 // in the original SiteInstance. | 1420 // in the original SiteInstance. |
1389 contents()->GetController().Reload(true); | 1421 contents()->GetController().Reload(true); |
1422 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | |
1390 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( | 1423 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( |
1391 rvh1->GetSiteInstance())->GetRoutingID(), | 1424 rvh1->GetSiteInstance())->GetRoutingID(), |
1392 test_rvh()->opener_route_id()); | 1425 test_rvh()->opener_route_id()); |
1393 } | 1426 } |
1394 | 1427 |
1395 // Test that RenderViewHosts created for WebUI navigations are properly | 1428 // Test that RenderViewHosts created for WebUI navigations are properly |
1396 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost | 1429 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost |
1397 // is in the same process (http://crbug.com/79918). | 1430 // is in the same process (http://crbug.com/79918). |
1398 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { | 1431 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { |
1399 set_should_create_webui(true); | 1432 set_should_create_webui(true); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1572 contents()->NavigateAndCommit(kUrl1); | 1605 contents()->NavigateAndCommit(kUrl1); |
1573 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1606 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1574 | 1607 |
1575 // Start to close the tab, but assume it's unresponsive. | 1608 // Start to close the tab, but assume it's unresponsive. |
1576 rfh1->render_view_host()->ClosePage(); | 1609 rfh1->render_view_host()->ClosePage(); |
1577 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1610 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
1578 | 1611 |
1579 // Start a navigation to a new site. | 1612 // Start a navigation to a new site. |
1580 controller().LoadURL( | 1613 controller().LoadURL( |
1581 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1614 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1615 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1616 switches::kEnableBrowserSideNavigation)) { | |
1617 rfh1->PrepareForCommit(kUrl2); | |
1618 } | |
1582 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1619 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1583 | 1620 |
1584 // Simulate the unresponsiveness timer. The tab should close. | 1621 // Simulate the unresponsiveness timer. The tab should close. |
1585 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1622 contents()->RendererUnresponsive(rfh1->render_view_host()); |
1586 EXPECT_TRUE(close_delegate.is_closed()); | 1623 EXPECT_TRUE(close_delegate.is_closed()); |
1587 } | 1624 } |
1588 | 1625 |
1589 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1626 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
1590 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1627 // received. (SwapOut and the corresponding ACK always occur after commit.) |
1591 // Also tests that an early SwapOutACK is properly ignored. | 1628 // Also tests that an early SwapOutACK is properly ignored. |
1592 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1629 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
1593 const GURL kUrl1("http://www.google.com/"); | 1630 const GURL kUrl1("http://www.google.com/"); |
1594 const GURL kUrl2("http://www.chromium.org/"); | 1631 const GURL kUrl2("http://www.chromium.org/"); |
1595 | 1632 |
1596 // Navigate to the first page. | 1633 // Navigate to the first page. |
1597 contents()->NavigateAndCommit(kUrl1); | 1634 contents()->NavigateAndCommit(kUrl1); |
1598 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1635 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1599 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1636 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1600 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1637 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1601 | 1638 |
1602 // Navigate to new site, simulating onbeforeunload approval. | 1639 // Navigate to new site, simulating onbeforeunload approval. |
1603 controller().LoadURL( | 1640 controller().LoadURL( |
1604 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1641 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1605 base::TimeTicks now = base::TimeTicks::Now(); | 1642 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1606 contents()->GetMainFrame()->OnMessageReceived( | |
1607 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1608 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1643 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1609 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1644 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1610 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1645 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1611 | 1646 |
1612 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1647 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1613 // have no effect. | 1648 // have no effect. |
1614 rfh1->OnSwappedOut(); | 1649 rfh1->OnSwappedOut(); |
1615 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1650 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1616 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1651 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1617 | 1652 |
(...skipping 27 matching lines...) Expand all Loading... | |
1645 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1680 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1646 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1681 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1647 | 1682 |
1648 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1683 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1649 // not deleted on swap out. | 1684 // not deleted on swap out. |
1650 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1685 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1651 | 1686 |
1652 // Navigate to new site, simulating onbeforeunload approval. | 1687 // Navigate to new site, simulating onbeforeunload approval. |
1653 controller().LoadURL( | 1688 controller().LoadURL( |
1654 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1689 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1655 base::TimeTicks now = base::TimeTicks::Now(); | 1690 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1656 contents()->GetMainFrame()->OnMessageReceived( | |
1657 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1658 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1691 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1659 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1692 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1660 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1693 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1661 | 1694 |
1662 // The new page commits. | 1695 // The new page commits. |
1663 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1696 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1664 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1697 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1665 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1698 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1666 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1699 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1667 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1700 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
(...skipping 22 matching lines...) Expand all Loading... | |
1690 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1723 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1691 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1724 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1692 | 1725 |
1693 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1726 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1694 // not deleted on swap out. | 1727 // not deleted on swap out. |
1695 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1728 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1696 | 1729 |
1697 // Navigate to new site, simulating onbeforeunload approval. | 1730 // Navigate to new site, simulating onbeforeunload approval. |
1698 controller().LoadURL( | 1731 controller().LoadURL( |
1699 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1732 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1700 base::TimeTicks now = base::TimeTicks::Now(); | 1733 rfh1->PrepareForCommit(kUrl2); |
1701 rfh1->OnMessageReceived( | |
1702 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1703 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1734 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1704 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1735 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1705 | 1736 |
1706 // The new page commits. | 1737 // The new page commits. |
1707 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1738 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1708 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1739 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1709 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1740 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1710 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1741 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1711 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1742 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1712 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1743 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1786 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 1817 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
1787 std::string("frame_name"), SandboxFlags::NONE); | 1818 std::string("frame_name"), SandboxFlags::NONE); |
1788 RenderFrameHostManager* manager = | 1819 RenderFrameHostManager* manager = |
1789 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 1820 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
1790 | 1821 |
1791 // 1) The first navigation. -------------------------- | 1822 // 1) The first navigation. -------------------------- |
1792 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1823 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
1793 Referrer(), base::string16() /* title */, | 1824 Referrer(), base::string16() /* title */, |
1794 ui::PAGE_TRANSITION_TYPED, | 1825 ui::PAGE_TRANSITION_TYPED, |
1795 false /* is_renderer_init */); | 1826 false /* is_renderer_init */); |
1796 host = manager->Navigate(entry1); | 1827 host = GetFrameHostForNavigation(manager, entry1); |
1797 | 1828 |
1798 // The RenderFrameHost created in Init will be reused. | 1829 // The RenderFrameHost created in Init will be reused. |
1799 EXPECT_TRUE(host == manager->current_frame_host()); | 1830 EXPECT_TRUE(host == manager->current_frame_host()); |
1800 EXPECT_FALSE(manager->pending_frame_host()); | 1831 EXPECT_FALSE(GetPendingFrameHost(manager)); |
1801 | 1832 |
1802 // Commit. | 1833 // Commit. |
1803 manager->DidNavigateFrame(host, true); | 1834 manager->DidNavigateFrame(host, true); |
1804 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1835 // Commit to SiteInstance should be delayed until RenderFrame commit. |
1805 EXPECT_TRUE(host == manager->current_frame_host()); | 1836 EXPECT_TRUE(host == manager->current_frame_host()); |
1806 ASSERT_TRUE(host); | 1837 ASSERT_TRUE(host); |
1807 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1838 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1808 | 1839 |
1809 // 2) Cross-site navigate to next site. -------------- | 1840 // 2) Cross-site navigate to next site. -------------- |
1810 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1841 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
1811 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1842 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
1812 base::string16() /* title */, | 1843 base::string16() /* title */, |
1813 ui::PAGE_TRANSITION_LINK, | 1844 ui::PAGE_TRANSITION_LINK, |
1814 false /* is_renderer_init */); | 1845 false /* is_renderer_init */); |
1815 host = manager->Navigate(entry2); | 1846 host = GetFrameHostForNavigation(manager, entry2); |
1816 | 1847 |
1817 // A new RenderFrameHost should be created. | 1848 // A new RenderFrameHost should be created. |
1818 EXPECT_TRUE(manager->pending_frame_host()); | 1849 EXPECT_TRUE(GetPendingFrameHost(manager)); |
1819 ASSERT_EQ(host, manager->pending_frame_host()); | 1850 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
1820 ASSERT_NE(manager->current_frame_host(), manager->pending_frame_host()); | 1851 ASSERT_NE(manager->current_frame_host(), GetPendingFrameHost(manager)); |
1821 EXPECT_FALSE(contents()->cross_navigation_pending()) | 1852 EXPECT_FALSE(contents()->cross_navigation_pending()) |
1822 << "There should be no top-level pending navigation."; | 1853 << "There should be no top-level pending navigation."; |
1823 | 1854 |
1824 RenderFrameHostDeletedObserver delete_watcher(manager->pending_frame_host()); | 1855 RenderFrameHostDeletedObserver delete_watcher(GetPendingFrameHost(manager)); |
1825 EXPECT_FALSE(delete_watcher.deleted()); | 1856 EXPECT_FALSE(delete_watcher.deleted()); |
1826 | 1857 |
1827 // Extend the lifetime of the child frame's SiteInstance, pretending | 1858 // Extend the lifetime of the child frame's SiteInstance, pretending |
1828 // that there is another reference to it. | 1859 // that there is another reference to it. |
1829 scoped_refptr<SiteInstanceImpl> site_instance = | 1860 scoped_refptr<SiteInstanceImpl> site_instance = |
1830 manager->pending_frame_host()->GetSiteInstance(); | 1861 GetPendingFrameHost(manager)->GetSiteInstance(); |
1831 EXPECT_TRUE(site_instance->HasSite()); | 1862 EXPECT_TRUE(site_instance->HasSite()); |
1832 EXPECT_NE(site_instance, contents()->GetSiteInstance()); | 1863 EXPECT_NE(site_instance, contents()->GetSiteInstance()); |
1833 EXPECT_EQ(1U, site_instance->active_frame_count()); | 1864 EXPECT_EQ(1U, site_instance->active_frame_count()); |
1834 site_instance->increment_active_frame_count(); | 1865 site_instance->increment_active_frame_count(); |
1835 EXPECT_EQ(2U, site_instance->active_frame_count()); | 1866 EXPECT_EQ(2U, site_instance->active_frame_count()); |
1836 | 1867 |
1837 // Now detach the child FrameTreeNode. This should kill the pending host. | 1868 // Now detach the child FrameTreeNode. This should kill the pending host. |
1838 manager->current_frame_host()->OnMessageReceived( | 1869 manager->current_frame_host()->OnMessageReceived( |
1839 FrameHostMsg_Detach(manager->current_frame_host()->GetRoutingID())); | 1870 FrameHostMsg_Detach(manager->current_frame_host()->GetRoutingID())); |
1840 | 1871 |
1841 EXPECT_TRUE(delete_watcher.deleted()); | 1872 EXPECT_TRUE(delete_watcher.deleted()); |
1842 | 1873 |
1843 EXPECT_EQ(1U, site_instance->active_frame_count()); | 1874 EXPECT_EQ(1U, site_instance->active_frame_count()); |
1844 site_instance->decrement_active_frame_count(); | 1875 site_instance->decrement_active_frame_count(); |
1845 | 1876 |
1846 #if 0 | 1877 #if 0 |
1847 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | 1878 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. |
1848 // Enable this assert below once the proxies to the subframe are correctly | 1879 // Enable this assert below once the proxies to the subframe are correctly |
1849 // cleaned up after detach. http://crbug.com/444955. | 1880 // cleaned up after detach. http://crbug.com/444955. |
1850 ASSERT_TRUE(site_instance->HasOneRef()) | 1881 ASSERT_TRUE(site_instance->HasOneRef()) |
1851 << "This SiteInstance should be destroyable now."; | 1882 << "This SiteInstance should be destroyable now."; |
1852 #endif | 1883 #endif |
1853 } | 1884 } |
1854 | 1885 |
1855 } // namespace content | 1886 } // namespace content |
OLD | NEW |