| 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/interstitial_page_impl.h" | 7 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 8 #include "content/browser/frame_host/navigation_entry_impl.h" | 8 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 controller().LoadURL( | 401 controller().LoadURL( |
| 402 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); | 402 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); |
| 403 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); | 403 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); |
| 404 } | 404 } |
| 405 | 405 |
| 406 // Test that navigating across a site boundary creates a new RenderViewHost | 406 // Test that navigating across a site boundary creates a new RenderViewHost |
| 407 // with a new SiteInstance. Going back should do the same. | 407 // with a new SiteInstance. Going back should do the same. |
| 408 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 408 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
| 409 contents()->transition_cross_site = true; | 409 contents()->transition_cross_site = true; |
| 410 TestRenderViewHost* orig_rvh = test_rvh(); | 410 TestRenderViewHost* orig_rvh = test_rvh(); |
| 411 RenderFrameHostImpl* orig_rfh = |
| 412 contents()->GetFrameTree()->root()->render_frame_host(); |
| 411 int orig_rvh_delete_count = 0; | 413 int orig_rvh_delete_count = 0; |
| 412 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 414 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 413 SiteInstance* instance1 = contents()->GetSiteInstance(); | 415 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 414 | 416 |
| 415 // Navigate to URL. First URL should use first RenderViewHost. | 417 // Navigate to URL. First URL should use first RenderViewHost. |
| 416 const GURL url("http://www.google.com"); | 418 const GURL url("http://www.google.com"); |
| 417 controller().LoadURL( | 419 controller().LoadURL( |
| 418 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 420 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 419 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 421 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
| 420 | 422 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 433 const GURL url2("http://www.yahoo.com"); | 435 const GURL url2("http://www.yahoo.com"); |
| 434 controller().LoadURL( | 436 controller().LoadURL( |
| 435 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 437 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 436 EXPECT_TRUE(contents()->cross_navigation_pending()); | 438 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 437 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 439 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
| 438 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 440 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 439 TestRenderViewHost* pending_rvh = | 441 TestRenderViewHost* pending_rvh = |
| 440 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 442 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
| 441 int pending_rvh_delete_count = 0; | 443 int pending_rvh_delete_count = 0; |
| 442 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 444 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
| 445 RenderFrameHostImpl* pending_rfh = |
| 446 contents()->GetFrameTree()->root()->render_manager()->pending_render_frame
_host(); |
| 443 | 447 |
| 444 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 448 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 445 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 449 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 446 orig_rvh->SendShouldCloseACK(true); | 450 orig_rvh->SendShouldCloseACK(true); |
| 447 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 451 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 448 | 452 |
| 449 // DidNavigate from the pending page | 453 // DidNavigate from the pending page |
| 450 contents()->TestDidNavigate( | 454 contents()->TestDidNavigate( |
| 451 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 455 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 452 SiteInstance* instance2 = contents()->GetSiteInstance(); | 456 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 453 | 457 |
| 454 // Keep the number of active views in pending_rvh's SiteInstance | 458 // Keep the number of active views in pending_rvh's SiteInstance |
| 455 // non-zero so that orig_rvh doesn't get deleted when it gets | 459 // non-zero so that orig_rvh doesn't get deleted when it gets |
| 456 // swapped out. | 460 // swapped out. |
| 457 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())-> | 461 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())-> |
| 458 increment_active_view_count(); | 462 increment_active_view_count(); |
| 459 | 463 |
| 460 EXPECT_FALSE(contents()->cross_navigation_pending()); | 464 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 461 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 465 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 462 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 466 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 463 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 467 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 464 EXPECT_NE(instance1, instance2); | 468 EXPECT_NE(instance1, instance2); |
| 465 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 469 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
| 466 // We keep the original RVH around, swapped out. | 470 // We keep the original RFH around, swapped out. |
| 467 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 471 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( |
| 468 orig_rvh)); | 472 orig_rfh)); |
| 469 EXPECT_EQ(orig_rvh_delete_count, 0); | 473 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 470 | 474 |
| 471 // Going back should switch SiteInstances again. The first SiteInstance is | 475 // Going back should switch SiteInstances again. The first SiteInstance is |
| 472 // stored in the NavigationEntry, so it should be the same as at the start. | 476 // stored in the NavigationEntry, so it should be the same as at the start. |
| 473 // We should use the same RVH as before, swapping it back in. | 477 // We should use the same RVH as before, swapping it back in. |
| 474 controller().GoBack(); | 478 controller().GoBack(); |
| 475 TestRenderViewHost* goback_rvh = | 479 TestRenderViewHost* goback_rvh = |
| 476 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 480 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
| 477 EXPECT_EQ(orig_rvh, goback_rvh); | 481 EXPECT_EQ(orig_rvh, goback_rvh); |
| 478 EXPECT_TRUE(contents()->cross_navigation_pending()); | 482 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 479 | 483 |
| 480 // Navigations should be suspended in goback_rvh until ShouldCloseACK. | 484 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
| 481 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); | 485 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
| 482 pending_rvh->SendShouldCloseACK(true); | 486 pending_rvh->SendShouldCloseACK(true); |
| 483 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); | 487 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
| 484 | 488 |
| 485 // DidNavigate from the back action | 489 // DidNavigate from the back action |
| 486 contents()->TestDidNavigate( | 490 contents()->TestDidNavigate( |
| 487 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 491 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 488 EXPECT_FALSE(contents()->cross_navigation_pending()); | 492 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 489 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); | 493 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); |
| 490 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 494 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 491 // The pending RVH should now be swapped out, not deleted. | 495 // The pending RFH should now be swapped out, not deleted. |
| 492 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 496 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
| 493 IsOnSwappedOutList(pending_rvh)); | 497 IsOnSwappedOutList(pending_rfh)); |
| 494 EXPECT_EQ(pending_rvh_delete_count, 0); | 498 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 495 | 499 |
| 496 // Close contents and ensure RVHs are deleted. | 500 // Close contents and ensure RVHs are deleted. |
| 497 DeleteContents(); | 501 DeleteContents(); |
| 498 EXPECT_EQ(orig_rvh_delete_count, 1); | 502 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 499 EXPECT_EQ(pending_rvh_delete_count, 1); | 503 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 500 } | 504 } |
| 501 | 505 |
| 502 // Test that navigating across a site boundary after a crash creates a new | 506 // Test that navigating across a site boundary after a crash creates a new |
| 503 // RVH without requiring a cross-site transition (i.e., PENDING state). | 507 // RVH without requiring a cross-site transition (i.e., PENDING state). |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 // Both contentses should now be in the same SiteInstance. | 610 // Both contentses should now be in the same SiteInstance. |
| 607 EXPECT_EQ(instance2a, instance2b); | 611 EXPECT_EQ(instance2a, instance2b); |
| 608 } | 612 } |
| 609 | 613 |
| 610 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { | 614 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { |
| 611 WebContentsImplTestBrowserClient browser_client; | 615 WebContentsImplTestBrowserClient browser_client; |
| 612 SetBrowserClientForTesting(&browser_client); | 616 SetBrowserClientForTesting(&browser_client); |
| 613 | 617 |
| 614 contents()->transition_cross_site = true; | 618 contents()->transition_cross_site = true; |
| 615 TestRenderViewHost* orig_rvh = test_rvh(); | 619 TestRenderViewHost* orig_rvh = test_rvh(); |
| 620 RenderFrameHostImpl* orig_rfh = |
| 621 contents()->GetFrameTree()->root()->render_frame_host(); |
| 616 int orig_rvh_delete_count = 0; | 622 int orig_rvh_delete_count = 0; |
| 617 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 623 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 618 SiteInstanceImpl* orig_instance = | 624 SiteInstanceImpl* orig_instance = |
| 619 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 625 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
| 620 | 626 |
| 621 browser_client.set_assign_site_for_url(false); | 627 browser_client.set_assign_site_for_url(false); |
| 622 // Navigate to an URL that will not assign a new SiteInstance. | 628 // Navigate to an URL that will not assign a new SiteInstance. |
| 623 const GURL native_url("non-site-url://stuffandthings"); | 629 const GURL native_url("non-site-url://stuffandthings"); |
| 624 controller().LoadURL( | 630 controller().LoadURL( |
| 625 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 631 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 contents()->TestDidNavigate( | 682 contents()->TestDidNavigate( |
| 677 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 683 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 678 SiteInstance* new_instance = contents()->GetSiteInstance(); | 684 SiteInstance* new_instance = contents()->GetSiteInstance(); |
| 679 | 685 |
| 680 EXPECT_FALSE(contents()->cross_navigation_pending()); | 686 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 681 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 687 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 682 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 688 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 683 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 689 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 684 EXPECT_NE(new_instance, orig_instance); | 690 EXPECT_NE(new_instance, orig_instance); |
| 685 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); | 691 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
| 686 // We keep the original RVH around, swapped out. | 692 // We keep the original RFH around, swapped out. |
| 687 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 693 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( |
| 688 orig_rvh)); | 694 orig_rfh)); |
| 689 EXPECT_EQ(orig_rvh_delete_count, 0); | 695 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 690 | 696 |
| 691 // Close contents and ensure RVHs are deleted. | 697 // Close contents and ensure RVHs are deleted. |
| 692 DeleteContents(); | 698 DeleteContents(); |
| 693 EXPECT_EQ(orig_rvh_delete_count, 1); | 699 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 694 EXPECT_EQ(pending_rvh_delete_count, 1); | 700 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 695 } | 701 } |
| 696 | 702 |
| 697 // Test that we can find an opener RVH even if it's pending. | 703 // Test that we can find an opener RVH even if it's pending. |
| 698 // http://crbug.com/176252. | 704 // http://crbug.com/176252. |
| (...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 TEST_F(WebContentsImplTest, PendingContents) { | 2147 TEST_F(WebContentsImplTest, PendingContents) { |
| 2142 scoped_ptr<TestWebContents> other_contents( | 2148 scoped_ptr<TestWebContents> other_contents( |
| 2143 static_cast<TestWebContents*>(CreateTestWebContents())); | 2149 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 2144 contents()->AddPendingContents(other_contents.get()); | 2150 contents()->AddPendingContents(other_contents.get()); |
| 2145 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); | 2151 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); |
| 2146 other_contents.reset(); | 2152 other_contents.reset(); |
| 2147 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); | 2153 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); |
| 2148 } | 2154 } |
| 2149 | 2155 |
| 2150 } // namespace content | 2156 } // namespace content |
| OLD | NEW |