| 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/site_instance_impl.h" | 10 #include "content/browser/site_instance_impl.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 void set_delegate(Delegate* delegate) { | 179 void set_delegate(Delegate* delegate) { |
| 180 delegate_ = delegate; | 180 delegate_ = delegate; |
| 181 } | 181 } |
| 182 | 182 |
| 183 protected: | 183 protected: |
| 184 virtual RenderViewHost* CreateRenderViewHost() OVERRIDE { | 184 virtual RenderViewHost* CreateRenderViewHost() OVERRIDE { |
| 185 return new TestRenderViewHost( | 185 return new TestRenderViewHost( |
| 186 SiteInstance::Create(web_contents()->GetBrowserContext()), | 186 SiteInstance::Create(web_contents()->GetBrowserContext()), |
| 187 this, this, MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); | 187 this, this, this, MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); |
| 188 } | 188 } |
| 189 | 189 |
| 190 virtual WebContentsView* CreateWebContentsView() OVERRIDE { | 190 virtual WebContentsView* CreateWebContentsView() OVERRIDE { |
| 191 return NULL; | 191 return NULL; |
| 192 } | 192 } |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 InterstitialState* state_; | 195 InterstitialState* state_; |
| 196 bool* deleted_; | 196 bool* deleted_; |
| 197 int command_received_count_; | 197 int command_received_count_; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 controller().LoadURL( | 422 controller().LoadURL( |
| 423 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); | 423 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); |
| 424 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); | 424 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); |
| 425 } | 425 } |
| 426 | 426 |
| 427 // Test that navigating across a site boundary creates a new RenderViewHost | 427 // Test that navigating across a site boundary creates a new RenderViewHost |
| 428 // with a new SiteInstance. Going back should do the same. | 428 // with a new SiteInstance. Going back should do the same. |
| 429 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 429 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
| 430 contents()->transition_cross_site = true; | 430 contents()->transition_cross_site = true; |
| 431 TestRenderViewHost* orig_rvh = test_rvh(); | 431 TestRenderViewHost* orig_rvh = test_rvh(); |
| 432 RenderFrameHostImpl* orig_rfh = | |
| 433 contents()->GetFrameTree()->root()->current_frame_host(); | |
| 434 int orig_rvh_delete_count = 0; | 432 int orig_rvh_delete_count = 0; |
| 435 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 433 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 436 SiteInstance* instance1 = contents()->GetSiteInstance(); | 434 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 437 | 435 |
| 438 // Navigate to URL. First URL should use first RenderViewHost. | 436 // Navigate to URL. First URL should use first RenderViewHost. |
| 439 const GURL url("http://www.google.com"); | 437 const GURL url("http://www.google.com"); |
| 440 controller().LoadURL( | 438 controller().LoadURL( |
| 441 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 439 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 442 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 440 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
| 443 | 441 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 456 const GURL url2("http://www.yahoo.com"); | 454 const GURL url2("http://www.yahoo.com"); |
| 457 controller().LoadURL( | 455 controller().LoadURL( |
| 458 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 456 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 459 EXPECT_TRUE(contents()->cross_navigation_pending()); | 457 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 460 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 458 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
| 461 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 459 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 462 TestRenderViewHost* pending_rvh = | 460 TestRenderViewHost* pending_rvh = |
| 463 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 461 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
| 464 int pending_rvh_delete_count = 0; | 462 int pending_rvh_delete_count = 0; |
| 465 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 463 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
| 466 RenderFrameHostImpl* pending_rfh = contents()->GetFrameTree()->root()-> | |
| 467 render_manager()->pending_frame_host(); | |
| 468 | 464 |
| 469 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 465 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
| 470 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 466 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
| 471 orig_rvh->SendShouldCloseACK(true); | 467 orig_rvh->SendShouldCloseACK(true); |
| 472 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 468 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
| 473 | 469 |
| 474 // DidNavigate from the pending page | 470 // DidNavigate from the pending page |
| 475 contents()->TestDidNavigate( | 471 contents()->TestDidNavigate( |
| 476 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 472 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 477 SiteInstance* instance2 = contents()->GetSiteInstance(); | 473 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 478 | 474 |
| 479 // Keep the number of active views in pending_rvh's SiteInstance | 475 // Keep the number of active views in pending_rvh's SiteInstance |
| 480 // non-zero so that orig_rvh doesn't get deleted when it gets | 476 // non-zero so that orig_rvh doesn't get deleted when it gets |
| 481 // swapped out. | 477 // swapped out. |
| 482 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())-> | 478 static_cast<SiteInstanceImpl*>(pending_rvh->GetSiteInstance())-> |
| 483 increment_active_view_count(); | 479 increment_active_view_count(); |
| 484 | 480 |
| 485 EXPECT_FALSE(contents()->cross_navigation_pending()); | 481 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 486 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 482 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 487 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 483 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 488 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 484 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 489 EXPECT_NE(instance1, instance2); | 485 EXPECT_NE(instance1, instance2); |
| 490 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 486 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
| 491 // We keep the original RFH around, swapped out. | 487 // We keep the original RVH around, swapped out. |
| 492 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 488 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( |
| 493 orig_rfh)); | 489 orig_rvh)); |
| 494 EXPECT_EQ(orig_rvh_delete_count, 0); | 490 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 495 | 491 |
| 496 // Going back should switch SiteInstances again. The first SiteInstance is | 492 // Going back should switch SiteInstances again. The first SiteInstance is |
| 497 // stored in the NavigationEntry, so it should be the same as at the start. | 493 // stored in the NavigationEntry, so it should be the same as at the start. |
| 498 // We should use the same RVH as before, swapping it back in. | 494 // We should use the same RVH as before, swapping it back in. |
| 499 controller().GoBack(); | 495 controller().GoBack(); |
| 500 TestRenderViewHost* goback_rvh = | 496 TestRenderViewHost* goback_rvh = |
| 501 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 497 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
| 502 EXPECT_EQ(orig_rvh, goback_rvh); | 498 EXPECT_EQ(orig_rvh, goback_rvh); |
| 503 EXPECT_TRUE(contents()->cross_navigation_pending()); | 499 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 504 | 500 |
| 505 // Navigations should be suspended in goback_rvh until ShouldCloseACK. | 501 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
| 506 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); | 502 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
| 507 pending_rvh->SendShouldCloseACK(true); | 503 pending_rvh->SendShouldCloseACK(true); |
| 508 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); | 504 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
| 509 | 505 |
| 510 // DidNavigate from the back action | 506 // DidNavigate from the back action |
| 511 contents()->TestDidNavigate( | 507 contents()->TestDidNavigate( |
| 512 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 508 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 513 EXPECT_FALSE(contents()->cross_navigation_pending()); | 509 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 514 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); | 510 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); |
| 515 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 511 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 516 // The pending RFH should now be swapped out, not deleted. | 512 // The pending RVH should now be swapped out, not deleted. |
| 517 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 513 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
| 518 IsOnSwappedOutList(pending_rfh)); | 514 IsOnSwappedOutList(pending_rvh)); |
| 519 EXPECT_EQ(pending_rvh_delete_count, 0); | 515 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 520 | 516 |
| 521 // Close contents and ensure RVHs are deleted. | 517 // Close contents and ensure RVHs are deleted. |
| 522 DeleteContents(); | 518 DeleteContents(); |
| 523 EXPECT_EQ(orig_rvh_delete_count, 1); | 519 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 524 EXPECT_EQ(pending_rvh_delete_count, 1); | 520 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 525 } | 521 } |
| 526 | 522 |
| 527 // Test that navigating across a site boundary after a crash creates a new | 523 // Test that navigating across a site boundary after a crash creates a new |
| 528 // RVH without requiring a cross-site transition (i.e., PENDING state). | 524 // RVH without requiring a cross-site transition (i.e., PENDING state). |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 // Both contentses should now be in the same SiteInstance. | 627 // Both contentses should now be in the same SiteInstance. |
| 632 EXPECT_EQ(instance2a, instance2b); | 628 EXPECT_EQ(instance2a, instance2b); |
| 633 } | 629 } |
| 634 | 630 |
| 635 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { | 631 TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) { |
| 636 WebContentsImplTestBrowserClient browser_client; | 632 WebContentsImplTestBrowserClient browser_client; |
| 637 SetBrowserClientForTesting(&browser_client); | 633 SetBrowserClientForTesting(&browser_client); |
| 638 | 634 |
| 639 contents()->transition_cross_site = true; | 635 contents()->transition_cross_site = true; |
| 640 TestRenderViewHost* orig_rvh = test_rvh(); | 636 TestRenderViewHost* orig_rvh = test_rvh(); |
| 641 RenderFrameHostImpl* orig_rfh = | |
| 642 contents()->GetFrameTree()->root()->current_frame_host(); | |
| 643 int orig_rvh_delete_count = 0; | 637 int orig_rvh_delete_count = 0; |
| 644 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 638 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
| 645 SiteInstanceImpl* orig_instance = | 639 SiteInstanceImpl* orig_instance = |
| 646 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 640 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
| 647 | 641 |
| 648 browser_client.set_assign_site_for_url(false); | 642 browser_client.set_assign_site_for_url(false); |
| 649 // Navigate to an URL that will not assign a new SiteInstance. | 643 // Navigate to an URL that will not assign a new SiteInstance. |
| 650 const GURL native_url("non-site-url://stuffandthings"); | 644 const GURL native_url("non-site-url://stuffandthings"); |
| 651 controller().LoadURL( | 645 controller().LoadURL( |
| 652 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 646 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 contents()->TestDidNavigate( | 697 contents()->TestDidNavigate( |
| 704 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); | 698 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
| 705 SiteInstance* new_instance = contents()->GetSiteInstance(); | 699 SiteInstance* new_instance = contents()->GetSiteInstance(); |
| 706 | 700 |
| 707 EXPECT_FALSE(contents()->cross_navigation_pending()); | 701 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 708 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 702 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
| 709 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 703 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| 710 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 704 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
| 711 EXPECT_NE(new_instance, orig_instance); | 705 EXPECT_NE(new_instance, orig_instance); |
| 712 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); | 706 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
| 713 // We keep the original RFH around, swapped out. | 707 // We keep the original RVH around, swapped out. |
| 714 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 708 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( |
| 715 orig_rfh)); | 709 orig_rvh)); |
| 716 EXPECT_EQ(orig_rvh_delete_count, 0); | 710 EXPECT_EQ(orig_rvh_delete_count, 0); |
| 717 | 711 |
| 718 // Close contents and ensure RVHs are deleted. | 712 // Close contents and ensure RVHs are deleted. |
| 719 DeleteContents(); | 713 DeleteContents(); |
| 720 EXPECT_EQ(orig_rvh_delete_count, 1); | 714 EXPECT_EQ(orig_rvh_delete_count, 1); |
| 721 EXPECT_EQ(pending_rvh_delete_count, 1); | 715 EXPECT_EQ(pending_rvh_delete_count, 1); |
| 722 } | 716 } |
| 723 | 717 |
| 724 // Test that we can find an opener RVH even if it's pending. | 718 // Test that we can find an opener RVH even if it's pending. |
| 725 // http://crbug.com/176252. | 719 // http://crbug.com/176252. |
| (...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 TEST_F(WebContentsImplTest, PendingContents) { | 2162 TEST_F(WebContentsImplTest, PendingContents) { |
| 2169 scoped_ptr<TestWebContents> other_contents( | 2163 scoped_ptr<TestWebContents> other_contents( |
| 2170 static_cast<TestWebContents*>(CreateTestWebContents())); | 2164 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 2171 contents()->AddPendingContents(other_contents.get()); | 2165 contents()->AddPendingContents(other_contents.get()); |
| 2172 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); | 2166 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); |
| 2173 other_contents.reset(); | 2167 other_contents.reset(); |
| 2174 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); | 2168 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); |
| 2175 } | 2169 } |
| 2176 | 2170 |
| 2177 } // namespace content | 2171 } // namespace content |
| OLD | NEW |