Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 606113005: Move RenderViewHost swap out state to RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review suggestions Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cross_site_transferring_request.h" 7 #include "content/browser/frame_host/cross_site_transferring_request.h"
8 #include "content/browser/frame_host/interstitial_page_impl.h" 8 #include "content/browser/frame_host/interstitial_page_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/media/audio_stream_monitor.h" 10 #include "content/browser/media/audio_stream_monitor.h"
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 int orig_rvh_delete_count = 0; 471 int orig_rvh_delete_count = 0;
472 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 472 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
473 SiteInstance* instance1 = contents()->GetSiteInstance(); 473 SiteInstance* instance1 = contents()->GetSiteInstance();
474 474
475 // Navigate to URL. First URL should use first RenderViewHost. 475 // Navigate to URL. First URL should use first RenderViewHost.
476 const GURL url("http://www.google.com"); 476 const GURL url("http://www.google.com");
477 controller().LoadURL( 477 controller().LoadURL(
478 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 478 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
479 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 479 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
480 480
481 // Keep the number of active views in orig_rfh's SiteInstance non-zero so that 481 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
482 // orig_rfh doesn't get deleted when it gets swapped out. 482 // that orig_rfh doesn't get deleted when it gets swapped out.
483 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> 483 orig_rfh->GetSiteInstance()->increment_active_frame_count();
484 increment_active_view_count();
485 484
486 EXPECT_FALSE(contents()->cross_navigation_pending()); 485 EXPECT_FALSE(contents()->cross_navigation_pending());
487 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 486 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
488 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 487 EXPECT_EQ(url, contents()->GetLastCommittedURL());
489 EXPECT_EQ(url, contents()->GetVisibleURL()); 488 EXPECT_EQ(url, contents()->GetVisibleURL());
490 489
491 // Navigate to new site 490 // Navigate to new site
492 const GURL url2("http://www.yahoo.com"); 491 const GURL url2("http://www.yahoo.com");
493 controller().LoadURL( 492 controller().LoadURL(
494 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 493 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
495 EXPECT_TRUE(contents()->cross_navigation_pending()); 494 EXPECT_TRUE(contents()->cross_navigation_pending());
496 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 495 EXPECT_EQ(url, contents()->GetLastCommittedURL());
497 EXPECT_EQ(url2, contents()->GetVisibleURL()); 496 EXPECT_EQ(url2, contents()->GetVisibleURL());
498 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 497 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
499 int pending_rvh_delete_count = 0; 498 int pending_rvh_delete_count = 0;
500 pending_rfh->GetRenderViewHost()->set_delete_counter( 499 pending_rfh->GetRenderViewHost()->set_delete_counter(
501 &pending_rvh_delete_count); 500 &pending_rvh_delete_count);
502 501
503 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 502 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
504 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 503 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
505 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); 504 orig_rfh->SendBeforeUnloadACK(true);
506 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 505 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
507 506
508 // DidNavigate from the pending page 507 // DidNavigate from the pending page
509 contents()->TestDidNavigate( 508 contents()->TestDidNavigate(
510 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 509 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
511 SiteInstance* instance2 = contents()->GetSiteInstance(); 510 SiteInstance* instance2 = contents()->GetSiteInstance();
512 511
513 // Keep the number of active views in pending_rfh's SiteInstance 512 // Keep the number of active frames in pending_rfh's SiteInstance
514 // non-zero so that orig_rfh doesn't get deleted when it gets 513 // non-zero so that orig_rfh doesn't get deleted when it gets
515 // swapped out. 514 // swapped out.
516 static_cast<SiteInstanceImpl*>(pending_rfh->GetSiteInstance())-> 515 pending_rfh->GetSiteInstance()->increment_active_frame_count();
517 increment_active_view_count();
518 516
519 EXPECT_FALSE(contents()->cross_navigation_pending()); 517 EXPECT_FALSE(contents()->cross_navigation_pending());
520 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 518 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
521 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 519 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
522 EXPECT_EQ(url2, contents()->GetVisibleURL()); 520 EXPECT_EQ(url2, contents()->GetVisibleURL());
523 EXPECT_NE(instance1, instance2); 521 EXPECT_NE(instance1, instance2);
524 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 522 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
525 // We keep the original RFH around, swapped out. 523 // We keep the original RFH around, swapped out.
526 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 524 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
527 orig_rfh)); 525 orig_rfh));
528 EXPECT_EQ(orig_rvh_delete_count, 0); 526 EXPECT_EQ(orig_rvh_delete_count, 0);
529 527
530 // Going back should switch SiteInstances again. The first SiteInstance is 528 // Going back should switch SiteInstances again. The first SiteInstance is
531 // stored in the NavigationEntry, so it should be the same as at the start. 529 // stored in the NavigationEntry, so it should be the same as at the start.
532 // We should use the same RFH as before, swapping it back in. 530 // We should use the same RFH as before, swapping it back in.
533 controller().GoBack(); 531 controller().GoBack();
534 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 532 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
535 EXPECT_EQ(orig_rfh, goback_rfh); 533 EXPECT_EQ(orig_rfh, goback_rfh);
536 EXPECT_TRUE(contents()->cross_navigation_pending()); 534 EXPECT_TRUE(contents()->cross_navigation_pending());
537 535
538 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 536 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
539 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 537 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
540 pending_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); 538 pending_rfh->SendBeforeUnloadACK(true);
541 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); 539 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
542 540
543 // DidNavigate from the back action 541 // DidNavigate from the back action
544 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 542 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
545 EXPECT_FALSE(contents()->cross_navigation_pending()); 543 EXPECT_FALSE(contents()->cross_navigation_pending());
546 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); 544 EXPECT_EQ(goback_rfh, contents()->GetMainFrame());
547 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 545 EXPECT_EQ(instance1, contents()->GetSiteInstance());
548 // The pending RFH should now be swapped out, not deleted. 546 // The pending RFH should now be swapped out, not deleted.
549 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 547 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
550 IsOnSwappedOutList(pending_rfh)); 548 IsOnSwappedOutList(pending_rfh));
551 EXPECT_EQ(pending_rvh_delete_count, 0); 549 EXPECT_EQ(pending_rvh_delete_count, 0);
552 pending_rfh->OnSwappedOut(false); 550 pending_rfh->OnSwappedOut();
553 551
554 // Close contents and ensure RVHs are deleted. 552 // Close contents and ensure RVHs are deleted.
555 DeleteContents(); 553 DeleteContents();
556 EXPECT_EQ(orig_rvh_delete_count, 1); 554 EXPECT_EQ(orig_rvh_delete_count, 1);
557 EXPECT_EQ(pending_rvh_delete_count, 1); 555 EXPECT_EQ(pending_rvh_delete_count, 1);
558 } 556 }
559 557
560 // Test that navigating across a site boundary after a crash creates a new 558 // Test that navigating across a site boundary after a crash creates a new
561 // RFH without requiring a cross-site transition (i.e., PENDING state). 559 // RFH without requiring a cross-site transition (i.e., PENDING state).
562 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { 560 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::string()); 622 std::string());
625 // Need this page id to be 2 since the site instance is the same (which is the 623 // Need this page id to be 2 since the site instance is the same (which is the
626 // scope of page IDs) and we want to consider this a new page. 624 // scope of page IDs) and we want to consider this a new page.
627 contents2->TestDidNavigate( 625 contents2->TestDidNavigate(
628 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 626 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
629 627
630 // Navigate first contents to a new site. 628 // Navigate first contents to a new site.
631 const GURL url2a("http://www.yahoo.com"); 629 const GURL url2a("http://www.yahoo.com");
632 controller().LoadURL( 630 controller().LoadURL(
633 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 631 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
634 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); 632 orig_rfh->SendBeforeUnloadACK(true);
635 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); 633 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame();
636 contents()->TestDidNavigate( 634 contents()->TestDidNavigate(
637 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); 635 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED);
638 SiteInstance* instance2a = contents()->GetSiteInstance(); 636 SiteInstance* instance2a = contents()->GetSiteInstance();
639 EXPECT_NE(instance1, instance2a); 637 EXPECT_NE(instance1, instance2a);
640 638
641 // Navigate second contents to the same site as the first tab. 639 // Navigate second contents to the same site as the first tab.
642 const GURL url2b("http://mail.yahoo.com"); 640 const GURL url2b("http://mail.yahoo.com");
643 contents2->GetController().LoadURL(url2b, Referrer(), 641 contents2->GetController().LoadURL(url2b, Referrer(),
644 ui::PAGE_TRANSITION_TYPED, 642 ui::PAGE_TRANSITION_TYPED,
645 std::string()); 643 std::string());
646 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 644 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
647 rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); 645 rfh2->SendBeforeUnloadACK(true);
648 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); 646 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame();
649 EXPECT_TRUE(pending_rfh_b != NULL); 647 EXPECT_TRUE(pending_rfh_b != NULL);
650 EXPECT_TRUE(contents2->cross_navigation_pending()); 648 EXPECT_TRUE(contents2->cross_navigation_pending());
651 649
652 // NOTE(creis): We used to be in danger of showing a crash page here if the 650 // NOTE(creis): We used to be in danger of showing a crash page here if the
653 // second contents hadn't navigated somewhere first (bug 1145430). That case 651 // second contents hadn't navigated somewhere first (bug 1145430). That case
654 // is now covered by the CrossSiteBoundariesAfterCrash test. 652 // is now covered by the CrossSiteBoundariesAfterCrash test.
655 contents2->TestDidNavigate( 653 contents2->TestDidNavigate(
656 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); 654 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED);
657 SiteInstance* instance2b = contents2->GetSiteInstance(); 655 SiteInstance* instance2b = contents2->GetSiteInstance();
658 EXPECT_NE(instance1, instance2b); 656 EXPECT_NE(instance1, instance2b);
659 657
660 // Both contentses should now be in the same SiteInstance. 658 // Both contentses should now be in the same SiteInstance.
661 EXPECT_EQ(instance2a, instance2b); 659 EXPECT_EQ(instance2a, instance2b);
662 } 660 }
663 661
664 // The embedder can request sites for certain urls not be be assigned to the 662 // The embedder can request sites for certain urls not be be assigned to the
665 // SiteInstance through ShouldAssignSiteForURL() in content browser client, 663 // SiteInstance through ShouldAssignSiteForURL() in content browser client,
666 // allowing to reuse the renderer backing certain chrome urls for subsequent 664 // allowing to reuse the renderer backing certain chrome urls for subsequent
667 // navigation. The test verifies that the override is honored. 665 // navigation. The test verifies that the override is honored.
668 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { 666 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) {
669 WebContentsImplTestBrowserClient browser_client; 667 WebContentsImplTestBrowserClient browser_client;
670 SetBrowserClientForTesting(&browser_client); 668 SetBrowserClientForTesting(&browser_client);
671 669
672 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 670 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
673 int orig_rvh_delete_count = 0; 671 int orig_rvh_delete_count = 0;
674 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 672 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
675 SiteInstanceImpl* orig_instance = 673 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
676 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance());
677 674
678 browser_client.set_assign_site_for_url(false); 675 browser_client.set_assign_site_for_url(false);
679 // Navigate to an URL that will not assign a new SiteInstance. 676 // Navigate to an URL that will not assign a new SiteInstance.
680 const GURL native_url("non-site-url://stuffandthings"); 677 const GURL native_url("non-site-url://stuffandthings");
681 controller().LoadURL( 678 controller().LoadURL(
682 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 679 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
683 contents()->TestDidNavigate( 680 contents()->TestDidNavigate(
684 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); 681 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED);
685 682
686 EXPECT_FALSE(contents()->cross_navigation_pending()); 683 EXPECT_FALSE(contents()->cross_navigation_pending());
687 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 684 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
688 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 685 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
689 EXPECT_EQ(native_url, contents()->GetVisibleURL()); 686 EXPECT_EQ(native_url, contents()->GetVisibleURL());
690 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 687 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
691 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 688 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
692 EXPECT_FALSE(orig_instance->HasSite()); 689 EXPECT_FALSE(orig_instance->HasSite());
693 690
694 browser_client.set_assign_site_for_url(true); 691 browser_client.set_assign_site_for_url(true);
695 // Navigate to new site (should keep same site instance). 692 // Navigate to new site (should keep same site instance).
696 const GURL url("http://www.google.com"); 693 const GURL url("http://www.google.com");
697 controller().LoadURL( 694 controller().LoadURL(
698 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 695 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
699 EXPECT_FALSE(contents()->cross_navigation_pending()); 696 EXPECT_FALSE(contents()->cross_navigation_pending());
700 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 697 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
701 EXPECT_EQ(url, contents()->GetVisibleURL()); 698 EXPECT_EQ(url, contents()->GetVisibleURL());
702 EXPECT_FALSE(contents()->GetPendingMainFrame()); 699 EXPECT_FALSE(contents()->GetPendingMainFrame());
703 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 700 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
704 701
705 // Keep the number of active views in orig_rfh's SiteInstance 702 // Keep the number of active frames in orig_rfh's SiteInstance
706 // non-zero so that orig_rfh doesn't get deleted when it gets 703 // non-zero so that orig_rfh doesn't get deleted when it gets
707 // swapped out. 704 // swapped out.
708 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> 705 orig_rfh->GetSiteInstance()->increment_active_frame_count();
709 increment_active_view_count();
710 706
711 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 707 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
712 EXPECT_TRUE( 708 EXPECT_TRUE(
713 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 709 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
714 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 710 EXPECT_EQ(url, contents()->GetLastCommittedURL());
715 711
716 // Navigate to another new site (should create a new site instance). 712 // Navigate to another new site (should create a new site instance).
717 const GURL url2("http://www.yahoo.com"); 713 const GURL url2("http://www.yahoo.com");
718 controller().LoadURL( 714 controller().LoadURL(
719 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 715 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
720 EXPECT_TRUE(contents()->cross_navigation_pending()); 716 EXPECT_TRUE(contents()->cross_navigation_pending());
721 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 717 EXPECT_EQ(url, contents()->GetLastCommittedURL());
722 EXPECT_EQ(url2, contents()->GetVisibleURL()); 718 EXPECT_EQ(url2, contents()->GetVisibleURL());
723 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 719 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
724 int pending_rvh_delete_count = 0; 720 int pending_rvh_delete_count = 0;
725 pending_rfh->GetRenderViewHost()->set_delete_counter( 721 pending_rfh->GetRenderViewHost()->set_delete_counter(
726 &pending_rvh_delete_count); 722 &pending_rvh_delete_count);
727 723
728 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 724 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
729 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 725 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
730 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); 726 orig_rfh->SendBeforeUnloadACK(true);
731 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 727 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
732 728
733 // DidNavigate from the pending page. 729 // DidNavigate from the pending page.
734 contents()->TestDidNavigate( 730 contents()->TestDidNavigate(
735 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 731 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
736 SiteInstance* new_instance = contents()->GetSiteInstance(); 732 SiteInstance* new_instance = contents()->GetSiteInstance();
737 733
738 EXPECT_FALSE(contents()->cross_navigation_pending()); 734 EXPECT_FALSE(contents()->cross_navigation_pending());
739 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 735 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
740 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 736 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
741 EXPECT_EQ(url2, contents()->GetVisibleURL()); 737 EXPECT_EQ(url2, contents()->GetVisibleURL());
742 EXPECT_NE(new_instance, orig_instance); 738 EXPECT_NE(new_instance, orig_instance);
743 EXPECT_FALSE(contents()->GetPendingMainFrame()); 739 EXPECT_FALSE(contents()->GetPendingMainFrame());
744 // We keep the original RFH around, swapped out. 740 // We keep the original RFH around, swapped out.
745 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 741 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
746 orig_rfh)); 742 orig_rfh));
747 EXPECT_EQ(orig_rvh_delete_count, 0); 743 EXPECT_EQ(orig_rvh_delete_count, 0);
748 orig_rfh->OnSwappedOut(false); 744 orig_rfh->OnSwappedOut();
749 745
750 // Close contents and ensure RVHs are deleted. 746 // Close contents and ensure RVHs are deleted.
751 DeleteContents(); 747 DeleteContents();
752 EXPECT_EQ(orig_rvh_delete_count, 1); 748 EXPECT_EQ(orig_rvh_delete_count, 1);
753 EXPECT_EQ(pending_rvh_delete_count, 1); 749 EXPECT_EQ(pending_rvh_delete_count, 1);
754 } 750 }
755 751
756 // Regression test for http://crbug.com/386542 - variation of 752 // Regression test for http://crbug.com/386542 - variation of
757 // NavigateFromSitelessUrl in which the original navigation is a session 753 // NavigateFromSitelessUrl in which the original navigation is a session
758 // restore. 754 // restore.
759 TEST_F(WebContentsImplTest, NavigateFromRestoredSitelessUrl) { 755 TEST_F(WebContentsImplTest, NavigateFromRestoredSitelessUrl) {
760 WebContentsImplTestBrowserClient browser_client; 756 WebContentsImplTestBrowserClient browser_client;
761 SetBrowserClientForTesting(&browser_client); 757 SetBrowserClientForTesting(&browser_client);
762 SiteInstanceImpl* orig_instance = 758 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
763 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance());
764 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 759 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
765 760
766 // Restore a navigation entry for URL that should not assign site to the 761 // Restore a navigation entry for URL that should not assign site to the
767 // SiteInstance. 762 // SiteInstance.
768 browser_client.set_assign_site_for_url(false); 763 browser_client.set_assign_site_for_url(false);
769 const GURL native_url("non-site-url://stuffandthings"); 764 const GURL native_url("non-site-url://stuffandthings");
770 std::vector<NavigationEntry*> entries; 765 std::vector<NavigationEntry*> entries;
771 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( 766 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry(
772 native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), 767 native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(),
773 browser_context()); 768 browser_context());
(...skipping 22 matching lines...) Expand all
796 791
797 // Cleanup. 792 // Cleanup.
798 DeleteContents(); 793 DeleteContents();
799 } 794 }
800 795
801 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular 796 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular
802 // tab is restored, the SiteInstance will change upon navigation. 797 // tab is restored, the SiteInstance will change upon navigation.
803 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { 798 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) {
804 WebContentsImplTestBrowserClient browser_client; 799 WebContentsImplTestBrowserClient browser_client;
805 SetBrowserClientForTesting(&browser_client); 800 SetBrowserClientForTesting(&browser_client);
806 SiteInstanceImpl* orig_instance = 801 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
807 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance());
808 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 802 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
809 803
810 // Restore a navigation entry for a regular URL ensuring that the embedder 804 // Restore a navigation entry for a regular URL ensuring that the embedder
811 // ShouldAssignSiteForUrl override is disabled (i.e. returns true). 805 // ShouldAssignSiteForUrl override is disabled (i.e. returns true).
812 browser_client.set_assign_site_for_url(true); 806 browser_client.set_assign_site_for_url(true);
813 const GURL regular_url("http://www.yahoo.com"); 807 const GURL regular_url("http://www.yahoo.com");
814 std::vector<NavigationEntry*> entries; 808 std::vector<NavigationEntry*> entries;
815 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( 809 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry(
816 regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), 810 regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(),
817 browser_context()); 811 browser_context());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 // Navigate to a URL. 843 // Navigate to a URL.
850 const GURL url("http://www.google.com"); 844 const GURL url("http://www.google.com");
851 controller().LoadURL( 845 controller().LoadURL(
852 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 846 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
853 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 847 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
854 848
855 // Start to navigate first tab to a new site, so that it has a pending RVH. 849 // Start to navigate first tab to a new site, so that it has a pending RVH.
856 const GURL url2("http://www.yahoo.com"); 850 const GURL url2("http://www.yahoo.com");
857 controller().LoadURL( 851 controller().LoadURL(
858 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 852 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
859 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); 853 orig_rfh->SendBeforeUnloadACK(true);
860 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 854 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
861 855
862 // While it is still pending, simulate opening a new tab with the first tab 856 // While it is still pending, simulate opening a new tab with the first tab
863 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews 857 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews
864 // on the opener to ensure that an RVH exists. 858 // on the opener to ensure that an RVH exists.
865 int opener_routing_id = 859 int opener_routing_id =
866 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); 860 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance());
867 861
868 // We should find the pending RVH and not create a new one. 862 // We should find the pending RVH and not create a new one.
869 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), 863 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 controller().LoadURL( 924 controller().LoadURL(
931 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 925 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
932 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 926 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
933 EXPECT_FALSE(contents()->cross_navigation_pending()); 927 EXPECT_FALSE(contents()->cross_navigation_pending());
934 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 928 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
935 929
936 // Navigate to new site, but simulate an onbeforeunload denial. 930 // Navigate to new site, but simulate an onbeforeunload denial.
937 const GURL url2("http://www.yahoo.com"); 931 const GURL url2("http://www.yahoo.com");
938 controller().LoadURL( 932 controller().LoadURL(
939 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 933 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
940 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 934 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
941 base::TimeTicks now = base::TimeTicks::Now(); 935 base::TimeTicks now = base::TimeTicks::Now();
942 orig_rfh->OnMessageReceived( 936 orig_rfh->OnMessageReceived(
943 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 937 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
944 EXPECT_FALSE( 938 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
945 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
946 EXPECT_FALSE(contents()->cross_navigation_pending()); 939 EXPECT_FALSE(contents()->cross_navigation_pending());
947 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 940 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
948 941
949 // Navigate again, but simulate an onbeforeunload approval. 942 // Navigate again, but simulate an onbeforeunload approval.
950 controller().LoadURL( 943 controller().LoadURL(
951 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 944 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
952 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 945 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
953 now = base::TimeTicks::Now(); 946 now = base::TimeTicks::Now();
954 orig_rfh->OnMessageReceived( 947 orig_rfh->OnMessageReceived(
955 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 948 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
956 EXPECT_FALSE( 949 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
957 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
958 EXPECT_TRUE(contents()->cross_navigation_pending()); 950 EXPECT_TRUE(contents()->cross_navigation_pending());
959 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 951 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
960 952
961 // We won't hear DidNavigate until the onunload handler has finished running. 953 // We won't hear DidNavigate until the onunload handler has finished running.
962 954
963 // DidNavigate from the pending page. 955 // DidNavigate from the pending page.
964 contents()->TestDidNavigate( 956 contents()->TestDidNavigate(
965 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 957 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
966 SiteInstance* instance2 = contents()->GetSiteInstance(); 958 SiteInstance* instance2 = contents()->GetSiteInstance();
967 EXPECT_FALSE(contents()->cross_navigation_pending()); 959 EXPECT_FALSE(contents()->cross_navigation_pending());
(...skipping 14 matching lines...) Expand all
982 controller().LoadURL( 974 controller().LoadURL(
983 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 975 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
984 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 976 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
985 EXPECT_FALSE(contents()->cross_navigation_pending()); 977 EXPECT_FALSE(contents()->cross_navigation_pending());
986 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 978 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
987 979
988 // Navigate to new site, simulating an onbeforeunload approval. 980 // Navigate to new site, simulating an onbeforeunload approval.
989 const GURL url2("http://www.yahoo.com"); 981 const GURL url2("http://www.yahoo.com");
990 controller().LoadURL( 982 controller().LoadURL(
991 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 983 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
992 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 984 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
993 base::TimeTicks now = base::TimeTicks::Now(); 985 base::TimeTicks now = base::TimeTicks::Now();
994 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 986 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
995 EXPECT_TRUE(contents()->cross_navigation_pending()); 987 EXPECT_TRUE(contents()->cross_navigation_pending());
996 988
997 // Suppose the original renderer navigates before the new one is ready. 989 // Suppose the original renderer navigates before the new one is ready.
998 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); 990 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo"));
999 991
1000 // Verify that the pending navigation is cancelled. 992 // Verify that the pending navigation is cancelled.
1001 EXPECT_FALSE( 993 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1002 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
1003 SiteInstance* instance2 = contents()->GetSiteInstance(); 994 SiteInstance* instance2 = contents()->GetSiteInstance();
1004 EXPECT_FALSE(contents()->cross_navigation_pending()); 995 EXPECT_FALSE(contents()->cross_navigation_pending());
1005 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 996 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1006 EXPECT_EQ(instance1, instance2); 997 EXPECT_EQ(instance1, instance2);
1007 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 998 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1008 } 999 }
1009 1000
1010 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1001 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1011 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1002 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1012 const GURL url1("chrome://blah"); 1003 const GURL url1("chrome://blah");
(...skipping 13 matching lines...) Expand all
1026 BINDINGS_POLICY_WEB_UI); 1017 BINDINGS_POLICY_WEB_UI);
1027 1018
1028 // Navigate to new site. 1019 // Navigate to new site.
1029 const GURL url2("http://www.google.com"); 1020 const GURL url2("http://www.google.com");
1030 controller().LoadURL( 1021 controller().LoadURL(
1031 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1022 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1032 EXPECT_TRUE(contents()->cross_navigation_pending()); 1023 EXPECT_TRUE(contents()->cross_navigation_pending());
1033 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1024 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1034 1025
1035 // Simulate beforeunload approval. 1026 // Simulate beforeunload approval.
1036 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 1027 EXPECT_TRUE(ntp_rfh->is_waiting_for_beforeunload_ack());
1037 base::TimeTicks now = base::TimeTicks::Now(); 1028 base::TimeTicks now = base::TimeTicks::Now();
1038 ntp_rfh->OnMessageReceived( 1029 ntp_rfh->OnMessageReceived(
1039 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1030 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1040 1031
1041 // DidNavigate from the pending page. 1032 // DidNavigate from the pending page.
1042 contents()->TestDidNavigate( 1033 contents()->TestDidNavigate(
1043 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1034 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1044 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1035 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1045 SiteInstance* instance2 = contents()->GetSiteInstance(); 1036 SiteInstance* instance2 = contents()->GetSiteInstance();
1046 1037
(...skipping 30 matching lines...) Expand all
1077 EXPECT_FALSE(contents()->cross_navigation_pending()); 1068 EXPECT_FALSE(contents()->cross_navigation_pending());
1078 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1069 EXPECT_EQ(entry2, controller().GetPendingEntry());
1079 1070
1080 // Before that commits, go back again. 1071 // Before that commits, go back again.
1081 controller().GoBack(); 1072 controller().GoBack();
1082 EXPECT_TRUE(contents()->cross_navigation_pending()); 1073 EXPECT_TRUE(contents()->cross_navigation_pending());
1083 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1074 EXPECT_TRUE(contents()->GetPendingMainFrame());
1084 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1075 EXPECT_EQ(entry1, controller().GetPendingEntry());
1085 1076
1086 // Simulate beforeunload approval. 1077 // Simulate beforeunload approval.
1087 EXPECT_TRUE( 1078 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack());
1088 google_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
1089 now = base::TimeTicks::Now(); 1079 now = base::TimeTicks::Now();
1090 google_rfh->OnMessageReceived( 1080 google_rfh->OnMessageReceived(
1091 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1081 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1092 1082
1093 // DidNavigate from the first back. This aborts the second back's pending RFH. 1083 // DidNavigate from the first back. This aborts the second back's pending RFH.
1094 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1084 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1095 1085
1096 // We should commit this page and forget about the second back. 1086 // We should commit this page and forget about the second back.
1097 EXPECT_FALSE(contents()->cross_navigation_pending()); 1087 EXPECT_FALSE(contents()->cross_navigation_pending());
1098 EXPECT_FALSE(controller().GetPendingEntry()); 1088 EXPECT_FALSE(controller().GetPendingEntry());
(...skipping 26 matching lines...) Expand all
1125 // Start navigating to new site. 1115 // Start navigating to new site.
1126 const GURL url2("http://www.yahoo.com"); 1116 const GURL url2("http://www.yahoo.com");
1127 controller().LoadURL( 1117 controller().LoadURL(
1128 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1118 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1129 1119
1130 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1120 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1131 // waiting for a before unload response. 1121 // waiting for a before unload response.
1132 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1122 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1133 child_rfh->SendNavigateWithTransition( 1123 child_rfh->SendNavigateWithTransition(
1134 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1124 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1135 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 1125 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
1136 1126
1137 // Now simulate the onbeforeunload approval and verify the navigation is 1127 // Now simulate the onbeforeunload approval and verify the navigation is
1138 // not canceled. 1128 // not canceled.
1139 base::TimeTicks now = base::TimeTicks::Now(); 1129 base::TimeTicks now = base::TimeTicks::Now();
1140 orig_rfh->OnMessageReceived( 1130 orig_rfh->OnMessageReceived(
1141 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1131 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1142 EXPECT_FALSE( 1132 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1143 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
1144 EXPECT_TRUE(contents()->cross_navigation_pending()); 1133 EXPECT_TRUE(contents()->cross_navigation_pending());
1145 } 1134 }
1146 1135
1147 // Test that a cross-site navigation is not preempted if the previous 1136 // Test that a cross-site navigation is not preempted if the previous
1148 // renderer sends a FrameNavigate message just before being told to stop. 1137 // renderer sends a FrameNavigate message just before being told to stop.
1149 // We should only preempt the cross-site navigation if the previous renderer 1138 // We should only preempt the cross-site navigation if the previous renderer
1150 // has started a new navigation. See http://crbug.com/79176. 1139 // has started a new navigation. See http://crbug.com/79176.
1151 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1140 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1152 // Navigate to NTP URL. 1141 // Navigate to NTP URL.
1153 const GURL url("chrome://blah"); 1142 const GURL url("chrome://blah");
1154 controller().LoadURL( 1143 controller().LoadURL(
1155 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1144 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1156 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1145 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1157 EXPECT_FALSE(contents()->cross_navigation_pending()); 1146 EXPECT_FALSE(contents()->cross_navigation_pending());
1158 1147
1159 // Navigate to new site, with the beforeunload request in flight. 1148 // Navigate to new site, with the beforeunload request in flight.
1160 const GURL url2("http://www.yahoo.com"); 1149 const GURL url2("http://www.yahoo.com");
1161 controller().LoadURL( 1150 controller().LoadURL(
1162 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1151 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1163 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1152 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1164 EXPECT_TRUE(contents()->cross_navigation_pending()); 1153 EXPECT_TRUE(contents()->cross_navigation_pending());
1165 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 1154 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
1166 1155
1167 // Suppose the first navigation tries to commit now, with a 1156 // Suppose the first navigation tries to commit now, with a
1168 // FrameMsg_Stop in flight. This should not cancel the pending navigation, 1157 // FrameMsg_Stop in flight. This should not cancel the pending navigation,
1169 // but it should act as if the beforeunload ack arrived. 1158 // but it should act as if the beforeunload ack arrived.
1170 orig_rfh->SendNavigate(1, GURL("chrome://blah")); 1159 orig_rfh->SendNavigate(1, GURL("chrome://blah"));
1171 EXPECT_TRUE(contents()->cross_navigation_pending()); 1160 EXPECT_TRUE(contents()->cross_navigation_pending());
1172 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1161 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1173 EXPECT_FALSE( 1162 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1174 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
1175 1163
1176 // The pending navigation should be able to commit successfully. 1164 // The pending navigation should be able to commit successfully.
1177 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1165 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1178 EXPECT_FALSE(contents()->cross_navigation_pending()); 1166 EXPECT_FALSE(contents()->cross_navigation_pending());
1179 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1167 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1180 } 1168 }
1181 1169
1182 // Test that a cross-site navigation that doesn't commit after the unload 1170 // Test that a cross-site navigation that doesn't commit after the unload
1183 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 1171 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562
1184 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { 1172 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
1185 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1173 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1186 SiteInstance* instance1 = contents()->GetSiteInstance(); 1174 SiteInstance* instance1 = contents()->GetSiteInstance();
1187 1175
1188 // Navigate to URL. First URL should use original RenderFrameHost. 1176 // Navigate to URL. First URL should use original RenderFrameHost.
1189 const GURL url("http://www.google.com"); 1177 const GURL url("http://www.google.com");
1190 controller().LoadURL( 1178 controller().LoadURL(
1191 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1179 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1192 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1180 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1193 EXPECT_FALSE(contents()->cross_navigation_pending()); 1181 EXPECT_FALSE(contents()->cross_navigation_pending());
1194 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1182 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1195 1183
1196 // Navigate to new site, simulating an onbeforeunload approval. 1184 // Navigate to new site, simulating an onbeforeunload approval.
1197 const GURL url2("http://www.yahoo.com"); 1185 const GURL url2("http://www.yahoo.com");
1198 controller().LoadURL( 1186 controller().LoadURL(
1199 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1187 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1200 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); 1188 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
1201 base::TimeTicks now = base::TimeTicks::Now(); 1189 base::TimeTicks now = base::TimeTicks::Now();
1202 orig_rfh->OnMessageReceived( 1190 orig_rfh->OnMessageReceived(
1203 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1191 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1204 EXPECT_TRUE(contents()->cross_navigation_pending()); 1192 EXPECT_TRUE(contents()->cross_navigation_pending());
1205 1193
1206 // Simulate swap out message when the response arrives. 1194 // Simulate swap out message when the response arrives.
1207 orig_rfh->OnSwappedOut(false); 1195 orig_rfh->OnSwappedOut();
1208 1196
1209 // Suppose the navigation doesn't get a chance to commit, and the user 1197 // Suppose the navigation doesn't get a chance to commit, and the user
1210 // navigates in the current RFH's SiteInstance. 1198 // navigates in the current RFH's SiteInstance.
1211 controller().LoadURL( 1199 controller().LoadURL(
1212 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1200 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1213 1201
1214 // Verify that the pending navigation is cancelled and the renderer is no 1202 // Verify that the pending navigation is cancelled and the renderer is no
1215 // longer swapped out. 1203 // longer swapped out.
1216 EXPECT_FALSE( 1204 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1217 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack());
1218 SiteInstance* instance2 = contents()->GetSiteInstance(); 1205 SiteInstance* instance2 = contents()->GetSiteInstance();
1219 EXPECT_FALSE(contents()->cross_navigation_pending()); 1206 EXPECT_FALSE(contents()->cross_navigation_pending());
1220 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1207 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1221 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, 1208 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, orig_rfh->rfh_state());
1222 orig_rfh->GetRenderViewHost()->rvh_state());
1223 EXPECT_EQ(instance1, instance2); 1209 EXPECT_EQ(instance1, instance2);
1224 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1210 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1225 } 1211 }
1226 1212
1227 // Test that NavigationEntries have the correct page state after going 1213 // Test that NavigationEntries have the correct page state after going
1228 // forward and back. Prevents regression for bug 1116137. 1214 // forward and back. Prevents regression for bug 1116137.
1229 TEST_F(WebContentsImplTest, NavigationEntryContentState) { 1215 TEST_F(WebContentsImplTest, NavigationEntryContentState) {
1230 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1216 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1231 1217
1232 // Navigate to URL. There should be no committed entry yet. 1218 // Navigate to URL. There should be no committed entry yet.
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 2774
2789 // Destroy the video only player. No power save blockers should remain. 2775 // Destroy the video only player. No power save blockers should remain.
2790 rfh->OnMessageReceived( 2776 rfh->OnMessageReceived(
2791 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); 2777 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId));
2792 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2778 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2793 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2779 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2794 } 2780 }
2795 #endif 2781 #endif
2796 2782
2797 } // namespace content 2783 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/public/test/test_renderer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698