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