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

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

Issue 789643005: PlzNavigate: make content unit tests work with browser side navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cancel-navigations
Patch Set: Now addressing failures due to speculative RFH Created 5 years, 11 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { 475 TEST_F(WebContentsImplTest, CrossSiteBoundaries) {
476 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 476 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
477 int orig_rvh_delete_count = 0; 477 int orig_rvh_delete_count = 0;
478 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 478 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
479 SiteInstance* instance1 = contents()->GetSiteInstance(); 479 SiteInstance* instance1 = contents()->GetSiteInstance();
480 480
481 // Navigate to URL. First URL should use first RenderViewHost. 481 // Navigate to URL. First URL should use first RenderViewHost.
482 const GURL url("http://www.google.com"); 482 const GURL url("http://www.google.com");
483 controller().LoadURL( 483 controller().LoadURL(
484 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 484 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
485 orig_rfh->PrepareForCommit(url);
485 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 486 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
486 487
487 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 488 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
488 // that orig_rfh doesn't get deleted when it gets swapped out. 489 // that orig_rfh doesn't get deleted when it gets swapped out.
489 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 490 orig_rfh->GetSiteInstance()->increment_active_frame_count();
490 491
491 EXPECT_FALSE(contents()->cross_navigation_pending()); 492 EXPECT_FALSE(contents()->cross_navigation_pending());
492 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 493 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
493 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 494 EXPECT_EQ(url, contents()->GetLastCommittedURL());
494 EXPECT_EQ(url, contents()->GetVisibleURL()); 495 EXPECT_EQ(url, contents()->GetVisibleURL());
495 496
496 // Navigate to new site 497 // Navigate to new site
497 const GURL url2("http://www.yahoo.com"); 498 const GURL url2("http://www.yahoo.com");
498 controller().LoadURL( 499 controller().LoadURL(
499 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 500 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
501 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
502 switches::kEnableBrowserSideNavigation)) {
503 orig_rfh->PrepareForCommit(url2);
504 }
500 EXPECT_TRUE(contents()->cross_navigation_pending()); 505 EXPECT_TRUE(contents()->cross_navigation_pending());
501 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 506 EXPECT_EQ(url, contents()->GetLastCommittedURL());
502 EXPECT_EQ(url2, contents()->GetVisibleURL()); 507 EXPECT_EQ(url2, contents()->GetVisibleURL());
503 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 508 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
504 int pending_rvh_delete_count = 0; 509 int pending_rvh_delete_count = 0;
505 pending_rfh->GetRenderViewHost()->set_delete_counter( 510 pending_rfh->GetRenderViewHost()->set_delete_counter(
506 &pending_rvh_delete_count); 511 &pending_rvh_delete_count);
507 512
508 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 513 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
509 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 514 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
510 orig_rfh->SendBeforeUnloadACK(true); 515 switches::kEnableBrowserSideNavigation)) {
511 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 516 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
517 orig_rfh->SendBeforeUnloadACK(true);
518 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
519 }
512 520
513 // DidNavigate from the pending page 521 // DidNavigate from the pending page
514 contents()->TestDidNavigate( 522 contents()->TestDidNavigate(
515 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 523 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
516 SiteInstance* instance2 = contents()->GetSiteInstance(); 524 SiteInstance* instance2 = contents()->GetSiteInstance();
517 525
518 // Keep the number of active frames in pending_rfh's SiteInstance 526 // Keep the number of active frames in pending_rfh's SiteInstance
519 // non-zero so that orig_rfh doesn't get deleted when it gets 527 // non-zero so that orig_rfh doesn't get deleted when it gets
520 // swapped out. 528 // swapped out.
521 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 529 pending_rfh->GetSiteInstance()->increment_active_frame_count();
522 530
523 EXPECT_FALSE(contents()->cross_navigation_pending()); 531 EXPECT_FALSE(contents()->cross_navigation_pending());
524 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 532 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
525 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 533 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
526 EXPECT_EQ(url2, contents()->GetVisibleURL()); 534 EXPECT_EQ(url2, contents()->GetVisibleURL());
527 EXPECT_NE(instance1, instance2); 535 EXPECT_NE(instance1, instance2);
528 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 536 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
529 // We keep the original RFH around, swapped out. 537 // We keep the original RFH around, swapped out.
530 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 538 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
531 orig_rfh)); 539 orig_rfh));
532 EXPECT_EQ(orig_rvh_delete_count, 0); 540 EXPECT_EQ(orig_rvh_delete_count, 0);
533 541
534 // Going back should switch SiteInstances again. The first SiteInstance is 542 // Going back should switch SiteInstances again. The first SiteInstance is
535 // stored in the NavigationEntry, so it should be the same as at the start. 543 // stored in the NavigationEntry, so it should be the same as at the start.
536 // We should use the same RFH as before, swapping it back in. 544 // We should use the same RFH as before, swapping it back in.
537 controller().GoBack(); 545 controller().GoBack();
546 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
547 switches::kEnableBrowserSideNavigation)) {
548 contents()->GetMainFrame()->PrepareForCommit(url);
549 }
538 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 550 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
539 EXPECT_EQ(orig_rfh, goback_rfh); 551 EXPECT_EQ(orig_rfh, goback_rfh);
540 EXPECT_TRUE(contents()->cross_navigation_pending()); 552 EXPECT_TRUE(contents()->cross_navigation_pending());
541 553
542 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 554 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
543 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 555 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
544 pending_rfh->SendBeforeUnloadACK(true); 556 switches::kEnableBrowserSideNavigation)) {
545 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); 557 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
558 pending_rfh->SendBeforeUnloadACK(true);
559 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
560 }
546 561
547 // DidNavigate from the back action 562 // DidNavigate from the back action
548 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 563 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
549 EXPECT_FALSE(contents()->cross_navigation_pending()); 564 EXPECT_FALSE(contents()->cross_navigation_pending());
550 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); 565 EXPECT_EQ(goback_rfh, contents()->GetMainFrame());
551 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 566 EXPECT_EQ(instance1, contents()->GetSiteInstance());
552 // The pending RFH should now be swapped out, not deleted. 567 // The pending RFH should now be swapped out, not deleted.
553 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 568 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
554 IsOnSwappedOutList(pending_rfh)); 569 IsOnSwappedOutList(pending_rfh));
555 EXPECT_EQ(pending_rvh_delete_count, 0); 570 EXPECT_EQ(pending_rvh_delete_count, 0);
(...skipping 11 matching lines...) Expand all
567 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 582 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
568 583
569 int orig_rvh_delete_count = 0; 584 int orig_rvh_delete_count = 0;
570 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 585 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
571 SiteInstance* instance1 = contents()->GetSiteInstance(); 586 SiteInstance* instance1 = contents()->GetSiteInstance();
572 587
573 // Navigate to URL. First URL should use first RenderViewHost. 588 // Navigate to URL. First URL should use first RenderViewHost.
574 const GURL url("http://www.google.com"); 589 const GURL url("http://www.google.com");
575 controller().LoadURL( 590 controller().LoadURL(
576 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 591 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
592 contents()->GetMainFrame()->PrepareForCommit(url);
577 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 593 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
578 594
579 EXPECT_FALSE(contents()->cross_navigation_pending()); 595 EXPECT_FALSE(contents()->cross_navigation_pending());
580 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 596 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
581 597
582 // Simulate a renderer crash. 598 // Simulate a renderer crash.
583 orig_rfh->GetRenderViewHost()->set_render_view_created(false); 599 orig_rfh->GetRenderViewHost()->set_render_view_created(false);
584 orig_rfh->set_render_frame_created(false); 600 orig_rfh->set_render_frame_created(false);
585 601
586 // Navigate to new site. We should not go into PENDING. 602 // Navigate to new site. We should not go into PENDING.
587 const GURL url2("http://www.yahoo.com"); 603 const GURL url2("http://www.yahoo.com");
588 controller().LoadURL( 604 controller().LoadURL(
589 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 605 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
606 contents()->GetMainFrame()->PrepareForCommit(url2);
590 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); 607 TestRenderFrameHost* new_rfh = contents()->GetMainFrame();
591 EXPECT_FALSE(contents()->cross_navigation_pending()); 608 EXPECT_FALSE(contents()->cross_navigation_pending());
592 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 609 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
593 EXPECT_NE(orig_rfh, new_rfh); 610 EXPECT_NE(orig_rfh, new_rfh);
594 EXPECT_EQ(orig_rvh_delete_count, 1); 611 EXPECT_EQ(orig_rvh_delete_count, 1);
595 612
596 // DidNavigate from the new page 613 // DidNavigate from the new page
597 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 614 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
598 SiteInstance* instance2 = contents()->GetSiteInstance(); 615 SiteInstance* instance2 = contents()->GetSiteInstance();
599 616
(...skipping 11 matching lines...) Expand all
611 // both contentses to a new site will place both contentses in a single 628 // both contentses to a new site will place both contentses in a single
612 // SiteInstance. 629 // SiteInstance.
613 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { 630 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) {
614 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 631 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
615 SiteInstance* instance1 = contents()->GetSiteInstance(); 632 SiteInstance* instance1 = contents()->GetSiteInstance();
616 633
617 // Navigate to URL. First URL should use first RenderViewHost. 634 // Navigate to URL. First URL should use first RenderViewHost.
618 const GURL url("http://www.google.com"); 635 const GURL url("http://www.google.com");
619 controller().LoadURL( 636 controller().LoadURL(
620 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 637 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
638 contents()->GetMainFrame()->PrepareForCommit(url);
621 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 639 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
622 640
623 // Open a new contents with the same SiteInstance, navigated to the same site. 641 // Open a new contents with the same SiteInstance, navigated to the same site.
624 scoped_ptr<TestWebContents> contents2( 642 scoped_ptr<TestWebContents> contents2(
625 TestWebContents::Create(browser_context(), instance1)); 643 TestWebContents::Create(browser_context(), instance1));
626 contents2->GetController().LoadURL(url, Referrer(), 644 contents2->GetController().LoadURL(url, Referrer(),
627 ui::PAGE_TRANSITION_TYPED, 645 ui::PAGE_TRANSITION_TYPED,
628 std::string()); 646 std::string());
647 contents2->GetMainFrame()->PrepareForCommit(url);
629 // Need this page id to be 2 since the site instance is the same (which is the 648 // Need this page id to be 2 since the site instance is the same (which is the
630 // scope of page IDs) and we want to consider this a new page. 649 // scope of page IDs) and we want to consider this a new page.
631 contents2->TestDidNavigate( 650 contents2->TestDidNavigate(
632 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 651 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
633 652
634 // Navigate first contents to a new site. 653 // Navigate first contents to a new site.
635 const GURL url2a("http://www.yahoo.com"); 654 const GURL url2a("http://www.yahoo.com");
636 controller().LoadURL( 655 controller().LoadURL(
637 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 656 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
638 orig_rfh->SendBeforeUnloadACK(true); 657 orig_rfh->PrepareForCommit(url2a);
639 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); 658 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame();
640 contents()->TestDidNavigate( 659 contents()->TestDidNavigate(
641 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); 660 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED);
642 SiteInstance* instance2a = contents()->GetSiteInstance(); 661 SiteInstance* instance2a = contents()->GetSiteInstance();
643 EXPECT_NE(instance1, instance2a); 662 EXPECT_NE(instance1, instance2a);
644 663
645 // Navigate second contents to the same site as the first tab. 664 // Navigate second contents to the same site as the first tab.
646 const GURL url2b("http://mail.yahoo.com"); 665 const GURL url2b("http://mail.yahoo.com");
647 contents2->GetController().LoadURL(url2b, Referrer(), 666 contents2->GetController().LoadURL(url2b, Referrer(),
648 ui::PAGE_TRANSITION_TYPED, 667 ui::PAGE_TRANSITION_TYPED,
649 std::string()); 668 std::string());
650 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 669 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
651 rfh2->SendBeforeUnloadACK(true); 670 rfh2->PrepareForCommit(url2b);
652 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); 671 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame();
653 EXPECT_TRUE(pending_rfh_b != NULL); 672 EXPECT_TRUE(pending_rfh_b != NULL);
654 EXPECT_TRUE(contents2->cross_navigation_pending()); 673 EXPECT_TRUE(contents2->cross_navigation_pending());
655 674
656 // NOTE(creis): We used to be in danger of showing a crash page here if the 675 // NOTE(creis): We used to be in danger of showing a crash page here if the
657 // second contents hadn't navigated somewhere first (bug 1145430). That case 676 // second contents hadn't navigated somewhere first (bug 1145430). That case
658 // is now covered by the CrossSiteBoundariesAfterCrash test. 677 // is now covered by the CrossSiteBoundariesAfterCrash test.
659 contents2->TestDidNavigate( 678 contents2->TestDidNavigate(
660 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); 679 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED);
661 SiteInstance* instance2b = contents2->GetSiteInstance(); 680 SiteInstance* instance2b = contents2->GetSiteInstance();
(...skipping 14 matching lines...) Expand all
676 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 695 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
677 int orig_rvh_delete_count = 0; 696 int orig_rvh_delete_count = 0;
678 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 697 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
679 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); 698 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
680 699
681 browser_client.set_assign_site_for_url(false); 700 browser_client.set_assign_site_for_url(false);
682 // Navigate to an URL that will not assign a new SiteInstance. 701 // Navigate to an URL that will not assign a new SiteInstance.
683 const GURL native_url("non-site-url://stuffandthings"); 702 const GURL native_url("non-site-url://stuffandthings");
684 controller().LoadURL( 703 controller().LoadURL(
685 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 704 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
705 contents()->GetMainFrame()->PrepareForCommit(native_url);
686 contents()->TestDidNavigate( 706 contents()->TestDidNavigate(
687 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); 707 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED);
688 708
689 EXPECT_FALSE(contents()->cross_navigation_pending()); 709 EXPECT_FALSE(contents()->cross_navigation_pending());
690 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 710 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
691 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 711 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
692 EXPECT_EQ(native_url, contents()->GetVisibleURL()); 712 EXPECT_EQ(native_url, contents()->GetVisibleURL());
693 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 713 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
694 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 714 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
695 EXPECT_FALSE(orig_instance->HasSite()); 715 EXPECT_FALSE(orig_instance->HasSite());
696 716
697 browser_client.set_assign_site_for_url(true); 717 browser_client.set_assign_site_for_url(true);
698 // Navigate to new site (should keep same site instance). 718 // Navigate to new site (should keep same site instance).
699 const GURL url("http://www.google.com"); 719 const GURL url("http://www.google.com");
700 controller().LoadURL( 720 controller().LoadURL(
701 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 721 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
722 contents()->GetMainFrame()->PrepareForCommit(url);
702 EXPECT_FALSE(contents()->cross_navigation_pending()); 723 EXPECT_FALSE(contents()->cross_navigation_pending());
703 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 724 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
704 EXPECT_EQ(url, contents()->GetVisibleURL()); 725 EXPECT_EQ(url, contents()->GetVisibleURL());
705 EXPECT_FALSE(contents()->GetPendingMainFrame()); 726 EXPECT_FALSE(contents()->GetPendingMainFrame());
706 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 727 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
707 728
708 // Keep the number of active frames in orig_rfh's SiteInstance 729 // Keep the number of active frames in orig_rfh's SiteInstance
709 // non-zero so that orig_rfh doesn't get deleted when it gets 730 // non-zero so that orig_rfh doesn't get deleted when it gets
710 // swapped out. 731 // swapped out.
711 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 732 orig_rfh->GetSiteInstance()->increment_active_frame_count();
712 733
713 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 734 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
714 EXPECT_TRUE( 735 EXPECT_TRUE(
715 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 736 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
716 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 737 EXPECT_EQ(url, contents()->GetLastCommittedURL());
717 738
718 // Navigate to another new site (should create a new site instance). 739 // Navigate to another new site (should create a new site instance).
719 const GURL url2("http://www.yahoo.com"); 740 const GURL url2("http://www.yahoo.com");
720 controller().LoadURL( 741 controller().LoadURL(
721 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 742 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
743 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
744 switches::kEnableBrowserSideNavigation)) {
745 orig_rfh->PrepareForCommit(url2);
746 }
722 EXPECT_TRUE(contents()->cross_navigation_pending()); 747 EXPECT_TRUE(contents()->cross_navigation_pending());
723 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 748 EXPECT_EQ(url, contents()->GetLastCommittedURL());
724 EXPECT_EQ(url2, contents()->GetVisibleURL()); 749 EXPECT_EQ(url2, contents()->GetVisibleURL());
725 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 750 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
726 int pending_rvh_delete_count = 0; 751 int pending_rvh_delete_count = 0;
727 pending_rfh->GetRenderViewHost()->set_delete_counter( 752 pending_rfh->GetRenderViewHost()->set_delete_counter(
728 &pending_rvh_delete_count); 753 &pending_rvh_delete_count);
729 754
730 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 755 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
731 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 756 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
732 orig_rfh->SendBeforeUnloadACK(true); 757 switches::kEnableBrowserSideNavigation)) {
733 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 758 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
759 orig_rfh->SendBeforeUnloadACK(true);
760 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
761 }
734 762
735 // DidNavigate from the pending page. 763 // DidNavigate from the pending page.
736 contents()->TestDidNavigate( 764 contents()->TestDidNavigate(
737 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 765 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
738 SiteInstance* new_instance = contents()->GetSiteInstance(); 766 SiteInstance* new_instance = contents()->GetSiteInstance();
739 767
740 EXPECT_FALSE(contents()->cross_navigation_pending()); 768 EXPECT_FALSE(contents()->cross_navigation_pending());
741 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 769 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
742 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 770 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
743 EXPECT_EQ(url2, contents()->GetVisibleURL()); 771 EXPECT_EQ(url2, contents()->GetVisibleURL());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 browser_context()); 845 browser_context());
818 entry->SetPageID(0); 846 entry->SetPageID(0);
819 entries.push_back(entry); 847 entries.push_back(entry);
820 controller().Restore( 848 controller().Restore(
821 0, 849 0,
822 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 850 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
823 &entries); 851 &entries);
824 ASSERT_EQ(0u, entries.size()); 852 ASSERT_EQ(0u, entries.size());
825 ASSERT_EQ(1, controller().GetEntryCount()); 853 ASSERT_EQ(1, controller().GetEntryCount());
826 controller().GoToIndex(0); 854 controller().GoToIndex(0);
855 orig_rfh->PrepareForCommit(regular_url);
827 contents()->TestDidNavigate( 856 contents()->TestDidNavigate(
828 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD); 857 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD);
829 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 858 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
830 EXPECT_TRUE(orig_instance->HasSite()); 859 EXPECT_TRUE(orig_instance->HasSite());
831 860
832 // Navigate to another site and verify that a new SiteInstance was created. 861 // Navigate to another site and verify that a new SiteInstance was created.
833 const GURL url("http://www.google.com"); 862 const GURL url("http://www.google.com");
834 controller().LoadURL( 863 controller().LoadURL(
835 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 864 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
865 orig_rfh->PrepareForCommit(url);
836 contents()->TestDidNavigate( 866 contents()->TestDidNavigate(
837 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 867 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
838 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); 868 EXPECT_NE(orig_instance, contents()->GetSiteInstance());
839 869
840 // Cleanup. 870 // Cleanup.
841 DeleteContents(); 871 DeleteContents();
842 } 872 }
843 873
844 // Test that we can find an opener RVH even if it's pending. 874 // Test that we can find an opener RVH even if it's pending.
845 // http://crbug.com/176252. 875 // http://crbug.com/176252.
846 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { 876 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) {
847 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 877 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
848 878
849 // Navigate to a URL. 879 // Navigate to a URL.
850 const GURL url("http://www.google.com"); 880 const GURL url("http://www.google.com");
851 controller().LoadURL( 881 controller().LoadURL(
852 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 882 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
883 orig_rfh->PrepareForCommit(url);
853 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 884 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
854 885
855 // Start to navigate first tab to a new site, so that it has a pending RVH. 886 // Start to navigate first tab to a new site, so that it has a pending RVH.
856 const GURL url2("http://www.yahoo.com"); 887 const GURL url2("http://www.yahoo.com");
857 controller().LoadURL( 888 controller().LoadURL(
858 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 889 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
859 orig_rfh->SendBeforeUnloadACK(true); 890 orig_rfh->PrepareForCommit(url2);
860 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 891 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
861 892
862 // While it is still pending, simulate opening a new tab with the first tab 893 // While it is still pending, simulate opening a new tab with the first tab
863 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews 894 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews
864 // on the opener to ensure that an RVH exists. 895 // on the opener to ensure that an RVH exists.
865 int opener_routing_id = 896 int opener_routing_id =
866 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); 897 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance());
867 898
868 // We should find the pending RVH and not create a new one. 899 // We should find the pending RVH and not create a new one.
869 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), 900 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(),
870 opener_routing_id); 901 opener_routing_id);
871 } 902 }
872 903
873 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, 904 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site,
874 // to determine whether a navigation is cross-site. 905 // to determine whether a navigation is cross-site.
875 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { 906 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) {
876 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 907 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
877 SiteInstance* instance1 = contents()->GetSiteInstance(); 908 SiteInstance* instance1 = contents()->GetSiteInstance();
878 909
879 // Navigate to URL. 910 // Navigate to URL.
880 const GURL url("http://www.google.com"); 911 const GURL url("http://www.google.com");
881 controller().LoadURL( 912 controller().LoadURL(
882 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 913 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
914 contents()->GetMainFrame()->PrepareForCommit(url);
883 contents()->TestDidNavigate( 915 contents()->TestDidNavigate(
884 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 916 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
885 917
886 // Open a related contents to a second site. 918 // Open a related contents to a second site.
887 scoped_ptr<TestWebContents> contents2( 919 scoped_ptr<TestWebContents> contents2(
888 TestWebContents::Create(browser_context(), instance1)); 920 TestWebContents::Create(browser_context(), instance1));
889 const GURL url2("http://www.yahoo.com"); 921 const GURL url2("http://www.yahoo.com");
890 contents2->GetController().LoadURL(url2, Referrer(), 922 contents2->GetController().LoadURL(url2, Referrer(),
891 ui::PAGE_TRANSITION_TYPED, 923 ui::PAGE_TRANSITION_TYPED,
892 std::string()); 924 std::string());
925 contents2->GetMainFrame()->PrepareForCommit(url2);
893 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 926 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
894 // pending. 927 // pending.
895 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 928 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
896 EXPECT_FALSE(contents2->cross_navigation_pending()); 929 EXPECT_FALSE(contents2->cross_navigation_pending());
897 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED); 930 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED);
898 SiteInstance* instance2 = contents2->GetSiteInstance(); 931 SiteInstance* instance2 = contents2->GetSiteInstance();
899 EXPECT_NE(instance1, instance2); 932 EXPECT_NE(instance1, instance2);
900 EXPECT_FALSE(contents2->cross_navigation_pending()); 933 EXPECT_FALSE(contents2->cross_navigation_pending());
901 934
902 // Simulate a link click in first contents to second site. Doesn't switch 935 // Simulate a link click in first contents to second site. Doesn't switch
903 // SiteInstances, because we don't intercept WebKit navigations. 936 // SiteInstances, because we don't intercept WebKit navigations.
904 contents()->TestDidNavigate( 937 contents()->TestDidNavigate(
905 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 938 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED);
906 SiteInstance* instance3 = contents()->GetSiteInstance(); 939 SiteInstance* instance3 = contents()->GetSiteInstance();
907 EXPECT_EQ(instance1, instance3); 940 EXPECT_EQ(instance1, instance3);
908 EXPECT_FALSE(contents()->cross_navigation_pending()); 941 EXPECT_FALSE(contents()->cross_navigation_pending());
909 942
910 // Navigate to the new site. Doesn't switch SiteInstancees, because we 943 // Navigate to the new site. Doesn't switch SiteInstancees, because we
911 // compare against the current URL, not the SiteInstance's site. 944 // compare against the current URL, not the SiteInstance's site.
912 const GURL url3("http://mail.yahoo.com"); 945 const GURL url3("http://mail.yahoo.com");
913 controller().LoadURL( 946 controller().LoadURL(
914 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 947 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
915 EXPECT_FALSE(contents()->cross_navigation_pending()); 948 EXPECT_FALSE(contents()->cross_navigation_pending());
949 contents()->GetMainFrame()->PrepareForCommit(url3);
916 contents()->TestDidNavigate( 950 contents()->TestDidNavigate(
917 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); 951 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED);
918 SiteInstance* instance4 = contents()->GetSiteInstance(); 952 SiteInstance* instance4 = contents()->GetSiteInstance();
919 EXPECT_EQ(instance1, instance4); 953 EXPECT_EQ(instance1, instance4);
920 } 954 }
921 955
922 // Test that the onbeforeunload and onunload handlers run when navigating 956 // Test that the onbeforeunload and onunload handlers run when navigating
923 // across site boundaries. 957 // across site boundaries.
924 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 958 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
925 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 959 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
926 SiteInstance* instance1 = contents()->GetSiteInstance(); 960 SiteInstance* instance1 = contents()->GetSiteInstance();
927 961
928 // Navigate to URL. First URL should use first RenderViewHost. 962 // Navigate to URL. First URL should use first RenderViewHost.
929 const GURL url("http://www.google.com"); 963 const GURL url("http://www.google.com");
930 controller().LoadURL( 964 controller().LoadURL(
931 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 965 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
966 contents()->GetMainFrame()->PrepareForCommit(url);
932 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 967 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
933 EXPECT_FALSE(contents()->cross_navigation_pending()); 968 EXPECT_FALSE(contents()->cross_navigation_pending());
934 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 969 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
935 970
936 // Navigate to new site, but simulate an onbeforeunload denial. 971 // Navigate to new site, but simulate an onbeforeunload denial.
937 const GURL url2("http://www.yahoo.com"); 972 const GURL url2("http://www.yahoo.com");
938 controller().LoadURL( 973 controller().LoadURL(
939 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 974 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
940 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 975 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
941 base::TimeTicks now = base::TimeTicks::Now(); 976 base::TimeTicks now = base::TimeTicks::Now();
942 orig_rfh->OnMessageReceived( 977 orig_rfh->OnMessageReceived(
943 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 978 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
944 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 979 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
945 EXPECT_FALSE(contents()->cross_navigation_pending()); 980 EXPECT_FALSE(contents()->cross_navigation_pending());
946 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 981 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
947 982
948 // Navigate again, but simulate an onbeforeunload approval. 983 // Navigate again, but simulate an onbeforeunload approval.
949 controller().LoadURL( 984 controller().LoadURL(
950 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 985 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
951 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 986 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
952 now = base::TimeTicks::Now(); 987 now = base::TimeTicks::Now();
953 orig_rfh->OnMessageReceived( 988 orig_rfh->PrepareForCommit(url2);
954 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 989 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
955 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
956 EXPECT_TRUE(contents()->cross_navigation_pending()); 990 EXPECT_TRUE(contents()->cross_navigation_pending());
957 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 991 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
958 992
959 // We won't hear DidNavigate until the onunload handler has finished running. 993 // We won't hear DidNavigate until the onunload handler has finished running.
960 994
961 // DidNavigate from the pending page. 995 // DidNavigate from the pending page.
962 contents()->TestDidNavigate( 996 contents()->TestDidNavigate(
963 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 997 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
964 SiteInstance* instance2 = contents()->GetSiteInstance(); 998 SiteInstance* instance2 = contents()->GetSiteInstance();
965 EXPECT_FALSE(contents()->cross_navigation_pending()); 999 EXPECT_FALSE(contents()->cross_navigation_pending());
966 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1000 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
967 EXPECT_NE(instance1, instance2); 1001 EXPECT_NE(instance1, instance2);
968 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1002 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
969 } 1003 }
970 1004
971 // Test that during a slow cross-site navigation, the original renderer can 1005 // Test that during a slow cross-site navigation, the original renderer can
972 // navigate to a different URL and have it displayed, canceling the slow 1006 // navigate to a different URL and have it displayed, canceling the slow
973 // navigation. 1007 // navigation.
974 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { 1008 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) {
975 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1009 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
976 SiteInstance* instance1 = contents()->GetSiteInstance(); 1010 SiteInstance* instance1 = contents()->GetSiteInstance();
977 1011
978 // Navigate to URL. First URL should use first RenderFrameHost. 1012 // Navigate to URL. First URL should use first RenderFrameHost.
979 const GURL url("http://www.google.com"); 1013 const GURL url("http://www.google.com");
980 controller().LoadURL( 1014 controller().LoadURL(
981 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1015 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1016 contents()->GetMainFrame()->PrepareForCommit(url);
982 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1017 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
983 EXPECT_FALSE(contents()->cross_navigation_pending()); 1018 EXPECT_FALSE(contents()->cross_navigation_pending());
984 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1019 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
985 1020
986 // Navigate to new site, simulating an onbeforeunload approval. 1021 // Navigate to new site, simulating an onbeforeunload approval.
987 const GURL url2("http://www.yahoo.com"); 1022 const GURL url2("http://www.yahoo.com");
988 controller().LoadURL( 1023 controller().LoadURL(
989 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1024 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
990 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1025 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
991 base::TimeTicks now = base::TimeTicks::Now(); 1026 orig_rfh->PrepareForCommit(url2);
992 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
993 EXPECT_TRUE(contents()->cross_navigation_pending()); 1027 EXPECT_TRUE(contents()->cross_navigation_pending());
994 1028
995 // Suppose the original renderer navigates before the new one is ready. 1029 // Suppose the original renderer navigates before the new one is ready.
996 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); 1030 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo"));
997 1031
998 // Verify that the pending navigation is cancelled. 1032 // Verify that the pending navigation is cancelled.
999 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1033 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1000 SiteInstance* instance2 = contents()->GetSiteInstance(); 1034 SiteInstance* instance2 = contents()->GetSiteInstance();
1001 EXPECT_FALSE(contents()->cross_navigation_pending()); 1035 EXPECT_FALSE(contents()->cross_navigation_pending());
1002 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1036 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1003 EXPECT_EQ(instance1, instance2); 1037 EXPECT_EQ(instance1, instance2);
1004 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1038 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1005 } 1039 }
1006 1040
1007 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1041 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1008 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1042 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1009 const GURL url1("chrome://blah"); 1043 const GURL url1("chrome://blah");
1010 controller().LoadURL( 1044 controller().LoadURL(
1011 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1045 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1012 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 1046 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
1047 ntp_rfh->PrepareForCommit(url1);
1013 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); 1048 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED);
1014 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1049 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1015 SiteInstance* instance1 = contents()->GetSiteInstance(); 1050 SiteInstance* instance1 = contents()->GetSiteInstance();
1016 1051
1017 EXPECT_FALSE(contents()->cross_navigation_pending()); 1052 EXPECT_FALSE(contents()->cross_navigation_pending());
1018 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1053 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
1019 EXPECT_EQ(url1, entry1->GetURL()); 1054 EXPECT_EQ(url1, entry1->GetURL());
1020 EXPECT_EQ(instance1, 1055 EXPECT_EQ(instance1,
1021 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1056 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1022 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & 1057 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() &
1023 BINDINGS_POLICY_WEB_UI); 1058 BINDINGS_POLICY_WEB_UI);
1024 1059
1025 // Navigate to new site. 1060 // Navigate to new site.
1026 const GURL url2("http://www.google.com"); 1061 const GURL url2("http://www.google.com");
1027 controller().LoadURL( 1062 controller().LoadURL(
1028 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1063 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1029 EXPECT_TRUE(contents()->cross_navigation_pending()); 1064 EXPECT_TRUE(contents()->cross_navigation_pending());
1030 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1065 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1031 1066
1032 // Simulate beforeunload approval. 1067 // Simulate beforeunload approval.
1033 EXPECT_TRUE(ntp_rfh->is_waiting_for_beforeunload_ack()); 1068 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK());
1034 base::TimeTicks now = base::TimeTicks::Now(); 1069 base::TimeTicks now = base::TimeTicks::Now();
1035 ntp_rfh->OnMessageReceived( 1070 ntp_rfh->PrepareForCommit(url2);
1036 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1037 1071
1038 // DidNavigate from the pending page. 1072 // DidNavigate from the pending page.
1039 contents()->TestDidNavigate( 1073 contents()->TestDidNavigate(
1040 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1074 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1041 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1075 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1042 SiteInstance* instance2 = contents()->GetSiteInstance(); 1076 SiteInstance* instance2 = contents()->GetSiteInstance();
1043 1077
1044 EXPECT_FALSE(contents()->cross_navigation_pending()); 1078 EXPECT_FALSE(contents()->cross_navigation_pending());
1045 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1079 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1046 EXPECT_NE(instance1, instance2); 1080 EXPECT_NE(instance1, instance2);
1047 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1081 EXPECT_FALSE(contents()->GetPendingMainFrame());
1048 EXPECT_EQ(url2, entry2->GetURL()); 1082 EXPECT_EQ(url2, entry2->GetURL());
1049 EXPECT_EQ(instance2, 1083 EXPECT_EQ(instance2,
1050 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1084 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1051 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1085 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1052 BINDINGS_POLICY_WEB_UI); 1086 BINDINGS_POLICY_WEB_UI);
1053 1087
1054 // Navigate to third page on same site. 1088 // Navigate to third page on same site.
1055 const GURL url3("http://news.google.com"); 1089 const GURL url3("http://news.google.com");
1056 controller().LoadURL( 1090 controller().LoadURL(
1057 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1091 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1058 EXPECT_FALSE(contents()->cross_navigation_pending()); 1092 EXPECT_FALSE(contents()->cross_navigation_pending());
1093 contents()->GetMainFrame()->PrepareForCommit(url3);
1059 contents()->TestDidNavigate( 1094 contents()->TestDidNavigate(
1060 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED); 1095 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED);
1061 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1096 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1062 SiteInstance* instance3 = contents()->GetSiteInstance(); 1097 SiteInstance* instance3 = contents()->GetSiteInstance();
1063 1098
1064 EXPECT_FALSE(contents()->cross_navigation_pending()); 1099 EXPECT_FALSE(contents()->cross_navigation_pending());
1065 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1100 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1066 EXPECT_EQ(instance2, instance3); 1101 EXPECT_EQ(instance2, instance3);
1067 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1102 EXPECT_FALSE(contents()->GetPendingMainFrame());
1068 EXPECT_EQ(url3, entry3->GetURL()); 1103 EXPECT_EQ(url3, entry3->GetURL());
1069 EXPECT_EQ(instance3, 1104 EXPECT_EQ(instance3,
1070 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1105 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1071 1106
1072 // Go back within the site. 1107 // Go back within the site.
1073 controller().GoBack(); 1108 controller().GoBack();
1074 EXPECT_FALSE(contents()->cross_navigation_pending()); 1109 EXPECT_FALSE(contents()->cross_navigation_pending());
1075 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1110 EXPECT_EQ(entry2, controller().GetPendingEntry());
1076 1111
1077 // Before that commits, go back again. 1112 // Before that commits, go back again.
1078 controller().GoBack(); 1113 controller().GoBack();
1079 EXPECT_TRUE(contents()->cross_navigation_pending()); 1114 EXPECT_TRUE(contents()->cross_navigation_pending());
1080 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1115 EXPECT_TRUE(contents()->GetPendingMainFrame());
1081 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1116 EXPECT_EQ(entry1, controller().GetPendingEntry());
1082 1117
1083 // Simulate beforeunload approval. 1118 // Simulate beforeunload approval.
1084 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); 1119 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK());
1085 now = base::TimeTicks::Now(); 1120 now = base::TimeTicks::Now();
1121 google_rfh->PrepareForCommit(url2);
1086 google_rfh->OnMessageReceived( 1122 google_rfh->OnMessageReceived(
1087 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1123 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1088 1124
1089 // DidNavigate from the first back. This aborts the second back's pending RFH. 1125 // DidNavigate from the first back. This aborts the second back's pending RFH.
1090 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1126 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1091 1127
1092 // We should commit this page and forget about the second back. 1128 // We should commit this page and forget about the second back.
1093 EXPECT_FALSE(contents()->cross_navigation_pending()); 1129 EXPECT_FALSE(contents()->cross_navigation_pending());
1094 EXPECT_FALSE(controller().GetPendingEntry()); 1130 EXPECT_FALSE(controller().GetPendingEntry());
1095 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1131 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
(...skipping 11 matching lines...) Expand all
1107 1143
1108 // Test that during a slow cross-site navigation, a sub-frame navigation in the 1144 // Test that during a slow cross-site navigation, a sub-frame navigation in the
1109 // original renderer will not cancel the slow navigation (bug 42029). 1145 // original renderer will not cancel the slow navigation (bug 42029).
1110 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { 1146 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) {
1111 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1147 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1112 1148
1113 // Navigate to URL. First URL should use the original RenderFrameHost. 1149 // Navigate to URL. First URL should use the original RenderFrameHost.
1114 const GURL url("http://www.google.com"); 1150 const GURL url("http://www.google.com");
1115 controller().LoadURL( 1151 controller().LoadURL(
1116 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1152 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1153 contents()->GetMainFrame()->PrepareForCommit(url);
1117 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1154 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1118 EXPECT_FALSE(contents()->cross_navigation_pending()); 1155 EXPECT_FALSE(contents()->cross_navigation_pending());
1119 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1156 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1120 1157
1121 // Start navigating to new site. 1158 // Start navigating to new site.
1122 const GURL url2("http://www.yahoo.com"); 1159 const GURL url2("http://www.yahoo.com");
1123 controller().LoadURL( 1160 controller().LoadURL(
1124 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1161 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1125 1162
1126 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1163 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1127 // waiting for a before unload response. 1164 // waiting for a before unload response.
1128 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1165 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1129 child_rfh->SendNavigateWithTransition( 1166 child_rfh->SendNavigateWithTransition(
1130 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1167 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1131 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1168 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1132 1169
1133 // Now simulate the onbeforeunload approval and verify the navigation is 1170 // Now simulate the onbeforeunload approval and verify the navigation is
1134 // not canceled. 1171 // not canceled.
1135 base::TimeTicks now = base::TimeTicks::Now(); 1172 orig_rfh->PrepareForCommit(url2);
1136 orig_rfh->OnMessageReceived( 1173 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1137 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1138 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1139 EXPECT_TRUE(contents()->cross_navigation_pending()); 1174 EXPECT_TRUE(contents()->cross_navigation_pending());
1140 } 1175 }
1141 1176
1142 // Test that a cross-site navigation is not preempted if the previous 1177 // Test that a cross-site navigation is not preempted if the previous
1143 // renderer sends a FrameNavigate message just before being told to stop. 1178 // renderer sends a FrameNavigate message just before being told to stop.
1144 // We should only preempt the cross-site navigation if the previous renderer 1179 // We should only preempt the cross-site navigation if the previous renderer
1145 // has started a new navigation. See http://crbug.com/79176. 1180 // has started a new navigation. See http://crbug.com/79176.
1146 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1181 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1147 // Navigate to NTP URL. 1182 // Navigate to NTP URL.
1148 const GURL url("chrome://blah"); 1183 const GURL url("chrome://blah");
1149 controller().LoadURL( 1184 controller().LoadURL(
1150 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1185 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1151 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1186 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1152 EXPECT_FALSE(contents()->cross_navigation_pending()); 1187 EXPECT_FALSE(contents()->cross_navigation_pending());
1153 1188
1154 // Navigate to new site, with the beforeunload request in flight. 1189 // Navigate to new site, with the beforeunload request in flight.
1155 const GURL url2("http://www.yahoo.com"); 1190 const GURL url2("http://www.yahoo.com");
1156 controller().LoadURL( 1191 controller().LoadURL(
1157 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1192 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1158 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1193 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1159 EXPECT_TRUE(contents()->cross_navigation_pending()); 1194 EXPECT_TRUE(contents()->cross_navigation_pending());
1160 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1195 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1161 1196
1162 // Suppose the first navigation tries to commit now, with a 1197 // Suppose the first navigation tries to commit now, with a
1163 // FrameMsg_Stop in flight. This should not cancel the pending navigation, 1198 // FrameMsg_Stop in flight. This should not cancel the pending navigation,
1164 // but it should act as if the beforeunload ack arrived. 1199 // but it should act as if the beforeunload ack arrived.
1165 orig_rfh->SendNavigate(1, GURL("chrome://blah")); 1200 orig_rfh->SendNavigate(1, GURL("chrome://blah"));
1166 EXPECT_TRUE(contents()->cross_navigation_pending()); 1201 EXPECT_TRUE(contents()->cross_navigation_pending());
1167 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1202 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1168 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1203 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1169 1204
1170 // The pending navigation should be able to commit successfully. 1205 // The pending navigation should be able to commit successfully.
1171 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1206 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1172 EXPECT_FALSE(contents()->cross_navigation_pending()); 1207 EXPECT_FALSE(contents()->cross_navigation_pending());
1173 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1208 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1174 } 1209 }
1175 1210
1176 // Test that a cross-site navigation that doesn't commit after the unload 1211 // Test that a cross-site navigation that doesn't commit after the unload
1177 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 1212 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562
1178 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { 1213 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
1179 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1214 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1180 SiteInstance* instance1 = contents()->GetSiteInstance(); 1215 SiteInstance* instance1 = contents()->GetSiteInstance();
1181 1216
1182 // Navigate to URL. First URL should use original RenderFrameHost. 1217 // Navigate to URL. First URL should use original RenderFrameHost.
1183 const GURL url("http://www.google.com"); 1218 const GURL url("http://www.google.com");
1184 controller().LoadURL( 1219 controller().LoadURL(
1185 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1220 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1221 contents()->GetMainFrame()->PrepareForCommit(url);
1186 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1222 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1187 EXPECT_FALSE(contents()->cross_navigation_pending()); 1223 EXPECT_FALSE(contents()->cross_navigation_pending());
1188 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1224 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1189 1225
1190 // Navigate to new site, simulating an onbeforeunload approval. 1226 // Navigate to new site, simulating an onbeforeunload approval.
1191 const GURL url2("http://www.yahoo.com"); 1227 const GURL url2("http://www.yahoo.com");
1192 controller().LoadURL( 1228 controller().LoadURL(
1193 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1229 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1194 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1230 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1195 base::TimeTicks now = base::TimeTicks::Now(); 1231 contents()->GetMainFrame()->PrepareForCommit(url2);
1196 orig_rfh->OnMessageReceived(
1197 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1198 EXPECT_TRUE(contents()->cross_navigation_pending()); 1232 EXPECT_TRUE(contents()->cross_navigation_pending());
1199 1233
1200 // Simulate swap out message when the response arrives. 1234 // Simulate swap out message when the response arrives.
1201 orig_rfh->OnSwappedOut(); 1235 orig_rfh->OnSwappedOut();
1202 1236
1203 // Suppose the navigation doesn't get a chance to commit, and the user 1237 // Suppose the navigation doesn't get a chance to commit, and the user
1204 // navigates in the current RFH's SiteInstance. 1238 // navigates in the current RFH's SiteInstance.
1205 controller().LoadURL( 1239 controller().LoadURL(
1206 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1240 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1207 1241
1208 // Verify that the pending navigation is cancelled and the renderer is no 1242 // Verify that the pending navigation is cancelled and the renderer is no
1209 // longer swapped out. 1243 // longer swapped out.
1210 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1244 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1211 SiteInstance* instance2 = contents()->GetSiteInstance(); 1245 SiteInstance* instance2 = contents()->GetSiteInstance();
1212 EXPECT_FALSE(contents()->cross_navigation_pending()); 1246 EXPECT_FALSE(contents()->cross_navigation_pending());
1213 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1247 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1214 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, orig_rfh->rfh_state()); 1248 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, orig_rfh->rfh_state());
1215 EXPECT_EQ(instance1, instance2); 1249 EXPECT_EQ(instance1, instance2);
1216 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1250 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1217 } 1251 }
1218 1252
1219 // Test that NavigationEntries have the correct page state after going 1253 // Test that NavigationEntries have the correct page state after going
1220 // forward and back. Prevents regression for bug 1116137. 1254 // forward and back. Prevents regression for bug 1116137.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { 1326 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) {
1293 FakeFullscreenDelegate fake_delegate; 1327 FakeFullscreenDelegate fake_delegate;
1294 contents()->SetDelegate(&fake_delegate); 1328 contents()->SetDelegate(&fake_delegate);
1295 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1329 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1296 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); 1330 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost();
1297 1331
1298 // Navigate to a site. 1332 // Navigate to a site.
1299 const GURL url("http://www.google.com"); 1333 const GURL url("http://www.google.com");
1300 controller().LoadURL( 1334 controller().LoadURL(
1301 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1335 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1336 contents()->GetMainFrame()->PrepareForCommit(url);
1302 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1337 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1303 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1338 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1304 1339
1305 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1340 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1306 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1341 EXPECT_FALSE(orig_rvh->IsFullscreen());
1307 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1342 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1308 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1343 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1309 orig_rfh->OnMessageReceived( 1344 orig_rfh->OnMessageReceived(
1310 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true)); 1345 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true));
1311 EXPECT_TRUE(orig_rvh->IsFullscreen()); 1346 EXPECT_TRUE(orig_rvh->IsFullscreen());
1312 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1347 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1313 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1348 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1314 1349
1315 // Navigate to a new site. 1350 // Navigate to a new site.
1316 const GURL url2("http://www.yahoo.com"); 1351 const GURL url2("http://www.yahoo.com");
1317 controller().LoadURL( 1352 controller().LoadURL(
1318 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1353 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1354 contents()->GetMainFrame()->PrepareForCommit(url2);
1319 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); 1355 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame();
1320 contents()->TestDidNavigate( 1356 contents()->TestDidNavigate(
1321 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1357 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1322 1358
1323 // Confirm fullscreen has exited. 1359 // Confirm fullscreen has exited.
1324 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1360 EXPECT_FALSE(orig_rvh->IsFullscreen());
1325 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1361 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1326 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1362 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1327 1363
1328 contents()->SetDelegate(NULL); 1364 contents()->SetDelegate(NULL);
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 // Navigate to a URL in the same site. 2732 // Navigate to a URL in the same site.
2697 contents->GetController().LoadURL(GURL("http://a.com/2"), 2733 contents->GetController().LoadURL(GURL("http://a.com/2"),
2698 Referrer(), 2734 Referrer(),
2699 ui::PAGE_TRANSITION_TYPED, 2735 ui::PAGE_TRANSITION_TYPED,
2700 std::string()); 2736 std::string());
2701 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2737 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2702 contents->CommitPendingNavigation(); 2738 contents->CommitPendingNavigation();
2703 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2739 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2704 2740
2705 // Navigate to a URL in a different site. 2741 // Navigate to a URL in a different site.
2706 contents->GetController().LoadURL(GURL("http://b.com"), 2742 const GURL kUrl = GURL("http://b.com");
2743 contents->GetController().LoadURL(kUrl,
2707 Referrer(), 2744 Referrer(),
2708 ui::PAGE_TRANSITION_TYPED, 2745 ui::PAGE_TRANSITION_TYPED,
2709 std::string()); 2746 std::string());
2747 contents->GetMainFrame()->PrepareForCommit(kUrl);
2710 EXPECT_TRUE(contents->cross_navigation_pending()); 2748 EXPECT_TRUE(contents->cross_navigation_pending());
2711 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2749 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2712 contents->CommitPendingNavigation(); 2750 contents->CommitPendingNavigation();
2713 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2751 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2714 2752
2715 contents.reset(); 2753 contents.reset();
2716 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2754 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2717 } 2755 }
2718 2756
2719 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes 2757 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes
(...skipping 10 matching lines...) Expand all
2730 2768
2731 // Navigate to a URL. 2769 // Navigate to a URL.
2732 contents->NavigateAndCommit(GURL("http://a.com")); 2770 contents->NavigateAndCommit(GURL("http://a.com"));
2733 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2771 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2734 2772
2735 // Navigate to a URL with WebUI. This will change BrowsingInstances. 2773 // Navigate to a URL with WebUI. This will change BrowsingInstances.
2736 contents->GetController().LoadURL(GURL(kTestWebUIUrl), 2774 contents->GetController().LoadURL(GURL(kTestWebUIUrl),
2737 Referrer(), 2775 Referrer(),
2738 ui::PAGE_TRANSITION_TYPED, 2776 ui::PAGE_TRANSITION_TYPED,
2739 std::string()); 2777 std::string());
2778 contents->GetMainFrame()->PrepareForCommit(GURL(kTestWebUIUrl));
2740 EXPECT_TRUE(contents->cross_navigation_pending()); 2779 EXPECT_TRUE(contents->cross_navigation_pending());
2741 scoped_refptr<SiteInstance> instance_webui( 2780 scoped_refptr<SiteInstance> instance_webui(
2742 contents->GetPendingMainFrame()->GetSiteInstance()); 2781 contents->GetPendingMainFrame()->GetSiteInstance());
2743 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); 2782 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get()));
2744 2783
2745 // At this point, contents still counts for the old BrowsingInstance. 2784 // At this point, contents still counts for the old BrowsingInstance.
2746 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2785 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2747 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); 2786 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount());
2748 2787
2749 // Commit and contents counts for the new one. 2788 // Commit and contents counts for the new one.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 3019
2981 // Destroy the remote player. No power save blockers should remain. 3020 // Destroy the remote player. No power save blockers should remain.
2982 rfh->OnMessageReceived( 3021 rfh->OnMessageReceived(
2983 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 3022 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId));
2984 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3023 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2985 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3024 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2986 } 3025 }
2987 #endif 3026 #endif
2988 3027
2989 } // namespace content 3028 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698