| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/cross_site_transferring_request.h" | 8 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 9 #include "content/browser/frame_host/interstitial_page_impl.h" | 9 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 10 #include "content/browser/frame_host/navigation_entry_impl.h" | 10 #include "content/browser/frame_host/navigation_entry_impl.h" |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 GetMaxURLChars() + 1, 'a')); | 452 GetMaxURLChars() + 1, 'a')); |
| 453 | 453 |
| 454 controller().LoadURL( | 454 controller().LoadURL( |
| 455 url, Referrer(), ui::PAGE_TRANSITION_GENERATED, std::string()); | 455 url, Referrer(), ui::PAGE_TRANSITION_GENERATED, std::string()); |
| 456 EXPECT_EQ(nullptr, controller().GetVisibleEntry()); | 456 EXPECT_EQ(nullptr, controller().GetVisibleEntry()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Test that navigating across a site boundary creates a new RenderViewHost | 459 // Test that navigating across a site boundary creates a new RenderViewHost |
| 460 // with a new SiteInstance. Going back should do the same. | 460 // with a new SiteInstance. Going back should do the same. |
| 461 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 461 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
| 462 bool is_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 463 switches::kSitePerProcess); |
| 462 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 464 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
| 463 int orig_rvh_delete_count = 0; | 465 int orig_rvh_delete_count = 0; |
| 464 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); | 466 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); |
| 465 SiteInstance* instance1 = contents()->GetSiteInstance(); | 467 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 466 | 468 |
| 467 // Navigate to URL. First URL should use first RenderViewHost. | 469 // Navigate to URL. First URL should use first RenderViewHost. |
| 468 const GURL url("http://www.google.com"); | 470 const GURL url("http://www.google.com"); |
| 469 controller().LoadURL( | 471 controller().LoadURL( |
| 470 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 472 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 471 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 473 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // non-zero so that orig_rfh doesn't get deleted when it gets | 518 // non-zero so that orig_rfh doesn't get deleted when it gets |
| 517 // swapped out. | 519 // swapped out. |
| 518 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 520 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 519 | 521 |
| 520 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 522 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 521 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 523 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
| 522 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 524 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 523 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 525 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 524 EXPECT_NE(instance1, instance2); | 526 EXPECT_NE(instance1, instance2); |
| 525 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); | 527 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); |
| 526 // We keep the original RFH around, swapped out. | 528 // We keep a proxy for the original RFH's SiteInstance. |
| 527 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 529 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->GetRenderFrameProxyHost( |
| 528 orig_rfh)); | 530 orig_rfh->GetSiteInstance())); |
| 529 EXPECT_EQ(orig_rvh_delete_count, 0); | 531 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 530 | 532 |
| 531 // Going back should switch SiteInstances again. The first SiteInstance is | 533 // Going back should switch SiteInstances again. The first SiteInstance is |
| 532 // 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. |
| 533 // We should use the same RFH as before, swapping it back in. | 535 // We should use the same RFH as before, swapping it back in. |
| 534 controller().GoBack(); | 536 controller().GoBack(); |
| 535 entry_id = controller().GetPendingEntry()->GetUniqueID(); | 537 entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 536 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 538 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 537 switches::kEnableBrowserSideNavigation)) { | 539 switches::kEnableBrowserSideNavigation)) { |
| 538 contents()->GetMainFrame()->PrepareForCommit(); | 540 contents()->GetMainFrame()->PrepareForCommit(); |
| 539 } | 541 } |
| 540 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); | 542 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); |
| 541 EXPECT_EQ(orig_rfh, goback_rfh); | 543 if (!is_site_per_process) |
| 544 EXPECT_EQ(orig_rfh, goback_rfh); |
| 542 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 545 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 543 | 546 |
| 544 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. | 547 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. |
| 545 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 548 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 546 switches::kEnableBrowserSideNavigation)) { | 549 switches::kEnableBrowserSideNavigation)) { |
| 547 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); | 550 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); |
| 548 pending_rfh->SendBeforeUnloadACK(true); | 551 pending_rfh->SendBeforeUnloadACK(true); |
| 549 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); | 552 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); |
| 550 } | 553 } |
| 551 | 554 |
| 552 // DidNavigate from the back action | 555 // DidNavigate from the back action |
| 553 contents()->TestDidNavigate(goback_rfh, 1, entry_id, false, url2, | 556 contents()->TestDidNavigate(goback_rfh, 1, entry_id, false, url2, |
| 554 ui::PAGE_TRANSITION_TYPED); | 557 ui::PAGE_TRANSITION_TYPED); |
| 555 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 558 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 556 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); | 559 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); |
| 557 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 560 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 558 // The pending RFH should now be swapped out, not deleted. | 561 // There should be a proxy for the pending RFH SiteInstance. |
| 559 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 562 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
| 560 IsOnSwappedOutList(pending_rfh)); | 563 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance())); |
| 561 EXPECT_EQ(pending_rvh_delete_count, 0); | 564 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 562 pending_rfh->OnSwappedOut(); | 565 pending_rfh->OnSwappedOut(); |
| 563 | 566 |
| 564 // Close contents and ensure RVHs are deleted. | 567 // Close contents and ensure RVHs are deleted. |
| 565 DeleteContents(); | 568 DeleteContents(); |
| 566 EXPECT_EQ(orig_rvh_delete_count, 1); | 569 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 567 EXPECT_EQ(pending_rvh_delete_count, 1); | 570 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 568 } | 571 } |
| 569 | 572 |
| 570 // Test that navigating across a site boundary after a crash creates a new | 573 // Test that navigating across a site boundary after a crash creates a new |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2, | 772 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2, |
| 770 ui::PAGE_TRANSITION_TYPED); | 773 ui::PAGE_TRANSITION_TYPED); |
| 771 SiteInstance* new_instance = contents()->GetSiteInstance(); | 774 SiteInstance* new_instance = contents()->GetSiteInstance(); |
| 772 | 775 |
| 773 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 776 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 774 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 777 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
| 775 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 778 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 776 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 779 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 777 EXPECT_NE(new_instance, orig_instance); | 780 EXPECT_NE(new_instance, orig_instance); |
| 778 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 781 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 779 // We keep the original RFH around, swapped out. | 782 // We keep a proxy for the original RFH's SiteInstance. |
| 780 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 783 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->GetRenderFrameProxyHost( |
| 781 orig_rfh)); | 784 orig_rfh->GetSiteInstance())); |
| 782 EXPECT_EQ(orig_rvh_delete_count, 0); | 785 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 783 orig_rfh->OnSwappedOut(); | 786 orig_rfh->OnSwappedOut(); |
| 784 | 787 |
| 785 // Close contents and ensure RVHs are deleted. | 788 // Close contents and ensure RVHs are deleted. |
| 786 DeleteContents(); | 789 DeleteContents(); |
| 787 EXPECT_EQ(orig_rvh_delete_count, 1); | 790 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 788 EXPECT_EQ(pending_rvh_delete_count, 1); | 791 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 789 } | 792 } |
| 790 | 793 |
| 791 // Regression test for http://crbug.com/386542 - variation of | 794 // Regression test for http://crbug.com/386542 - variation of |
| (...skipping 2368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 // Additional changes made by the web contents should propagate as well. | 3163 // Additional changes made by the web contents should propagate as well. |
| 3161 RenderViewHostTester::TestOnMessageReceived( | 3164 RenderViewHostTester::TestOnMessageReceived( |
| 3162 test_rvh(), | 3165 test_rvh(), |
| 3163 FrameHostMsg_DidChangeThemeColor(rfh->GetRoutingID(), SK_ColorGREEN)); | 3166 FrameHostMsg_DidChangeThemeColor(rfh->GetRoutingID(), SK_ColorGREEN)); |
| 3164 | 3167 |
| 3165 EXPECT_EQ(SK_ColorGREEN, contents()->GetThemeColor()); | 3168 EXPECT_EQ(SK_ColorGREEN, contents()->GetThemeColor()); |
| 3166 EXPECT_EQ(SK_ColorGREEN, observer.last_theme_color()); | 3169 EXPECT_EQ(SK_ColorGREEN, observer.last_theme_color()); |
| 3167 } | 3170 } |
| 3168 | 3171 |
| 3169 } // namespace content | 3172 } // namespace content |
| OLD | NEW |