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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 466933003: Revert of Revert of [site isolation] cross-site transfers should track the RenderFrameHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const GURL url2("http://www.yahoo.com"); 493 const GURL url2("http://www.yahoo.com");
494 controller().LoadURL( 494 controller().LoadURL(
495 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 495 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
496 EXPECT_TRUE(contents()->cross_navigation_pending()); 496 EXPECT_TRUE(contents()->cross_navigation_pending());
497 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 497 EXPECT_EQ(url, contents()->GetLastCommittedURL());
498 EXPECT_EQ(url2, contents()->GetVisibleURL()); 498 EXPECT_EQ(url2, contents()->GetVisibleURL());
499 TestRenderViewHost* pending_rvh = 499 TestRenderViewHost* pending_rvh =
500 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); 500 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost());
501 int pending_rvh_delete_count = 0; 501 int pending_rvh_delete_count = 0;
502 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 502 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
503 RenderFrameHostImpl* pending_rfh = contents()->GetFrameTree()->root()-> 503 RenderFrameHostImpl* pending_rfh = pending_main_test_rfh();
504 render_manager()->pending_frame_host();
505 504
506 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 505 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
507 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); 506 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
508 orig_rvh->SendBeforeUnloadACK(true); 507 orig_rvh->SendBeforeUnloadACK(true);
509 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); 508 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
510 509
511 // DidNavigate from the pending page 510 // DidNavigate from the pending page
512 contents()->TestDidNavigate( 511 contents()->TestDidNavigate(
513 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); 512 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED);
514 SiteInstance* instance2 = contents()->GetSiteInstance(); 513 SiteInstance* instance2 = contents()->GetSiteInstance();
515 514
516 // Keep the number of active views in pending_rvh's SiteInstance 515 // Keep the number of active views in pending_rvh's SiteInstance
517 // non-zero so that orig_rvh doesn't get deleted when it gets 516 // non-zero so that orig_rvh doesn't get deleted when it gets
518 // swapped out. 517 // swapped out.
519 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())-> 518 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())->
520 increment_active_view_count(); 519 increment_active_view_count();
521 520
522 EXPECT_FALSE(contents()->cross_navigation_pending()); 521 EXPECT_FALSE(contents()->cross_navigation_pending());
523 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); 522 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost());
524 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 523 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
525 EXPECT_EQ(url2, contents()->GetVisibleURL()); 524 EXPECT_EQ(url2, contents()->GetVisibleURL());
526 EXPECT_NE(instance1, instance2); 525 EXPECT_NE(instance1, instance2);
527 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); 526 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL);
528 // We keep the original RFH around, swapped out. 527 // We keep the original RFH around, swapped out.
529 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 528 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
530 orig_rfh)); 529 orig_rfh));
531 EXPECT_EQ(orig_rvh_delete_count, 0); 530 EXPECT_EQ(orig_rvh_delete_count, 0);
532 531
533 // Going back should switch SiteInstances again. The first SiteInstance is 532 // Going back should switch SiteInstances again. The first SiteInstance is
534 // stored in the NavigationEntry, so it should be the same as at the start. 533 // stored in the NavigationEntry, so it should be the same as at the start.
535 // We should use the same RVH as before, swapping it back in. 534 // We should use the same RFH as before, swapping it back in.
536 controller().GoBack(); 535 controller().GoBack();
537 TestRenderViewHost* goback_rvh = 536 TestRenderFrameHost* goback_rfh = pending_main_test_rfh();
538 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); 537 EXPECT_EQ(orig_rfh, goback_rfh);
539 EXPECT_EQ(orig_rvh, goback_rvh);
540 EXPECT_TRUE(contents()->cross_navigation_pending()); 538 EXPECT_TRUE(contents()->cross_navigation_pending());
541 539
542 // Navigations should be suspended in goback_rvh until BeforeUnloadACK. 540 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
543 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); 541 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
544 pending_rvh->SendBeforeUnloadACK(true); 542 pending_rvh->SendBeforeUnloadACK(true);
545 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); 543 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
546 544
547 // DidNavigate from the back action 545 // DidNavigate from the back action
548 contents()->TestDidNavigate( 546 contents()->TestDidNavigate(
549 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); 547 goback_rfh->GetRenderViewHost(), 1, url2, PAGE_TRANSITION_TYPED);
550 EXPECT_FALSE(contents()->cross_navigation_pending()); 548 EXPECT_FALSE(contents()->cross_navigation_pending());
551 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); 549 EXPECT_EQ(goback_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
552 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 550 EXPECT_EQ(instance1, contents()->GetSiteInstance());
553 // The pending RFH should now be swapped out, not deleted. 551 // The pending RFH should now be swapped out, not deleted.
554 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 552 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
555 IsOnSwappedOutList(pending_rfh)); 553 IsOnSwappedOutList(pending_rfh));
556 EXPECT_EQ(pending_rvh_delete_count, 0); 554 EXPECT_EQ(pending_rvh_delete_count, 0);
557 pending_rvh->OnSwappedOut(false); 555 pending_rvh->OnSwappedOut(false);
558 556
559 // Close contents and ensure RVHs are deleted. 557 // Close contents and ensure RVHs are deleted.
560 DeleteContents(); 558 DeleteContents();
561 EXPECT_EQ(orig_rvh_delete_count, 1); 559 EXPECT_EQ(orig_rvh_delete_count, 1);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 667
670 // The embedder can request sites for certain urls not be be assigned to the 668 // The embedder can request sites for certain urls not be be assigned to the
671 // SiteInstance through ShouldAssignSiteForURL() in content browser client, 669 // SiteInstance through ShouldAssignSiteForURL() in content browser client,
672 // allowing to reuse the renderer backing certain chrome urls for subsequent 670 // allowing to reuse the renderer backing certain chrome urls for subsequent
673 // navigation. The test verifies that the override is honored. 671 // navigation. The test verifies that the override is honored.
674 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { 672 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) {
675 WebContentsImplTestBrowserClient browser_client; 673 WebContentsImplTestBrowserClient browser_client;
676 SetBrowserClientForTesting(&browser_client); 674 SetBrowserClientForTesting(&browser_client);
677 675
678 TestRenderViewHost* orig_rvh = test_rvh(); 676 TestRenderViewHost* orig_rvh = test_rvh();
679 RenderFrameHostImpl* orig_rfh = 677 RenderFrameHostImpl* orig_rfh = main_test_rfh();
680 contents()->GetFrameTree()->root()->current_frame_host();
681 int orig_rvh_delete_count = 0; 678 int orig_rvh_delete_count = 0;
682 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 679 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
683 SiteInstanceImpl* orig_instance = 680 SiteInstanceImpl* orig_instance =
684 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); 681 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance());
685 682
686 browser_client.set_assign_site_for_url(false); 683 browser_client.set_assign_site_for_url(false);
687 // Navigate to an URL that will not assign a new SiteInstance. 684 // Navigate to an URL that will not assign a new SiteInstance.
688 const GURL native_url("non-site-url://stuffandthings"); 685 const GURL native_url("non-site-url://stuffandthings");
689 controller().LoadURL( 686 controller().LoadURL(
690 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 687 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string());
(...skipping 29 matching lines...) Expand all
720 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 717 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
721 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 718 EXPECT_EQ(url, contents()->GetLastCommittedURL());
722 719
723 // Navigate to another new site (should create a new site instance). 720 // Navigate to another new site (should create a new site instance).
724 const GURL url2("http://www.yahoo.com"); 721 const GURL url2("http://www.yahoo.com");
725 controller().LoadURL( 722 controller().LoadURL(
726 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 723 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
727 EXPECT_TRUE(contents()->cross_navigation_pending()); 724 EXPECT_TRUE(contents()->cross_navigation_pending());
728 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 725 EXPECT_EQ(url, contents()->GetLastCommittedURL());
729 EXPECT_EQ(url2, contents()->GetVisibleURL()); 726 EXPECT_EQ(url2, contents()->GetVisibleURL());
730 TestRenderViewHost* pending_rvh = 727 TestRenderFrameHost* pending_rfh = pending_main_test_rfh();
731 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); 728 TestRenderViewHost* pending_rvh = pending_test_rvh();
729 EXPECT_EQ(pending_rfh->GetRenderViewHost(), pending_rvh);
732 int pending_rvh_delete_count = 0; 730 int pending_rvh_delete_count = 0;
733 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 731 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
734 732
735 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 733 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
736 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); 734 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
737 orig_rvh->SendBeforeUnloadACK(true); 735 orig_rvh->SendBeforeUnloadACK(true);
738 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); 736 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
737 EXPECT_EQ(pending_rfh->GetRenderViewHost(), pending_rvh);
739 738
740 // DidNavigate from the pending page. 739 // DidNavigate from the pending page.
741 contents()->TestDidNavigate( 740 contents()->TestDidNavigate(
742 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); 741 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED);
743 SiteInstance* new_instance = contents()->GetSiteInstance(); 742 SiteInstance* new_instance = contents()->GetSiteInstance();
744 743
745 EXPECT_FALSE(contents()->cross_navigation_pending()); 744 EXPECT_FALSE(contents()->cross_navigation_pending());
746 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); 745 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost());
747 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 746 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
748 EXPECT_EQ(url2, contents()->GetVisibleURL()); 747 EXPECT_EQ(url2, contents()->GetVisibleURL());
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 contents->CommitPendingNavigation(); 2742 contents->CommitPendingNavigation();
2744 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2743 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2745 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); 2744 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount());
2746 2745
2747 contents.reset(); 2746 contents.reset();
2748 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2747 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2749 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); 2748 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount());
2750 } 2749 }
2751 2750
2752 } // namespace content 2751 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | content/public/test/test_renderer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698