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

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

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