OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/browser/frame_host/cross_site_transferring_request.h" | 9 #include "content/browser/frame_host/cross_site_transferring_request.h" |
10 #include "content/browser/frame_host/navigation_before_commit_info.h" | 10 #include "content/browser/frame_host/navigation_before_commit_info.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_widget_host_iterator.h" | 25 #include "content/public/browser/render_widget_host_iterator.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
28 #include "content/public/browser/web_ui_controller.h" | 28 #include "content/public/browser/web_ui_controller.h" |
29 #include "content/public/common/bindings_policy.h" | 29 #include "content/public/common/bindings_policy.h" |
30 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
31 #include "content/public/common/javascript_message_type.h" | 31 #include "content/public/common/javascript_message_type.h" |
32 #include "content/public/common/page_transition_types.h" | |
33 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
34 #include "content/public/common/url_utils.h" | 33 #include "content/public/common/url_utils.h" |
35 #include "content/public/test/mock_render_process_host.h" | 34 #include "content/public/test/mock_render_process_host.h" |
36 #include "content/public/test/test_notification_tracker.h" | 35 #include "content/public/test/test_notification_tracker.h" |
37 #include "content/test/test_content_browser_client.h" | 36 #include "content/test/test_content_browser_client.h" |
38 #include "content/test/test_content_client.h" | 37 #include "content/test/test_content_client.h" |
39 #include "content/test/test_render_frame_host.h" | 38 #include "content/test/test_render_frame_host.h" |
40 #include "content/test/test_render_view_host.h" | 39 #include "content/test/test_render_view_host.h" |
41 #include "content/test/test_web_contents.h" | 40 #include "content/test/test_web_contents.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "ui/base/page_transition_types.h" |
43 | 43 |
44 namespace content { | 44 namespace content { |
45 namespace { | 45 namespace { |
46 | 46 |
47 class RenderFrameHostManagerTestWebUIControllerFactory | 47 class RenderFrameHostManagerTestWebUIControllerFactory |
48 : public WebUIControllerFactory { | 48 : public WebUIControllerFactory { |
49 public: | 49 public: |
50 RenderFrameHostManagerTestWebUIControllerFactory() | 50 RenderFrameHostManagerTestWebUIControllerFactory() |
51 : should_create_webui_(false) { | 51 : should_create_webui_(false) { |
52 } | 52 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 | 272 |
273 void set_should_create_webui(bool should_create_webui) { | 273 void set_should_create_webui(bool should_create_webui) { |
274 factory_.set_should_create_webui(should_create_webui); | 274 factory_.set_should_create_webui(should_create_webui); |
275 } | 275 } |
276 | 276 |
277 void NavigateActiveAndCommit(const GURL& url) { | 277 void NavigateActiveAndCommit(const GURL& url) { |
278 // Note: we navigate the active RenderFrameHost because previous navigations | 278 // Note: we navigate the active RenderFrameHost because previous navigations |
279 // won't have committed yet, so NavigateAndCommit does the wrong thing | 279 // won't have committed yet, so NavigateAndCommit does the wrong thing |
280 // for us. | 280 // for us. |
281 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 281 controller().LoadURL( |
| 282 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
282 TestRenderViewHost* old_rvh = test_rvh(); | 283 TestRenderViewHost* old_rvh = test_rvh(); |
283 | 284 |
284 // Simulate the BeforeUnload_ACK that is received from the current renderer | 285 // Simulate the BeforeUnload_ACK that is received from the current renderer |
285 // for a cross-site navigation. | 286 // for a cross-site navigation. |
286 if (old_rvh != active_rvh()) { | 287 if (old_rvh != active_rvh()) { |
287 old_rvh->SendBeforeUnloadACK(true); | 288 old_rvh->SendBeforeUnloadACK(true); |
288 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, old_rvh->rvh_state()); | 289 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, old_rvh->rvh_state()); |
289 } | 290 } |
290 | 291 |
291 // Commit the navigation with a new page ID. | 292 // Commit the navigation with a new page ID. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 TestRenderViewHost* CreateSwappedOutRenderViewHost() { | 349 TestRenderViewHost* CreateSwappedOutRenderViewHost() { |
349 const GURL kChromeURL("chrome://foo"); | 350 const GURL kChromeURL("chrome://foo"); |
350 const GURL kDestUrl("http://www.google.com/"); | 351 const GURL kDestUrl("http://www.google.com/"); |
351 | 352 |
352 // Navigate our first tab to a chrome url and then to the destination. | 353 // Navigate our first tab to a chrome url and then to the destination. |
353 NavigateActiveAndCommit(kChromeURL); | 354 NavigateActiveAndCommit(kChromeURL); |
354 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 355 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
355 | 356 |
356 // Navigate to a cross-site URL. | 357 // Navigate to a cross-site URL. |
357 contents()->GetController().LoadURL( | 358 contents()->GetController().LoadURL( |
358 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 359 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
359 EXPECT_TRUE(contents()->cross_navigation_pending()); | 360 EXPECT_TRUE(contents()->cross_navigation_pending()); |
360 | 361 |
361 // Manually increase the number of active views in the | 362 // Manually increase the number of active views in the |
362 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 363 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
363 // destroyed when it gets swapped out. | 364 // destroyed when it gets swapped out. |
364 static_cast<SiteInstanceImpl*>(ntp_rfh->GetSiteInstance())-> | 365 static_cast<SiteInstanceImpl*>(ntp_rfh->GetSiteInstance())-> |
365 increment_active_view_count(); | 366 increment_active_view_count(); |
366 | 367 |
367 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 368 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
368 CHECK(dest_rfh); | 369 CHECK(dest_rfh); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 411 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
411 | 412 |
412 // Make a second tab. | 413 // Make a second tab. |
413 scoped_ptr<TestWebContents> contents2( | 414 scoped_ptr<TestWebContents> contents2( |
414 TestWebContents::Create(browser_context(), NULL)); | 415 TestWebContents::Create(browser_context(), NULL)); |
415 | 416 |
416 // Load the two URLs in the second tab. Note that the first navigation creates | 417 // Load the two URLs in the second tab. Note that the first navigation creates |
417 // a RFH that's not pending (since there is no cross-site transition), so | 418 // a RFH that's not pending (since there is no cross-site transition), so |
418 // we use the committed one. | 419 // we use the committed one. |
419 contents2->GetController().LoadURL( | 420 contents2->GetController().LoadURL( |
420 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 421 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
421 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 422 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
422 EXPECT_FALSE(contents2->cross_navigation_pending()); | 423 EXPECT_FALSE(contents2->cross_navigation_pending()); |
423 ntp_rfh2->SendNavigate(100, kChromeUrl); | 424 ntp_rfh2->SendNavigate(100, kChromeUrl); |
424 | 425 |
425 // The second one is the opposite, creating a cross-site transition and | 426 // The second one is the opposite, creating a cross-site transition and |
426 // requiring a beforeunload ack. | 427 // requiring a beforeunload ack. |
427 contents2->GetController().LoadURL( | 428 contents2->GetController().LoadURL( |
428 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 429 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
429 EXPECT_TRUE(contents2->cross_navigation_pending()); | 430 EXPECT_TRUE(contents2->cross_navigation_pending()); |
430 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 431 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
431 ASSERT_TRUE(dest_rfh2); | 432 ASSERT_TRUE(dest_rfh2); |
432 | 433 |
433 ntp_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 434 ntp_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); |
434 dest_rfh2->SendNavigate(101, kDestUrl); | 435 dest_rfh2->SendNavigate(101, kDestUrl); |
435 | 436 |
436 // The two RFH's should be different in every way. | 437 // The two RFH's should be different in every way. |
437 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 438 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
438 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 439 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
439 dest_rfh2->GetSiteInstance()); | 440 dest_rfh2->GetSiteInstance()); |
440 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 441 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
441 contents()->GetMainFrame()->GetSiteInstance())); | 442 contents()->GetMainFrame()->GetSiteInstance())); |
442 | 443 |
443 // Navigate both to the new tab page, and verify that they share a | 444 // Navigate both to the new tab page, and verify that they share a |
444 // RenderProcessHost (not a SiteInstance). | 445 // RenderProcessHost (not a SiteInstance). |
445 NavigateActiveAndCommit(kChromeUrl); | 446 NavigateActiveAndCommit(kChromeUrl); |
446 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 447 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
447 | 448 |
448 contents2->GetController().LoadURL( | 449 contents2->GetController().LoadURL( |
449 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 450 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
450 dest_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 451 dest_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); |
451 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 452 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
452 | 453 |
453 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 454 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
454 contents2->GetMainFrame()->GetSiteInstance()); | 455 contents2->GetMainFrame()->GetSiteInstance()); |
455 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 456 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
456 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 457 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
457 } | 458 } |
458 | 459 |
459 // Ensure that the browser ignores most IPC messages that arrive from a | 460 // Ensure that the browser ignores most IPC messages that arrive from a |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 // We have to navigate to some page at first since without this, the first | 733 // We have to navigate to some page at first since without this, the first |
733 // navigation will reuse the SiteInstance created by Init(), and the second | 734 // navigation will reuse the SiteInstance created by Init(), and the second |
734 // one will create a new SiteInstance. Because current_instance and | 735 // one will create a new SiteInstance. Because current_instance and |
735 // new_instance will be different, a new RenderViewHost will be created for | 736 // new_instance will be different, a new RenderViewHost will be created for |
736 // the second navigation. We have to avoid this in order to exercise the | 737 // the second navigation. We have to avoid this in order to exercise the |
737 // target code patch. | 738 // target code patch. |
738 NavigateActiveAndCommit(kChromeUrl); | 739 NavigateActiveAndCommit(kChromeUrl); |
739 | 740 |
740 // Navigate. | 741 // Navigate. |
741 controller().LoadURL( | 742 controller().LoadURL( |
742 kUrl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 743 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
743 // Simulate response from RenderFrame for DispatchBeforeUnload. | 744 // Simulate response from RenderFrame for DispatchBeforeUnload. |
744 base::TimeTicks now = base::TimeTicks::Now(); | 745 base::TimeTicks now = base::TimeTicks::Now(); |
745 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK( | 746 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK( |
746 contents()->GetMainFrame()->GetRoutingID(), true, now, now)); | 747 contents()->GetMainFrame()->GetRoutingID(), true, now, now)); |
747 ASSERT_TRUE(contents()->GetPendingMainFrame()) | 748 ASSERT_TRUE(contents()->GetPendingMainFrame()) |
748 << "Expected new pending RenderFrameHost to be created."; | 749 << "Expected new pending RenderFrameHost to be created."; |
749 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); | 750 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); |
750 int32 new_id = | 751 int32 new_id = |
751 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; | 752 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; |
752 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); | 753 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); |
753 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 754 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
754 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 755 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
755 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 756 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
756 EXPECT_FALSE(controller().GetPendingEntry()); | 757 EXPECT_FALSE(controller().GetPendingEntry()); |
757 // Because we're using TestWebContents and TestRenderViewHost in this | 758 // Because we're using TestWebContents and TestRenderViewHost in this |
758 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no | 759 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no |
759 // EnableViewSourceMode message, here. | 760 // EnableViewSourceMode message, here. |
760 | 761 |
761 // Clear queued messages before load. | 762 // Clear queued messages before load. |
762 process()->sink().ClearMessages(); | 763 process()->sink().ClearMessages(); |
763 // Navigate, again. | 764 // Navigate, again. |
764 controller().LoadURL( | 765 controller().LoadURL( |
765 kUrl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 766 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
766 // The same RenderViewHost should be reused. | 767 // The same RenderViewHost should be reused. |
767 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 768 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
768 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); | 769 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); |
769 // Navigate using the returned page_id. | 770 // Navigate using the returned page_id. |
770 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); | 771 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); |
771 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 772 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
772 EXPECT_FALSE(controller().GetPendingEntry()); | 773 EXPECT_FALSE(controller().GetPendingEntry()); |
773 // New message should be sent out to make sure to enter view-source mode. | 774 // New message should be sent out to make sure to enter view-source mode. |
774 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 775 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
775 ViewMsg_EnableViewSourceMode::ID)); | 776 ViewMsg_EnableViewSourceMode::ID)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 811 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
811 Source<WebContents>(web_contents.get())); | 812 Source<WebContents>(web_contents.get())); |
812 | 813 |
813 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 814 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
814 RenderFrameHostImpl* host; | 815 RenderFrameHostImpl* host; |
815 | 816 |
816 // 1) The first navigation. -------------------------- | 817 // 1) The first navigation. -------------------------- |
817 const GURL kUrl1("http://www.google.com/"); | 818 const GURL kUrl1("http://www.google.com/"); |
818 NavigationEntryImpl entry1( | 819 NavigationEntryImpl entry1( |
819 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 820 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
820 base::string16() /* title */, PAGE_TRANSITION_TYPED, | 821 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
821 false /* is_renderer_init */); | 822 false /* is_renderer_init */); |
822 host = manager->Navigate(entry1); | 823 host = manager->Navigate(entry1); |
823 | 824 |
824 // The RenderFrameHost created in Init will be reused. | 825 // The RenderFrameHost created in Init will be reused. |
825 EXPECT_TRUE(host == manager->current_frame_host()); | 826 EXPECT_TRUE(host == manager->current_frame_host()); |
826 EXPECT_FALSE(manager->pending_frame_host()); | 827 EXPECT_FALSE(manager->pending_frame_host()); |
827 | 828 |
828 // Commit. | 829 // Commit. |
829 manager->DidNavigateFrame(host); | 830 manager->DidNavigateFrame(host); |
830 // Commit to SiteInstance should be delayed until RenderView commit. | 831 // Commit to SiteInstance should be delayed until RenderView commit. |
831 EXPECT_TRUE(host == manager->current_frame_host()); | 832 EXPECT_TRUE(host == manager->current_frame_host()); |
832 ASSERT_TRUE(host); | 833 ASSERT_TRUE(host); |
833 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 834 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> |
834 HasSite()); | 835 HasSite()); |
835 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); | 836 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); |
836 | 837 |
837 // 2) Navigate to next site. ------------------------- | 838 // 2) Navigate to next site. ------------------------- |
838 const GURL kUrl2("http://www.google.com/foo"); | 839 const GURL kUrl2("http://www.google.com/foo"); |
839 NavigationEntryImpl entry2( | 840 NavigationEntryImpl entry2( |
840 NULL /* instance */, -1 /* page_id */, kUrl2, | 841 NULL /* instance */, -1 /* page_id */, kUrl2, |
841 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 842 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
842 base::string16() /* title */, PAGE_TRANSITION_LINK, | 843 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
843 true /* is_renderer_init */); | 844 true /* is_renderer_init */); |
844 host = manager->Navigate(entry2); | 845 host = manager->Navigate(entry2); |
845 | 846 |
846 // The RenderFrameHost created in Init will be reused. | 847 // The RenderFrameHost created in Init will be reused. |
847 EXPECT_TRUE(host == manager->current_frame_host()); | 848 EXPECT_TRUE(host == manager->current_frame_host()); |
848 EXPECT_FALSE(manager->pending_frame_host()); | 849 EXPECT_FALSE(manager->pending_frame_host()); |
849 | 850 |
850 // Commit. | 851 // Commit. |
851 manager->DidNavigateFrame(host); | 852 manager->DidNavigateFrame(host); |
852 EXPECT_TRUE(host == manager->current_frame_host()); | 853 EXPECT_TRUE(host == manager->current_frame_host()); |
853 ASSERT_TRUE(host); | 854 ASSERT_TRUE(host); |
854 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 855 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> |
855 HasSite()); | 856 HasSite()); |
856 | 857 |
857 // 3) Cross-site navigate to next site. -------------- | 858 // 3) Cross-site navigate to next site. -------------- |
858 const GURL kUrl3("http://webkit.org/"); | 859 const GURL kUrl3("http://webkit.org/"); |
859 NavigationEntryImpl entry3( | 860 NavigationEntryImpl entry3( |
860 NULL /* instance */, -1 /* page_id */, kUrl3, | 861 NULL /* instance */, -1 /* page_id */, kUrl3, |
861 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 862 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
862 base::string16() /* title */, PAGE_TRANSITION_LINK, | 863 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
863 false /* is_renderer_init */); | 864 false /* is_renderer_init */); |
864 host = manager->Navigate(entry3); | 865 host = manager->Navigate(entry3); |
865 | 866 |
866 // A new RenderFrameHost should be created. | 867 // A new RenderFrameHost should be created. |
867 EXPECT_TRUE(manager->pending_frame_host()); | 868 EXPECT_TRUE(manager->pending_frame_host()); |
868 ASSERT_EQ(host, manager->pending_frame_host()); | 869 ASSERT_EQ(host, manager->pending_frame_host()); |
869 | 870 |
870 notifications.Reset(); | 871 notifications.Reset(); |
871 | 872 |
872 // Commit. | 873 // Commit. |
(...skipping 17 matching lines...) Expand all Loading... |
890 | 891 |
891 scoped_ptr<TestWebContents> web_contents( | 892 scoped_ptr<TestWebContents> web_contents( |
892 TestWebContents::Create(browser_context(), instance)); | 893 TestWebContents::Create(browser_context(), instance)); |
893 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 894 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
894 | 895 |
895 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 896 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
896 | 897 |
897 const GURL kUrl("chrome://foo"); | 898 const GURL kUrl("chrome://foo"); |
898 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 899 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
899 Referrer(), base::string16() /* title */, | 900 Referrer(), base::string16() /* title */, |
900 PAGE_TRANSITION_TYPED, | 901 ui::PAGE_TRANSITION_TYPED, |
901 false /* is_renderer_init */); | 902 false /* is_renderer_init */); |
902 RenderFrameHostImpl* host = manager->Navigate(entry); | 903 RenderFrameHostImpl* host = manager->Navigate(entry); |
903 | 904 |
904 // We commit the pending RenderFrameHost immediately because the previous | 905 // We commit the pending RenderFrameHost immediately because the previous |
905 // RenderFrameHost was not live. We test a case where it is live in | 906 // RenderFrameHost was not live. We test a case where it is live in |
906 // WebUIInNewTab. | 907 // WebUIInNewTab. |
907 EXPECT_TRUE(host); | 908 EXPECT_TRUE(host); |
908 EXPECT_EQ(host, manager->current_frame_host()); | 909 EXPECT_EQ(host, manager->current_frame_host()); |
909 EXPECT_FALSE(manager->pending_frame_host()); | 910 EXPECT_FALSE(manager->pending_frame_host()); |
910 | 911 |
(...skipping 30 matching lines...) Expand all Loading... |
941 // Test the case that new RVH is considered live. | 942 // Test the case that new RVH is considered live. |
942 manager1->current_host()->CreateRenderView( | 943 manager1->current_host()->CreateRenderView( |
943 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 944 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
944 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); | 945 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); |
945 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); | 946 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); |
946 | 947 |
947 // Navigate to a WebUI page. | 948 // Navigate to a WebUI page. |
948 const GURL kUrl1("chrome://foo"); | 949 const GURL kUrl1("chrome://foo"); |
949 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 950 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
950 Referrer(), base::string16() /* title */, | 951 Referrer(), base::string16() /* title */, |
951 PAGE_TRANSITION_TYPED, | 952 ui::PAGE_TRANSITION_TYPED, |
952 false /* is_renderer_init */); | 953 false /* is_renderer_init */); |
953 RenderFrameHostImpl* host1 = manager1->Navigate(entry1); | 954 RenderFrameHostImpl* host1 = manager1->Navigate(entry1); |
954 | 955 |
955 // We should have a pending navigation to the WebUI RenderViewHost. | 956 // We should have a pending navigation to the WebUI RenderViewHost. |
956 // It should already have bindings. | 957 // It should already have bindings. |
957 EXPECT_EQ(host1, manager1->pending_frame_host()); | 958 EXPECT_EQ(host1, manager1->pending_frame_host()); |
958 EXPECT_NE(host1, manager1->current_frame_host()); | 959 EXPECT_NE(host1, manager1->current_frame_host()); |
959 EXPECT_TRUE( | 960 EXPECT_TRUE( |
960 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 961 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
961 | 962 |
(...skipping 10 matching lines...) Expand all Loading... |
972 RenderFrameHostManager* manager2 = | 973 RenderFrameHostManager* manager2 = |
973 web_contents2->GetRenderManagerForTesting(); | 974 web_contents2->GetRenderManagerForTesting(); |
974 // Make sure the new RVH is considered live. This is usually done in | 975 // Make sure the new RVH is considered live. This is usually done in |
975 // RenderWidgetHost::Init when opening a new tab from a link. | 976 // RenderWidgetHost::Init when opening a new tab from a link. |
976 manager2->current_host()->CreateRenderView( | 977 manager2->current_host()->CreateRenderView( |
977 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 978 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
978 | 979 |
979 const GURL kUrl2("chrome://foo/bar"); | 980 const GURL kUrl2("chrome://foo/bar"); |
980 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 981 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
981 Referrer(), base::string16() /* title */, | 982 Referrer(), base::string16() /* title */, |
982 PAGE_TRANSITION_LINK, | 983 ui::PAGE_TRANSITION_LINK, |
983 true /* is_renderer_init */); | 984 true /* is_renderer_init */); |
984 RenderFrameHostImpl* host2 = manager2->Navigate(entry2); | 985 RenderFrameHostImpl* host2 = manager2->Navigate(entry2); |
985 | 986 |
986 // No cross-process transition happens because we are already in the right | 987 // No cross-process transition happens because we are already in the right |
987 // SiteInstance. We should grant bindings immediately. | 988 // SiteInstance. We should grant bindings immediately. |
988 EXPECT_EQ(host2, manager2->current_frame_host()); | 989 EXPECT_EQ(host2, manager2->current_frame_host()); |
989 EXPECT_TRUE( | 990 EXPECT_TRUE( |
990 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 991 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
991 | 992 |
992 manager2->DidNavigateFrame(host2); | 993 manager2->DidNavigateFrame(host2); |
(...skipping 19 matching lines...) Expand all Loading... |
1012 // Note that in this case, the navigation has not committed, so evil_rfh will | 1013 // Note that in this case, the navigation has not committed, so evil_rfh will |
1013 // not be deleted yet. | 1014 // not be deleted yet. |
1014 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); | 1015 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); |
1015 EXPECT_NE(evil_rfh->GetRenderViewHost(), | 1016 EXPECT_NE(evil_rfh->GetRenderViewHost(), |
1016 contents()->GetPendingMainFrame()->GetRenderViewHost()); | 1017 contents()->GetPendingMainFrame()->GetRenderViewHost()); |
1017 | 1018 |
1018 // Before that RFH has committed, the evil page reloads itself. | 1019 // Before that RFH has committed, the evil page reloads itself. |
1019 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1020 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1020 params.page_id = 1; | 1021 params.page_id = 1; |
1021 params.url = kUrl2; | 1022 params.url = kUrl2; |
1022 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; | 1023 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
1023 params.should_update_history = false; | 1024 params.should_update_history = false; |
1024 params.gesture = NavigationGestureAuto; | 1025 params.gesture = NavigationGestureAuto; |
1025 params.was_within_same_page = false; | 1026 params.was_within_same_page = false; |
1026 params.is_post = false; | 1027 params.is_post = false; |
1027 params.page_state = PageState::CreateFromURL(kUrl2); | 1028 params.page_state = PageState::CreateFromURL(kUrl2); |
1028 | 1029 |
1029 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh, | 1030 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh, |
1030 params); | 1031 params); |
1031 | 1032 |
1032 // That should have cancelled the pending RFH, and the evil RFH should be the | 1033 // That should have cancelled the pending RFH, and the evil RFH should be the |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 TestWebContents::Create(browser_context(), instance)); | 1390 TestWebContents::Create(browser_context(), instance)); |
1390 | 1391 |
1391 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1392 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1392 | 1393 |
1393 RenderFrameHostImpl* host; | 1394 RenderFrameHostImpl* host; |
1394 | 1395 |
1395 // 1) The first navigation. -------------------------- | 1396 // 1) The first navigation. -------------------------- |
1396 const GURL kUrl1("http://www.google.com/"); | 1397 const GURL kUrl1("http://www.google.com/"); |
1397 NavigationEntryImpl entry1( | 1398 NavigationEntryImpl entry1( |
1398 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1399 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
1399 base::string16() /* title */, PAGE_TRANSITION_TYPED, | 1400 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1400 false /* is_renderer_init */); | 1401 false /* is_renderer_init */); |
1401 host = manager->Navigate(entry1); | 1402 host = manager->Navigate(entry1); |
1402 | 1403 |
1403 // The RenderFrameHost created in Init will be reused. | 1404 // The RenderFrameHost created in Init will be reused. |
1404 EXPECT_TRUE(host == manager->current_frame_host()); | 1405 EXPECT_TRUE(host == manager->current_frame_host()); |
1405 EXPECT_FALSE(manager->pending_frame_host()); | 1406 EXPECT_FALSE(manager->pending_frame_host()); |
1406 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1407 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
1407 | 1408 |
1408 // Commit. | 1409 // Commit. |
1409 manager->DidNavigateFrame(host); | 1410 manager->DidNavigateFrame(host); |
1410 // Commit to SiteInstance should be delayed until RenderView commit. | 1411 // Commit to SiteInstance should be delayed until RenderView commit. |
1411 EXPECT_EQ(host, manager->current_frame_host()); | 1412 EXPECT_EQ(host, manager->current_frame_host()); |
1412 ASSERT_TRUE(host); | 1413 ASSERT_TRUE(host); |
1413 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 1414 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> |
1414 HasSite()); | 1415 HasSite()); |
1415 | 1416 |
1416 // 2) Navigate to a different domain. ------------------------- | 1417 // 2) Navigate to a different domain. ------------------------- |
1417 // Guests stay in the same process on navigation. | 1418 // Guests stay in the same process on navigation. |
1418 const GURL kUrl2("http://www.chromium.org"); | 1419 const GURL kUrl2("http://www.chromium.org"); |
1419 NavigationEntryImpl entry2( | 1420 NavigationEntryImpl entry2( |
1420 NULL /* instance */, -1 /* page_id */, kUrl2, | 1421 NULL /* instance */, -1 /* page_id */, kUrl2, |
1421 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1422 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
1422 base::string16() /* title */, PAGE_TRANSITION_LINK, | 1423 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
1423 true /* is_renderer_init */); | 1424 true /* is_renderer_init */); |
1424 host = manager->Navigate(entry2); | 1425 host = manager->Navigate(entry2); |
1425 | 1426 |
1426 // The RenderFrameHost created in Init will be reused. | 1427 // The RenderFrameHost created in Init will be reused. |
1427 EXPECT_EQ(host, manager->current_frame_host()); | 1428 EXPECT_EQ(host, manager->current_frame_host()); |
1428 EXPECT_FALSE(manager->pending_frame_host()); | 1429 EXPECT_FALSE(manager->pending_frame_host()); |
1429 | 1430 |
1430 // Commit. | 1431 // Commit. |
1431 manager->DidNavigateFrame(host); | 1432 manager->DidNavigateFrame(host); |
1432 EXPECT_EQ(host, manager->current_frame_host()); | 1433 EXPECT_EQ(host, manager->current_frame_host()); |
(...skipping 15 matching lines...) Expand all Loading... |
1448 web_contents->SetDelegate(&delegate); | 1449 web_contents->SetDelegate(&delegate); |
1449 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 1450 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
1450 Source<WebContents>(web_contents.get())); | 1451 Source<WebContents>(web_contents.get())); |
1451 | 1452 |
1452 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1453 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1453 | 1454 |
1454 // 1) The first navigation. -------------------------- | 1455 // 1) The first navigation. -------------------------- |
1455 const GURL kUrl1("http://www.google.com/"); | 1456 const GURL kUrl1("http://www.google.com/"); |
1456 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1457 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
1457 Referrer(), base::string16() /* title */, | 1458 Referrer(), base::string16() /* title */, |
1458 PAGE_TRANSITION_TYPED, | 1459 ui::PAGE_TRANSITION_TYPED, |
1459 false /* is_renderer_init */); | 1460 false /* is_renderer_init */); |
1460 RenderFrameHostImpl* host = manager->Navigate(entry1); | 1461 RenderFrameHostImpl* host = manager->Navigate(entry1); |
1461 | 1462 |
1462 // The RenderFrameHost created in Init will be reused. | 1463 // The RenderFrameHost created in Init will be reused. |
1463 EXPECT_EQ(host, manager->current_frame_host()); | 1464 EXPECT_EQ(host, manager->current_frame_host()); |
1464 EXPECT_FALSE(manager->pending_frame_host()); | 1465 EXPECT_FALSE(manager->pending_frame_host()); |
1465 | 1466 |
1466 // We should observe a notification. | 1467 // We should observe a notification. |
1467 EXPECT_TRUE( | 1468 EXPECT_TRUE( |
1468 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1469 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
1469 notifications.Reset(); | 1470 notifications.Reset(); |
1470 | 1471 |
1471 // Commit. | 1472 // Commit. |
1472 manager->DidNavigateFrame(host); | 1473 manager->DidNavigateFrame(host); |
1473 | 1474 |
1474 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1475 // Commit to SiteInstance should be delayed until RenderFrame commits. |
1475 EXPECT_EQ(host, manager->current_frame_host()); | 1476 EXPECT_EQ(host, manager->current_frame_host()); |
1476 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 1477 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> |
1477 HasSite()); | 1478 HasSite()); |
1478 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); | 1479 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); |
1479 | 1480 |
1480 // 2) Cross-site navigate to next site. ------------------------- | 1481 // 2) Cross-site navigate to next site. ------------------------- |
1481 const GURL kUrl2("http://www.example.com"); | 1482 const GURL kUrl2("http://www.example.com"); |
1482 NavigationEntryImpl entry2( | 1483 NavigationEntryImpl entry2( |
1483 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1484 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
1484 base::string16() /* title */, PAGE_TRANSITION_TYPED, | 1485 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1485 false /* is_renderer_init */); | 1486 false /* is_renderer_init */); |
1486 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1487 RenderFrameHostImpl* host2 = manager->Navigate(entry2); |
1487 | 1488 |
1488 // A new RenderFrameHost should be created. | 1489 // A new RenderFrameHost should be created. |
1489 ASSERT_EQ(host2, manager->pending_frame_host()); | 1490 ASSERT_EQ(host2, manager->pending_frame_host()); |
1490 EXPECT_NE(host2, host); | 1491 EXPECT_NE(host2, host); |
1491 | 1492 |
1492 EXPECT_EQ(host, manager->current_frame_host()); | 1493 EXPECT_EQ(host, manager->current_frame_host()); |
1493 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | 1494 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); |
1494 EXPECT_EQ(host2, manager->pending_frame_host()); | 1495 EXPECT_EQ(host2, manager->pending_frame_host()); |
(...skipping 17 matching lines...) Expand all Loading... |
1512 const GURL kUrl2("http://www.chromium.org/"); | 1513 const GURL kUrl2("http://www.chromium.org/"); |
1513 | 1514 |
1514 // Navigate to the first page. | 1515 // Navigate to the first page. |
1515 contents()->NavigateAndCommit(kUrl1); | 1516 contents()->NavigateAndCommit(kUrl1); |
1516 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1517 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1517 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1518 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); |
1518 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1519 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1519 rfh1->GetRenderViewHost()->rvh_state()); | 1520 rfh1->GetRenderViewHost()->rvh_state()); |
1520 | 1521 |
1521 // Navigate to new site, simulating onbeforeunload approval. | 1522 // Navigate to new site, simulating onbeforeunload approval. |
1522 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1523 controller().LoadURL( |
| 1524 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1523 base::TimeTicks now = base::TimeTicks::Now(); | 1525 base::TimeTicks now = base::TimeTicks::Now(); |
1524 contents()->GetMainFrame()->OnMessageReceived( | 1526 contents()->GetMainFrame()->OnMessageReceived( |
1525 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1527 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1526 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1528 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1527 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1529 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1528 rfh1->GetRenderViewHost()->rvh_state()); | 1530 rfh1->GetRenderViewHost()->rvh_state()); |
1529 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1531 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1530 | 1532 |
1531 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1533 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1532 // have no effect. | 1534 // have no effect. |
1533 rfh1->OnSwappedOut(false); | 1535 rfh1->OnSwappedOut(false); |
1534 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1536 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1535 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1537 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1536 rfh1->GetRenderViewHost()->rvh_state()); | 1538 rfh1->GetRenderViewHost()->rvh_state()); |
1537 | 1539 |
1538 // The new page commits. | 1540 // The new page commits. |
1539 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | 1541 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1540 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1542 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1541 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1543 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1542 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1544 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1543 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1545 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1544 rfh2->GetRenderViewHost()->rvh_state()); | 1546 rfh2->GetRenderViewHost()->rvh_state()); |
1545 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, | 1547 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, |
1546 rfh1->GetRenderViewHost()->rvh_state()); | 1548 rfh1->GetRenderViewHost()->rvh_state()); |
1547 | 1549 |
1548 // Simulate the swap out ack. | 1550 // Simulate the swap out ack. |
1549 rfh1->OnSwappedOut(false); | 1551 rfh1->OnSwappedOut(false); |
(...skipping 15 matching lines...) Expand all Loading... |
1565 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1567 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); |
1566 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1568 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1567 rfh1->GetRenderViewHost()->rvh_state()); | 1569 rfh1->GetRenderViewHost()->rvh_state()); |
1568 | 1570 |
1569 // Increment the number of active views in SiteInstanceImpl so that rfh1 is | 1571 // Increment the number of active views in SiteInstanceImpl so that rfh1 is |
1570 // not deleted on swap out. | 1572 // not deleted on swap out. |
1571 static_cast<SiteInstanceImpl*>( | 1573 static_cast<SiteInstanceImpl*>( |
1572 rfh1->GetSiteInstance())->increment_active_view_count(); | 1574 rfh1->GetSiteInstance())->increment_active_view_count(); |
1573 | 1575 |
1574 // Navigate to new site, simulating onbeforeunload approval. | 1576 // Navigate to new site, simulating onbeforeunload approval. |
1575 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1577 controller().LoadURL( |
| 1578 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1576 base::TimeTicks now = base::TimeTicks::Now(); | 1579 base::TimeTicks now = base::TimeTicks::Now(); |
1577 contents()->GetMainFrame()->OnMessageReceived( | 1580 contents()->GetMainFrame()->OnMessageReceived( |
1578 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1581 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1579 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1582 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1580 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1583 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1581 rfh1->GetRenderViewHost()->rvh_state()); | 1584 rfh1->GetRenderViewHost()->rvh_state()); |
1582 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1585 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1583 | 1586 |
1584 // The new page commits. | 1587 // The new page commits. |
1585 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | 1588 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1586 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1589 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1587 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1590 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1588 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1591 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1589 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1592 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1590 rfh2->GetRenderViewHost()->rvh_state()); | 1593 rfh2->GetRenderViewHost()->rvh_state()); |
1591 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | 1594 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, |
1592 rfh1->GetRenderViewHost()->rvh_state()); | 1595 rfh1->GetRenderViewHost()->rvh_state()); |
1593 | 1596 |
1594 // Simulate the swap out ack. | 1597 // Simulate the swap out ack. |
1595 rfh1->OnSwappedOut(false); | 1598 rfh1->OnSwappedOut(false); |
(...skipping 18 matching lines...) Expand all Loading... |
1614 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1617 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); |
1615 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1618 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1616 rfh1->GetRenderViewHost()->rvh_state()); | 1619 rfh1->GetRenderViewHost()->rvh_state()); |
1617 | 1620 |
1618 // Increment the number of active views in SiteInstanceImpl so that rfh1 is | 1621 // Increment the number of active views in SiteInstanceImpl so that rfh1 is |
1619 // not deleted on swap out. | 1622 // not deleted on swap out. |
1620 static_cast<SiteInstanceImpl*>( | 1623 static_cast<SiteInstanceImpl*>( |
1621 rfh1->GetSiteInstance())->increment_active_view_count(); | 1624 rfh1->GetSiteInstance())->increment_active_view_count(); |
1622 | 1625 |
1623 // Navigate to new site, simulating onbeforeunload approval. | 1626 // Navigate to new site, simulating onbeforeunload approval. |
1624 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1627 controller().LoadURL( |
| 1628 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1625 base::TimeTicks now = base::TimeTicks::Now(); | 1629 base::TimeTicks now = base::TimeTicks::Now(); |
1626 rfh1->OnMessageReceived( | 1630 rfh1->OnMessageReceived( |
1627 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1631 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1628 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1632 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1629 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1633 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1630 | 1634 |
1631 // The new page commits. | 1635 // The new page commits. |
1632 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | 1636 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1633 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1637 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1634 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1638 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1635 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1639 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1636 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1640 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1637 rfh2->GetRenderViewHost()->rvh_state()); | 1641 rfh2->GetRenderViewHost()->rvh_state()); |
1638 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | 1642 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, |
1639 rfh1->GetRenderViewHost()->rvh_state()); | 1643 rfh1->GetRenderViewHost()->rvh_state()); |
1640 | 1644 |
1641 // Simulate the swap out ack. | 1645 // Simulate the swap out ack. |
1642 rfh1->OnSwappedOut(false); | 1646 rfh1->OnSwappedOut(false); |
(...skipping 11 matching lines...) Expand all Loading... |
1654 const GURL kUrl2("http://www.chromium.org/"); | 1658 const GURL kUrl2("http://www.chromium.org/"); |
1655 RenderFrameHostImpl* pending_rfh = NULL; | 1659 RenderFrameHostImpl* pending_rfh = NULL; |
1656 base::TimeTicks now = base::TimeTicks::Now(); | 1660 base::TimeTicks now = base::TimeTicks::Now(); |
1657 | 1661 |
1658 // Navigate to the first page. | 1662 // Navigate to the first page. |
1659 contents()->NavigateAndCommit(kUrl1); | 1663 contents()->NavigateAndCommit(kUrl1); |
1660 TestRenderViewHost* rvh1 = test_rvh(); | 1664 TestRenderViewHost* rvh1 = test_rvh(); |
1661 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | 1665 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); |
1662 | 1666 |
1663 // Navigate to a new site, starting a cross-site navigation. | 1667 // Navigate to a new site, starting a cross-site navigation. |
1664 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1668 controller().LoadURL( |
| 1669 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1665 { | 1670 { |
1666 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1671 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1667 ->pending_frame_host(); | 1672 ->pending_frame_host(); |
1668 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | 1673 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); |
1669 | 1674 |
1670 // Cancel the navigation by simulating a declined beforeunload dialog. | 1675 // Cancel the navigation by simulating a declined beforeunload dialog. |
1671 contents()->GetMainFrame()->OnMessageReceived( | 1676 contents()->GetMainFrame()->OnMessageReceived( |
1672 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1677 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1673 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1678 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1674 | 1679 |
1675 // Since the pending RFH is the only one for the new SiteInstance, it should | 1680 // Since the pending RFH is the only one for the new SiteInstance, it should |
1676 // be deleted. | 1681 // be deleted. |
1677 EXPECT_TRUE(rvh_deleted_observer.deleted()); | 1682 EXPECT_TRUE(rvh_deleted_observer.deleted()); |
1678 } | 1683 } |
1679 | 1684 |
1680 // Start another cross-site navigation. | 1685 // Start another cross-site navigation. |
1681 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1686 controller().LoadURL( |
| 1687 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1682 { | 1688 { |
1683 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1689 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1684 ->pending_frame_host(); | 1690 ->pending_frame_host(); |
1685 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | 1691 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); |
1686 | 1692 |
1687 // Increment the number of active views in the new SiteInstance, which will | 1693 // Increment the number of active views in the new SiteInstance, which will |
1688 // cause the pending RFH to be swapped out instead of deleted. | 1694 // cause the pending RFH to be swapped out instead of deleted. |
1689 static_cast<SiteInstanceImpl*>( | 1695 static_cast<SiteInstanceImpl*>( |
1690 pending_rfh->GetSiteInstance())->increment_active_view_count(); | 1696 pending_rfh->GetSiteInstance())->increment_active_view_count(); |
1691 | 1697 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 | 1749 |
1744 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 1750 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
1745 // RenderFrameHost is not modified when the navigation commits. | 1751 // RenderFrameHost is not modified when the navigation commits. |
1746 TEST_F(RenderFrameHostManagerTest, | 1752 TEST_F(RenderFrameHostManagerTest, |
1747 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 1753 BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
1748 const GURL kUrl("http://www.google.com/"); | 1754 const GURL kUrl("http://www.google.com/"); |
1749 | 1755 |
1750 EnableBrowserSideNavigation(); | 1756 EnableBrowserSideNavigation(); |
1751 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1757 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1752 contents()->GetController().LoadURL( | 1758 contents()->GetController().LoadURL( |
1753 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1759 kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1754 RenderFrameHostManager* render_manager = | 1760 RenderFrameHostManager* render_manager = |
1755 main_test_rfh()->frame_tree_node()->render_manager(); | 1761 main_test_rfh()->frame_tree_node()->render_manager(); |
1756 NavigationRequest* main_request = | 1762 NavigationRequest* main_request = |
1757 GetNavigationRequestForRenderFrameManager(render_manager); | 1763 GetNavigationRequestForRenderFrameManager(render_manager); |
1758 // A NavigationRequest should have been generated. | 1764 // A NavigationRequest should have been generated. |
1759 EXPECT_TRUE(main_request != NULL); | 1765 EXPECT_TRUE(main_request != NULL); |
1760 RenderFrameHostImpl* rfh = main_test_rfh(); | 1766 RenderFrameHostImpl* rfh = main_test_rfh(); |
1761 | 1767 |
1762 // Now commit the same url. | 1768 // Now commit the same url. |
1763 NavigationBeforeCommitInfo commit_info; | 1769 NavigationBeforeCommitInfo commit_info; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1854 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1849 | 1855 |
1850 // Confirms that a valid, request-matching commit is correctly processed. | 1856 // Confirms that a valid, request-matching commit is correctly processed. |
1851 nbc_info.navigation_url = kUrl2; | 1857 nbc_info.navigation_url = kUrl2; |
1852 nbc_info.navigation_request_id = request_id2; | 1858 nbc_info.navigation_request_id = request_id2; |
1853 render_manager->CommitNavigation(nbc_info); | 1859 render_manager->CommitNavigation(nbc_info); |
1854 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1860 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1855 } | 1861 } |
1856 | 1862 |
1857 } // namespace content | 1863 } // namespace content |
OLD | NEW |