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