OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 GetMaxURLChars() + 1, 'a')); | 442 GetMaxURLChars() + 1, 'a')); |
443 | 443 |
444 controller().LoadURL( | 444 controller().LoadURL( |
445 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); | 445 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); |
446 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); | 446 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); |
447 } | 447 } |
448 | 448 |
449 // Test that navigating across a site boundary creates a new RenderViewHost | 449 // Test that navigating across a site boundary creates a new RenderViewHost |
450 // with a new SiteInstance. Going back should do the same. | 450 // with a new SiteInstance. Going back should do the same. |
451 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 451 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
452 contents()->transition_cross_site = true; | |
453 TestRenderViewHost* orig_rvh = test_rvh(); | 452 TestRenderViewHost* orig_rvh = test_rvh(); |
454 RenderFrameHostImpl* orig_rfh = | 453 RenderFrameHostImpl* orig_rfh = |
455 contents()->GetFrameTree()->root()->current_frame_host(); | 454 contents()->GetFrameTree()->root()->current_frame_host(); |
456 int orig_rvh_delete_count = 0; | 455 int orig_rvh_delete_count = 0; |
457 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 456 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
458 SiteInstance* instance1 = contents()->GetSiteInstance(); | 457 SiteInstance* instance1 = contents()->GetSiteInstance(); |
459 | 458 |
460 // Navigate to URL. First URL should use first RenderViewHost. | 459 // Navigate to URL. First URL should use first RenderViewHost. |
461 const GURL url("http://www.google.com"); | 460 const GURL url("http://www.google.com"); |
462 controller().LoadURL( | 461 controller().LoadURL( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 542 |
544 // Close contents and ensure RVHs are deleted. | 543 // Close contents and ensure RVHs are deleted. |
545 DeleteContents(); | 544 DeleteContents(); |
546 EXPECT_EQ(orig_rvh_delete_count, 1); | 545 EXPECT_EQ(orig_rvh_delete_count, 1); |
547 EXPECT_EQ(pending_rvh_delete_count, 1); | 546 EXPECT_EQ(pending_rvh_delete_count, 1); |
548 } | 547 } |
549 | 548 |
550 // Test that navigating across a site boundary after a crash creates a new | 549 // Test that navigating across a site boundary after a crash creates a new |
551 // RVH without requiring a cross-site transition (i.e., PENDING state). | 550 // RVH without requiring a cross-site transition (i.e., PENDING state). |
552 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { | 551 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { |
553 contents()->transition_cross_site = true; | |
554 TestRenderViewHost* orig_rvh = test_rvh(); | 552 TestRenderViewHost* orig_rvh = test_rvh(); |
555 int orig_rvh_delete_count = 0; | 553 int orig_rvh_delete_count = 0; |
556 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 554 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
557 SiteInstance* instance1 = contents()->GetSiteInstance(); | 555 SiteInstance* instance1 = contents()->GetSiteInstance(); |
558 | 556 |
559 // Navigate to URL. First URL should use first RenderViewHost. | 557 // Navigate to URL. First URL should use first RenderViewHost. |
560 const GURL url("http://www.google.com"); | 558 const GURL url("http://www.google.com"); |
561 controller().LoadURL( | 559 controller().LoadURL( |
562 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 560 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
563 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 561 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
(...skipping 25 matching lines...) Expand all Loading... |
589 | 587 |
590 // Close contents and ensure RVHs are deleted. | 588 // Close contents and ensure RVHs are deleted. |
591 DeleteContents(); | 589 DeleteContents(); |
592 EXPECT_EQ(orig_rvh_delete_count, 1); | 590 EXPECT_EQ(orig_rvh_delete_count, 1); |
593 } | 591 } |
594 | 592 |
595 // Test that opening a new contents in the same SiteInstance and then navigating | 593 // Test that opening a new contents in the same SiteInstance and then navigating |
596 // both contentses to a new site will place both contentses in a single | 594 // both contentses to a new site will place both contentses in a single |
597 // SiteInstance. | 595 // SiteInstance. |
598 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { | 596 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { |
599 contents()->transition_cross_site = true; | |
600 TestRenderViewHost* orig_rvh = test_rvh(); | 597 TestRenderViewHost* orig_rvh = test_rvh(); |
601 SiteInstance* instance1 = contents()->GetSiteInstance(); | 598 SiteInstance* instance1 = contents()->GetSiteInstance(); |
602 | 599 |
603 // Navigate to URL. First URL should use first RenderViewHost. | 600 // Navigate to URL. First URL should use first RenderViewHost. |
604 const GURL url("http://www.google.com"); | 601 const GURL url("http://www.google.com"); |
605 controller().LoadURL( | 602 controller().LoadURL( |
606 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 603 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
607 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 604 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
608 | 605 |
609 // Open a new contents with the same SiteInstance, navigated to the same site. | 606 // Open a new contents with the same SiteInstance, navigated to the same site. |
610 scoped_ptr<TestWebContents> contents2( | 607 scoped_ptr<TestWebContents> contents2( |
611 TestWebContents::Create(browser_context(), instance1)); | 608 TestWebContents::Create(browser_context(), instance1)); |
612 contents2->transition_cross_site = true; | |
613 contents2->GetController().LoadURL(url, Referrer(), | 609 contents2->GetController().LoadURL(url, Referrer(), |
614 PAGE_TRANSITION_TYPED, | 610 PAGE_TRANSITION_TYPED, |
615 std::string()); | 611 std::string()); |
616 // Need this page id to be 2 since the site instance is the same (which is the | 612 // Need this page id to be 2 since the site instance is the same (which is the |
617 // scope of page IDs) and we want to consider this a new page. | 613 // scope of page IDs) and we want to consider this a new page. |
618 contents2->TestDidNavigate( | 614 contents2->TestDidNavigate( |
619 contents2->GetRenderViewHost(), 2, url, PAGE_TRANSITION_TYPED); | 615 contents2->GetRenderViewHost(), 2, url, PAGE_TRANSITION_TYPED); |
620 | 616 |
621 // Navigate first contents to a new site. | 617 // Navigate first contents to a new site. |
622 const GURL url2a("http://www.yahoo.com"); | 618 const GURL url2a("http://www.yahoo.com"); |
(...skipping 29 matching lines...) Expand all Loading... |
652 EXPECT_NE(instance1, instance2b); | 648 EXPECT_NE(instance1, instance2b); |
653 | 649 |
654 // Both contentses should now be in the same SiteInstance. | 650 // Both contentses should now be in the same SiteInstance. |
655 EXPECT_EQ(instance2a, instance2b); | 651 EXPECT_EQ(instance2a, instance2b); |
656 } | 652 } |
657 | 653 |
658 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { | 654 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { |
659 WebContentsImplTestBrowserClient browser_client; | 655 WebContentsImplTestBrowserClient browser_client; |
660 SetBrowserClientForTesting(&browser_client); | 656 SetBrowserClientForTesting(&browser_client); |
661 | 657 |
662 contents()->transition_cross_site = true; | |
663 TestRenderViewHost* orig_rvh = test_rvh(); | 658 TestRenderViewHost* orig_rvh = test_rvh(); |
664 RenderFrameHostImpl* orig_rfh = | 659 RenderFrameHostImpl* orig_rfh = |
665 contents()->GetFrameTree()->root()->current_frame_host(); | 660 contents()->GetFrameTree()->root()->current_frame_host(); |
666 int orig_rvh_delete_count = 0; | 661 int orig_rvh_delete_count = 0; |
667 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 662 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
668 SiteInstanceImpl* orig_instance = | 663 SiteInstanceImpl* orig_instance = |
669 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 664 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
670 | 665 |
671 browser_client.set_assign_site_for_url(false); | 666 browser_client.set_assign_site_for_url(false); |
672 // Navigate to an URL that will not assign a new SiteInstance. | 667 // Navigate to an URL that will not assign a new SiteInstance. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 | 736 |
742 // Close contents and ensure RVHs are deleted. | 737 // Close contents and ensure RVHs are deleted. |
743 DeleteContents(); | 738 DeleteContents(); |
744 EXPECT_EQ(orig_rvh_delete_count, 1); | 739 EXPECT_EQ(orig_rvh_delete_count, 1); |
745 EXPECT_EQ(pending_rvh_delete_count, 1); | 740 EXPECT_EQ(pending_rvh_delete_count, 1); |
746 } | 741 } |
747 | 742 |
748 // Test that we can find an opener RVH even if it's pending. | 743 // Test that we can find an opener RVH even if it's pending. |
749 // http://crbug.com/176252. | 744 // http://crbug.com/176252. |
750 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { | 745 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { |
751 contents()->transition_cross_site = true; | |
752 TestRenderViewHost* orig_rvh = test_rvh(); | 746 TestRenderViewHost* orig_rvh = test_rvh(); |
753 | 747 |
754 // Navigate to a URL. | 748 // Navigate to a URL. |
755 const GURL url("http://www.google.com"); | 749 const GURL url("http://www.google.com"); |
756 controller().LoadURL( | 750 controller().LoadURL( |
757 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 751 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
758 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 752 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
759 | 753 |
760 // Start to navigate first tab to a new site, so that it has a pending RVH. | 754 // Start to navigate first tab to a new site, so that it has a pending RVH. |
761 const GURL url2("http://www.yahoo.com"); | 755 const GURL url2("http://www.yahoo.com"); |
762 controller().LoadURL( | 756 controller().LoadURL( |
763 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 757 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
764 orig_rvh->SendBeforeUnloadACK(true); | 758 orig_rvh->SendBeforeUnloadACK(true); |
765 TestRenderViewHost* pending_rvh = | 759 TestRenderViewHost* pending_rvh = |
766 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 760 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
767 | 761 |
768 // While it is still pending, simulate opening a new tab with the first tab | 762 // While it is still pending, simulate opening a new tab with the first tab |
769 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews | 763 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews |
770 // on the opener to ensure that an RVH exists. | 764 // on the opener to ensure that an RVH exists. |
771 int opener_routing_id = contents()->CreateOpenerRenderViews( | 765 int opener_routing_id = contents()->CreateOpenerRenderViews( |
772 pending_rvh->GetSiteInstance()); | 766 pending_rvh->GetSiteInstance()); |
773 | 767 |
774 // We should find the pending RVH and not create a new one. | 768 // We should find the pending RVH and not create a new one. |
775 EXPECT_EQ(pending_rvh->GetRoutingID(), opener_routing_id); | 769 EXPECT_EQ(pending_rvh->GetRoutingID(), opener_routing_id); |
776 } | 770 } |
777 | 771 |
778 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, | 772 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, |
779 // to determine whether a navigation is cross-site. | 773 // to determine whether a navigation is cross-site. |
780 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { | 774 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { |
781 contents()->transition_cross_site = true; | |
782 RenderViewHost* orig_rvh = rvh(); | 775 RenderViewHost* orig_rvh = rvh(); |
783 SiteInstance* instance1 = contents()->GetSiteInstance(); | 776 SiteInstance* instance1 = contents()->GetSiteInstance(); |
784 | 777 |
785 // Navigate to URL. | 778 // Navigate to URL. |
786 const GURL url("http://www.google.com"); | 779 const GURL url("http://www.google.com"); |
787 controller().LoadURL( | 780 controller().LoadURL( |
788 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 781 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
789 contents()->TestDidNavigate( | 782 contents()->TestDidNavigate( |
790 orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 783 orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
791 | 784 |
792 // Open a related contents to a second site. | 785 // Open a related contents to a second site. |
793 scoped_ptr<TestWebContents> contents2( | 786 scoped_ptr<TestWebContents> contents2( |
794 TestWebContents::Create(browser_context(), instance1)); | 787 TestWebContents::Create(browser_context(), instance1)); |
795 contents2->transition_cross_site = true; | |
796 const GURL url2("http://www.yahoo.com"); | 788 const GURL url2("http://www.yahoo.com"); |
797 contents2->GetController().LoadURL(url2, Referrer(), | 789 contents2->GetController().LoadURL(url2, Referrer(), |
798 PAGE_TRANSITION_TYPED, | 790 PAGE_TRANSITION_TYPED, |
799 std::string()); | 791 std::string()); |
800 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 792 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
801 // pending. | 793 // pending. |
802 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 794 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
803 contents2->GetRenderViewHost()); | 795 contents2->GetRenderViewHost()); |
804 EXPECT_FALSE(contents2->cross_navigation_pending()); | 796 EXPECT_FALSE(contents2->cross_navigation_pending()); |
805 contents2->TestDidNavigate(rvh2, 2, url2, PAGE_TRANSITION_TYPED); | 797 contents2->TestDidNavigate(rvh2, 2, url2, PAGE_TRANSITION_TYPED); |
(...skipping 17 matching lines...) Expand all Loading... |
823 EXPECT_FALSE(contents()->cross_navigation_pending()); | 815 EXPECT_FALSE(contents()->cross_navigation_pending()); |
824 contents()->TestDidNavigate( | 816 contents()->TestDidNavigate( |
825 orig_rvh, 3, url3, PAGE_TRANSITION_TYPED); | 817 orig_rvh, 3, url3, PAGE_TRANSITION_TYPED); |
826 SiteInstance* instance4 = contents()->GetSiteInstance(); | 818 SiteInstance* instance4 = contents()->GetSiteInstance(); |
827 EXPECT_EQ(instance1, instance4); | 819 EXPECT_EQ(instance1, instance4); |
828 } | 820 } |
829 | 821 |
830 // Test that the onbeforeunload and onunload handlers run when navigating | 822 // Test that the onbeforeunload and onunload handlers run when navigating |
831 // across site boundaries. | 823 // across site boundaries. |
832 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { | 824 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { |
833 contents()->transition_cross_site = true; | |
834 TestRenderViewHost* orig_rvh = test_rvh(); | 825 TestRenderViewHost* orig_rvh = test_rvh(); |
835 SiteInstance* instance1 = contents()->GetSiteInstance(); | 826 SiteInstance* instance1 = contents()->GetSiteInstance(); |
836 | 827 |
837 // Navigate to URL. First URL should use first RenderViewHost. | 828 // Navigate to URL. First URL should use first RenderViewHost. |
838 const GURL url("http://www.google.com"); | 829 const GURL url("http://www.google.com"); |
839 controller().LoadURL( | 830 controller().LoadURL( |
840 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 831 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
841 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 832 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
842 EXPECT_FALSE(contents()->cross_navigation_pending()); | 833 EXPECT_FALSE(contents()->cross_navigation_pending()); |
843 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 834 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 EXPECT_FALSE(contents()->cross_navigation_pending()); | 866 EXPECT_FALSE(contents()->cross_navigation_pending()); |
876 EXPECT_EQ(pending_rvh, rvh()); | 867 EXPECT_EQ(pending_rvh, rvh()); |
877 EXPECT_NE(instance1, instance2); | 868 EXPECT_NE(instance1, instance2); |
878 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 869 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
879 } | 870 } |
880 | 871 |
881 // Test that during a slow cross-site navigation, the original renderer can | 872 // Test that during a slow cross-site navigation, the original renderer can |
882 // navigate to a different URL and have it displayed, canceling the slow | 873 // navigate to a different URL and have it displayed, canceling the slow |
883 // navigation. | 874 // navigation. |
884 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { | 875 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { |
885 contents()->transition_cross_site = true; | |
886 TestRenderViewHost* orig_rvh = test_rvh(); | 876 TestRenderViewHost* orig_rvh = test_rvh(); |
887 SiteInstance* instance1 = contents()->GetSiteInstance(); | 877 SiteInstance* instance1 = contents()->GetSiteInstance(); |
888 | 878 |
889 // Navigate to URL. First URL should use first RenderViewHost. | 879 // Navigate to URL. First URL should use first RenderViewHost. |
890 const GURL url("http://www.google.com"); | 880 const GURL url("http://www.google.com"); |
891 controller().LoadURL( | 881 controller().LoadURL( |
892 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 882 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
893 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 883 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
894 EXPECT_FALSE(contents()->cross_navigation_pending()); | 884 EXPECT_FALSE(contents()->cross_navigation_pending()); |
895 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 885 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
(...skipping 14 matching lines...) Expand all Loading... |
910 // Verify that the pending navigation is cancelled. | 900 // Verify that the pending navigation is cancelled. |
911 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 901 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
912 SiteInstance* instance2 = contents()->GetSiteInstance(); | 902 SiteInstance* instance2 = contents()->GetSiteInstance(); |
913 EXPECT_FALSE(contents()->cross_navigation_pending()); | 903 EXPECT_FALSE(contents()->cross_navigation_pending()); |
914 EXPECT_EQ(orig_rvh, rvh()); | 904 EXPECT_EQ(orig_rvh, rvh()); |
915 EXPECT_EQ(instance1, instance2); | 905 EXPECT_EQ(instance1, instance2); |
916 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 906 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
917 } | 907 } |
918 | 908 |
919 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { | 909 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
920 contents()->transition_cross_site = true; | |
921 | |
922 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 910 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
923 const GURL url1("chrome://blah"); | 911 const GURL url1("chrome://blah"); |
924 controller().LoadURL( | 912 controller().LoadURL( |
925 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 913 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
926 TestRenderViewHost* ntp_rvh = test_rvh(); | 914 TestRenderViewHost* ntp_rvh = test_rvh(); |
927 contents()->TestDidNavigate(ntp_rvh, 1, url1, PAGE_TRANSITION_TYPED); | 915 contents()->TestDidNavigate(ntp_rvh, 1, url1, PAGE_TRANSITION_TYPED); |
928 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 916 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
929 SiteInstance* instance1 = contents()->GetSiteInstance(); | 917 SiteInstance* instance1 = contents()->GetSiteInstance(); |
930 | 918 |
931 EXPECT_FALSE(contents()->cross_navigation_pending()); | 919 EXPECT_FALSE(contents()->cross_navigation_pending()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 EXPECT_EQ(instance2, | 1002 EXPECT_EQ(instance2, |
1015 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 1003 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
1016 EXPECT_EQ(instance1, | 1004 EXPECT_EQ(instance1, |
1017 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 1005 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
1018 EXPECT_EQ(url1, entry1->GetURL()); | 1006 EXPECT_EQ(url1, entry1->GetURL()); |
1019 } | 1007 } |
1020 | 1008 |
1021 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 1009 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
1022 // original renderer will not cancel the slow navigation (bug 42029). | 1010 // original renderer will not cancel the slow navigation (bug 42029). |
1023 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { | 1011 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { |
1024 contents()->transition_cross_site = true; | |
1025 TestRenderViewHost* orig_rvh = test_rvh(); | 1012 TestRenderViewHost* orig_rvh = test_rvh(); |
1026 | 1013 |
1027 // Navigate to URL. First URL should use first RenderViewHost. | 1014 // Navigate to URL. First URL should use first RenderViewHost. |
1028 const GURL url("http://www.google.com"); | 1015 const GURL url("http://www.google.com"); |
1029 controller().LoadURL( | 1016 controller().LoadURL( |
1030 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1017 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1031 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1018 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1032 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1019 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1033 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 1020 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
1034 | 1021 |
(...skipping 15 matching lines...) Expand all Loading... |
1050 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1037 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1051 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 1038 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
1052 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1039 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1053 } | 1040 } |
1054 | 1041 |
1055 // Test that a cross-site navigation is not preempted if the previous | 1042 // Test that a cross-site navigation is not preempted if the previous |
1056 // renderer sends a FrameNavigate message just before being told to stop. | 1043 // renderer sends a FrameNavigate message just before being told to stop. |
1057 // We should only preempt the cross-site navigation if the previous renderer | 1044 // We should only preempt the cross-site navigation if the previous renderer |
1058 // has started a new navigation. See http://crbug.com/79176. | 1045 // has started a new navigation. See http://crbug.com/79176. |
1059 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 1046 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
1060 contents()->transition_cross_site = true; | |
1061 | |
1062 // Navigate to NTP URL. | 1047 // Navigate to NTP URL. |
1063 const GURL url("chrome://blah"); | 1048 const GURL url("chrome://blah"); |
1064 controller().LoadURL( | 1049 controller().LoadURL( |
1065 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1050 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1066 TestRenderViewHost* orig_rvh = test_rvh(); | 1051 TestRenderViewHost* orig_rvh = test_rvh(); |
1067 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1052 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1068 | 1053 |
1069 // Navigate to new site, with the beforeunload request in flight. | 1054 // Navigate to new site, with the beforeunload request in flight. |
1070 const GURL url2("http://www.yahoo.com"); | 1055 const GURL url2("http://www.yahoo.com"); |
1071 controller().LoadURL( | 1056 controller().LoadURL( |
(...skipping 15 matching lines...) Expand all Loading... |
1087 contents()->TestDidNavigate(pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 1072 contents()->TestDidNavigate(pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
1088 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1073 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1089 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 1074 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
1090 } | 1075 } |
1091 | 1076 |
1092 // Test that the original renderer cannot preempt a cross-site navigation once | 1077 // Test that the original renderer cannot preempt a cross-site navigation once |
1093 // the unload request has been made. At this point, the cross-site navigation | 1078 // the unload request has been made. At this point, the cross-site navigation |
1094 // is almost ready to be displayed, and the original renderer is only given a | 1079 // is almost ready to be displayed, and the original renderer is only given a |
1095 // short chance to run an unload handler. Prevents regression of bug 23942. | 1080 // short chance to run an unload handler. Prevents regression of bug 23942. |
1096 TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) { | 1081 TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) { |
1097 contents()->transition_cross_site = true; | |
1098 TestRenderViewHost* orig_rvh = test_rvh(); | 1082 TestRenderViewHost* orig_rvh = test_rvh(); |
1099 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1083 SiteInstance* instance1 = contents()->GetSiteInstance(); |
1100 | 1084 |
1101 // Navigate to URL. First URL should use first RenderViewHost. | 1085 // Navigate to URL. First URL should use first RenderViewHost. |
1102 const GURL url("http://www.google.com"); | 1086 const GURL url("http://www.google.com"); |
1103 controller().LoadURL( | 1087 controller().LoadURL( |
1104 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1088 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1105 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1089 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1106 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1090 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1107 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 1091 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1129 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1146 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1130 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1147 EXPECT_EQ(pending_rvh, rvh()); | 1131 EXPECT_EQ(pending_rvh, rvh()); |
1148 EXPECT_NE(instance1, instance2); | 1132 EXPECT_NE(instance1, instance2); |
1149 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 1133 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
1150 } | 1134 } |
1151 | 1135 |
1152 // Test that a cross-site navigation that doesn't commit after the unload | 1136 // Test that a cross-site navigation that doesn't commit after the unload |
1153 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 | 1137 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 |
1154 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { | 1138 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { |
1155 contents()->transition_cross_site = true; | |
1156 TestRenderViewHost* orig_rvh = test_rvh(); | 1139 TestRenderViewHost* orig_rvh = test_rvh(); |
1157 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1140 SiteInstance* instance1 = contents()->GetSiteInstance(); |
1158 | 1141 |
1159 // Navigate to URL. First URL should use first RenderViewHost. | 1142 // Navigate to URL. First URL should use first RenderViewHost. |
1160 const GURL url("http://www.google.com"); | 1143 const GURL url("http://www.google.com"); |
1161 controller().LoadURL( | 1144 controller().LoadURL( |
1162 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1145 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1163 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1146 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1164 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1147 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1165 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 1148 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2636 contents->CommitPendingNavigation(); | 2619 contents->CommitPendingNavigation(); |
2637 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2620 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2638 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); | 2621 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); |
2639 | 2622 |
2640 contents.reset(); | 2623 contents.reset(); |
2641 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2624 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2642 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2625 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
2643 } | 2626 } |
2644 | 2627 |
2645 } // namespace content | 2628 } // namespace content |
OLD | NEW |