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

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

Issue 953503002: PlzNavigate: test updates post beforeUnload IPC refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor comment updates. Created 5 years, 9 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { 476 TEST_F(WebContentsImplTest, CrossSiteBoundaries) {
477 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 477 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
478 int orig_rvh_delete_count = 0; 478 int orig_rvh_delete_count = 0;
479 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 479 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
480 SiteInstance* instance1 = contents()->GetSiteInstance(); 480 SiteInstance* instance1 = contents()->GetSiteInstance();
481 481
482 // Navigate to URL. First URL should use first RenderViewHost. 482 // Navigate to URL. First URL should use first RenderViewHost.
483 const GURL url("http://www.google.com"); 483 const GURL url("http://www.google.com");
484 controller().LoadURL( 484 controller().LoadURL(
485 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 485 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
486 orig_rfh->PrepareForCommit(url); 486 orig_rfh->PrepareForCommit();
487 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 487 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
488 488
489 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 489 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
490 // that orig_rfh doesn't get deleted when it gets swapped out. 490 // that orig_rfh doesn't get deleted when it gets swapped out.
491 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 491 orig_rfh->GetSiteInstance()->increment_active_frame_count();
492 492
493 EXPECT_FALSE(contents()->cross_navigation_pending()); 493 EXPECT_FALSE(contents()->cross_navigation_pending());
494 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 494 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
495 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 495 EXPECT_EQ(url, contents()->GetLastCommittedURL());
496 EXPECT_EQ(url, contents()->GetVisibleURL()); 496 EXPECT_EQ(url, contents()->GetVisibleURL());
497 497
498 // Navigate to new site 498 // Navigate to new site
499 const GURL url2("http://www.yahoo.com"); 499 const GURL url2("http://www.yahoo.com");
500 controller().LoadURL( 500 controller().LoadURL(
501 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 501 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
502 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 502 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
503 switches::kEnableBrowserSideNavigation)) { 503 switches::kEnableBrowserSideNavigation)) {
504 orig_rfh->PrepareForCommit(url2); 504 orig_rfh->PrepareForCommit();
505 } 505 }
506 EXPECT_TRUE(contents()->cross_navigation_pending()); 506 EXPECT_TRUE(contents()->cross_navigation_pending());
507 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 507 EXPECT_EQ(url, contents()->GetLastCommittedURL());
508 EXPECT_EQ(url2, contents()->GetVisibleURL()); 508 EXPECT_EQ(url2, contents()->GetVisibleURL());
509 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 509 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
510 int pending_rvh_delete_count = 0; 510 int pending_rvh_delete_count = 0;
511 pending_rfh->GetRenderViewHost()->set_delete_counter( 511 pending_rfh->GetRenderViewHost()->set_delete_counter(
512 &pending_rvh_delete_count); 512 &pending_rvh_delete_count);
513 513
514 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 514 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
515 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 515 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
516 switches::kEnableBrowserSideNavigation)) { 516 switches::kEnableBrowserSideNavigation)) {
517 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 517 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
518 orig_rfh->SendBeforeUnloadACK(true); 518 orig_rfh->SendBeforeUnloadACK(true);
519 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 519 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
520 } 520 }
521 521
522 // DidNavigate from the pending page 522 // DidNavigate from the pending page
523 pending_rfh->PrepareForCommit(url2);
524 contents()->TestDidNavigate( 523 contents()->TestDidNavigate(
525 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 524 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
526 SiteInstance* instance2 = contents()->GetSiteInstance(); 525 SiteInstance* instance2 = contents()->GetSiteInstance();
527 526
528 // Keep the number of active frames in pending_rfh's SiteInstance 527 // Keep the number of active frames in pending_rfh's SiteInstance
529 // non-zero so that orig_rfh doesn't get deleted when it gets 528 // non-zero so that orig_rfh doesn't get deleted when it gets
530 // swapped out. 529 // swapped out.
531 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 530 pending_rfh->GetSiteInstance()->increment_active_frame_count();
532 531
533 EXPECT_FALSE(contents()->cross_navigation_pending()); 532 EXPECT_FALSE(contents()->cross_navigation_pending());
534 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 533 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
535 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 534 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
536 EXPECT_EQ(url2, contents()->GetVisibleURL()); 535 EXPECT_EQ(url2, contents()->GetVisibleURL());
537 EXPECT_NE(instance1, instance2); 536 EXPECT_NE(instance1, instance2);
538 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 537 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
539 // We keep the original RFH around, swapped out. 538 // We keep the original RFH around, swapped out.
540 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 539 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
541 orig_rfh)); 540 orig_rfh));
542 EXPECT_EQ(orig_rvh_delete_count, 0); 541 EXPECT_EQ(orig_rvh_delete_count, 0);
543 542
544 // Going back should switch SiteInstances again. The first SiteInstance is 543 // Going back should switch SiteInstances again. The first SiteInstance is
545 // stored in the NavigationEntry, so it should be the same as at the start. 544 // stored in the NavigationEntry, so it should be the same as at the start.
546 // We should use the same RFH as before, swapping it back in. 545 // We should use the same RFH as before, swapping it back in.
547 controller().GoBack(); 546 controller().GoBack();
548 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 547 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
549 switches::kEnableBrowserSideNavigation)) { 548 switches::kEnableBrowserSideNavigation)) {
550 contents()->GetMainFrame()->PrepareForCommit(url); 549 contents()->GetMainFrame()->PrepareForCommit();
551 } 550 }
552 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 551 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
553 EXPECT_EQ(orig_rfh, goback_rfh); 552 EXPECT_EQ(orig_rfh, goback_rfh);
554 EXPECT_TRUE(contents()->cross_navigation_pending()); 553 EXPECT_TRUE(contents()->cross_navigation_pending());
555 554
556 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 555 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
557 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 556 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
558 switches::kEnableBrowserSideNavigation)) { 557 switches::kEnableBrowserSideNavigation)) {
559 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 558 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
560 pending_rfh->SendBeforeUnloadACK(true); 559 pending_rfh->SendBeforeUnloadACK(true);
(...skipping 23 matching lines...) Expand all
584 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 583 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
585 584
586 int orig_rvh_delete_count = 0; 585 int orig_rvh_delete_count = 0;
587 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 586 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
588 SiteInstance* instance1 = contents()->GetSiteInstance(); 587 SiteInstance* instance1 = contents()->GetSiteInstance();
589 588
590 // Navigate to URL. First URL should use first RenderViewHost. 589 // Navigate to URL. First URL should use first RenderViewHost.
591 const GURL url("http://www.google.com"); 590 const GURL url("http://www.google.com");
592 controller().LoadURL( 591 controller().LoadURL(
593 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 592 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
594 contents()->GetMainFrame()->PrepareForCommit(url); 593 contents()->GetMainFrame()->PrepareForCommit();
595 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 594 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
596 595
597 EXPECT_FALSE(contents()->cross_navigation_pending()); 596 EXPECT_FALSE(contents()->cross_navigation_pending());
598 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 597 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
599 598
600 // Simulate a renderer crash. 599 // Simulate a renderer crash.
601 orig_rfh->GetRenderViewHost()->set_render_view_created(false); 600 orig_rfh->GetRenderViewHost()->set_render_view_created(false);
602 orig_rfh->SetRenderFrameCreated(false); 601 orig_rfh->SetRenderFrameCreated(false);
603 602
604 // Navigate to new site. We should not go into PENDING. 603 // Navigate to new site. We should not go into PENDING.
605 const GURL url2("http://www.yahoo.com"); 604 const GURL url2("http://www.yahoo.com");
606 controller().LoadURL( 605 controller().LoadURL(
607 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 606 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
608 contents()->GetMainFrame()->PrepareForCommit(url2); 607 contents()->GetMainFrame()->PrepareForCommit();
609 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); 608 TestRenderFrameHost* new_rfh = contents()->GetMainFrame();
610 EXPECT_FALSE(contents()->cross_navigation_pending()); 609 EXPECT_FALSE(contents()->cross_navigation_pending());
611 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 610 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
612 EXPECT_NE(orig_rfh, new_rfh); 611 EXPECT_NE(orig_rfh, new_rfh);
613 EXPECT_EQ(orig_rvh_delete_count, 1); 612 EXPECT_EQ(orig_rvh_delete_count, 1);
614 613
615 // DidNavigate from the new page 614 // DidNavigate from the new page
616 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 615 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
617 SiteInstance* instance2 = contents()->GetSiteInstance(); 616 SiteInstance* instance2 = contents()->GetSiteInstance();
618 617
(...skipping 11 matching lines...) Expand all
630 // both contentses to a new site will place both contentses in a single 629 // both contentses to a new site will place both contentses in a single
631 // SiteInstance. 630 // SiteInstance.
632 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { 631 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) {
633 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 632 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
634 SiteInstance* instance1 = contents()->GetSiteInstance(); 633 SiteInstance* instance1 = contents()->GetSiteInstance();
635 634
636 // Navigate to URL. First URL should use first RenderViewHost. 635 // Navigate to URL. First URL should use first RenderViewHost.
637 const GURL url("http://www.google.com"); 636 const GURL url("http://www.google.com");
638 controller().LoadURL( 637 controller().LoadURL(
639 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 638 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
640 contents()->GetMainFrame()->PrepareForCommit(url); 639 contents()->GetMainFrame()->PrepareForCommit();
641 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 640 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
642 641
643 // Open a new contents with the same SiteInstance, navigated to the same site. 642 // Open a new contents with the same SiteInstance, navigated to the same site.
644 scoped_ptr<TestWebContents> contents2( 643 scoped_ptr<TestWebContents> contents2(
645 TestWebContents::Create(browser_context(), instance1)); 644 TestWebContents::Create(browser_context(), instance1));
646 contents2->GetController().LoadURL(url, Referrer(), 645 contents2->GetController().LoadURL(url, Referrer(),
647 ui::PAGE_TRANSITION_TYPED, 646 ui::PAGE_TRANSITION_TYPED,
648 std::string()); 647 std::string());
649 contents2->GetMainFrame()->PrepareForCommit(url); 648 contents2->GetMainFrame()->PrepareForCommit();
650 // Need this page id to be 2 since the site instance is the same (which is the 649 // Need this page id to be 2 since the site instance is the same (which is the
651 // scope of page IDs) and we want to consider this a new page. 650 // scope of page IDs) and we want to consider this a new page.
652 contents2->TestDidNavigate( 651 contents2->TestDidNavigate(
653 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 652 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
654 653
655 // Navigate first contents to a new site. 654 // Navigate first contents to a new site.
656 const GURL url2a("http://www.yahoo.com"); 655 const GURL url2a("http://www.yahoo.com");
657 controller().LoadURL( 656 controller().LoadURL(
658 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 657 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
659 orig_rfh->PrepareForCommit(url2a); 658 orig_rfh->PrepareForCommit();
660 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); 659 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame();
661 contents()->TestDidNavigate( 660 contents()->TestDidNavigate(
662 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); 661 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED);
663 SiteInstance* instance2a = contents()->GetSiteInstance(); 662 SiteInstance* instance2a = contents()->GetSiteInstance();
664 EXPECT_NE(instance1, instance2a); 663 EXPECT_NE(instance1, instance2a);
665 664
666 // Navigate second contents to the same site as the first tab. 665 // Navigate second contents to the same site as the first tab.
667 const GURL url2b("http://mail.yahoo.com"); 666 const GURL url2b("http://mail.yahoo.com");
668 contents2->GetController().LoadURL(url2b, Referrer(), 667 contents2->GetController().LoadURL(url2b, Referrer(),
669 ui::PAGE_TRANSITION_TYPED, 668 ui::PAGE_TRANSITION_TYPED,
670 std::string()); 669 std::string());
671 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 670 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
672 rfh2->PrepareForCommit(url2b); 671 rfh2->PrepareForCommit();
673 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); 672 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame();
674 EXPECT_TRUE(pending_rfh_b != NULL); 673 EXPECT_TRUE(pending_rfh_b != NULL);
675 EXPECT_TRUE(contents2->cross_navigation_pending()); 674 EXPECT_TRUE(contents2->cross_navigation_pending());
676 675
677 // NOTE(creis): We used to be in danger of showing a crash page here if the 676 // NOTE(creis): We used to be in danger of showing a crash page here if the
678 // second contents hadn't navigated somewhere first (bug 1145430). That case 677 // second contents hadn't navigated somewhere first (bug 1145430). That case
679 // is now covered by the CrossSiteBoundariesAfterCrash test. 678 // is now covered by the CrossSiteBoundariesAfterCrash test.
680 contents2->TestDidNavigate( 679 contents2->TestDidNavigate(
681 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); 680 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED);
682 SiteInstance* instance2b = contents2->GetSiteInstance(); 681 SiteInstance* instance2b = contents2->GetSiteInstance();
(...skipping 14 matching lines...) Expand all
697 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 696 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
698 int orig_rvh_delete_count = 0; 697 int orig_rvh_delete_count = 0;
699 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 698 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
700 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); 699 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
701 700
702 browser_client.set_assign_site_for_url(false); 701 browser_client.set_assign_site_for_url(false);
703 // Navigate to an URL that will not assign a new SiteInstance. 702 // Navigate to an URL that will not assign a new SiteInstance.
704 const GURL native_url("non-site-url://stuffandthings"); 703 const GURL native_url("non-site-url://stuffandthings");
705 controller().LoadURL( 704 controller().LoadURL(
706 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 705 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
707 contents()->GetMainFrame()->PrepareForCommit(native_url); 706 contents()->GetMainFrame()->PrepareForCommit();
708 contents()->TestDidNavigate( 707 contents()->TestDidNavigate(
709 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); 708 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED);
710 709
711 EXPECT_FALSE(contents()->cross_navigation_pending()); 710 EXPECT_FALSE(contents()->cross_navigation_pending());
712 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 711 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
713 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 712 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
714 EXPECT_EQ(native_url, contents()->GetVisibleURL()); 713 EXPECT_EQ(native_url, contents()->GetVisibleURL());
715 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 714 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
716 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 715 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
717 EXPECT_FALSE(orig_instance->HasSite()); 716 EXPECT_FALSE(orig_instance->HasSite());
718 717
719 browser_client.set_assign_site_for_url(true); 718 browser_client.set_assign_site_for_url(true);
720 // Navigate to new site (should keep same site instance). 719 // Navigate to new site (should keep same site instance).
721 const GURL url("http://www.google.com"); 720 const GURL url("http://www.google.com");
722 controller().LoadURL( 721 controller().LoadURL(
723 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 722 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
724 contents()->GetMainFrame()->PrepareForCommit(url); 723 contents()->GetMainFrame()->PrepareForCommit();
725 EXPECT_FALSE(contents()->cross_navigation_pending()); 724 EXPECT_FALSE(contents()->cross_navigation_pending());
726 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 725 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
727 EXPECT_EQ(url, contents()->GetVisibleURL()); 726 EXPECT_EQ(url, contents()->GetVisibleURL());
728 EXPECT_FALSE(contents()->GetPendingMainFrame()); 727 EXPECT_FALSE(contents()->GetPendingMainFrame());
729 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 728 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
730 729
731 // Keep the number of active frames in orig_rfh's SiteInstance 730 // Keep the number of active frames in orig_rfh's SiteInstance
732 // non-zero so that orig_rfh doesn't get deleted when it gets 731 // non-zero so that orig_rfh doesn't get deleted when it gets
733 // swapped out. 732 // swapped out.
734 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 733 orig_rfh->GetSiteInstance()->increment_active_frame_count();
735 734
736 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 735 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
737 EXPECT_TRUE( 736 EXPECT_TRUE(
738 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 737 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
739 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 738 EXPECT_EQ(url, contents()->GetLastCommittedURL());
740 739
741 // Navigate to another new site (should create a new site instance). 740 // Navigate to another new site (should create a new site instance).
742 const GURL url2("http://www.yahoo.com"); 741 const GURL url2("http://www.yahoo.com");
743 controller().LoadURL( 742 controller().LoadURL(
744 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 743 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
745 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 744 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
746 switches::kEnableBrowserSideNavigation)) { 745 switches::kEnableBrowserSideNavigation)) {
747 orig_rfh->PrepareForCommit(url2); 746 orig_rfh->PrepareForCommit();
748 } 747 }
749 EXPECT_TRUE(contents()->cross_navigation_pending()); 748 EXPECT_TRUE(contents()->cross_navigation_pending());
750 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 749 EXPECT_EQ(url, contents()->GetLastCommittedURL());
751 EXPECT_EQ(url2, contents()->GetVisibleURL()); 750 EXPECT_EQ(url2, contents()->GetVisibleURL());
752 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 751 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
753 int pending_rvh_delete_count = 0; 752 int pending_rvh_delete_count = 0;
754 pending_rfh->GetRenderViewHost()->set_delete_counter( 753 pending_rfh->GetRenderViewHost()->set_delete_counter(
755 &pending_rvh_delete_count); 754 &pending_rvh_delete_count);
756 755
757 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 756 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 browser_context()); 846 browser_context());
848 entry->SetPageID(0); 847 entry->SetPageID(0);
849 entries.push_back(entry); 848 entries.push_back(entry);
850 controller().Restore( 849 controller().Restore(
851 0, 850 0,
852 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 851 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
853 &entries); 852 &entries);
854 ASSERT_EQ(0u, entries.size()); 853 ASSERT_EQ(0u, entries.size());
855 ASSERT_EQ(1, controller().GetEntryCount()); 854 ASSERT_EQ(1, controller().GetEntryCount());
856 controller().GoToIndex(0); 855 controller().GoToIndex(0);
857 orig_rfh->PrepareForCommit(regular_url); 856 orig_rfh->PrepareForCommit();
858 contents()->TestDidNavigate( 857 contents()->TestDidNavigate(
859 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD); 858 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD);
860 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 859 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
861 EXPECT_TRUE(orig_instance->HasSite()); 860 EXPECT_TRUE(orig_instance->HasSite());
862 861
863 // Navigate to another site and verify that a new SiteInstance was created. 862 // Navigate to another site and verify that a new SiteInstance was created.
864 const GURL url("http://www.google.com"); 863 const GURL url("http://www.google.com");
865 controller().LoadURL( 864 controller().LoadURL(
866 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 865 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
867 orig_rfh->PrepareForCommit(url); 866 orig_rfh->PrepareForCommit();
868 contents()->TestDidNavigate( 867 contents()->TestDidNavigate(
869 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 868 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
870 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); 869 EXPECT_NE(orig_instance, contents()->GetSiteInstance());
871 870
872 // Cleanup. 871 // Cleanup.
873 DeleteContents(); 872 DeleteContents();
874 } 873 }
875 874
876 // Test that we can find an opener RVH even if it's pending. 875 // Test that we can find an opener RVH even if it's pending.
877 // http://crbug.com/176252. 876 // http://crbug.com/176252.
878 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { 877 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) {
879 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 878 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
880 879
881 // Navigate to a URL. 880 // Navigate to a URL.
882 const GURL url("http://www.google.com"); 881 const GURL url("http://www.google.com");
883 controller().LoadURL( 882 controller().LoadURL(
884 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 883 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
885 orig_rfh->PrepareForCommit(url); 884 orig_rfh->PrepareForCommit();
886 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 885 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
887 886
888 // Start to navigate first tab to a new site, so that it has a pending RVH. 887 // Start to navigate first tab to a new site, so that it has a pending RVH.
889 const GURL url2("http://www.yahoo.com"); 888 const GURL url2("http://www.yahoo.com");
890 controller().LoadURL( 889 controller().LoadURL(
891 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 890 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
892 orig_rfh->PrepareForCommit(url2); 891 orig_rfh->PrepareForCommit();
893 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 892 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
894 893
895 // While it is still pending, simulate opening a new tab with the first tab 894 // While it is still pending, simulate opening a new tab with the first tab
896 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews 895 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews
897 // on the opener to ensure that an RVH exists. 896 // on the opener to ensure that an RVH exists.
898 int opener_routing_id = 897 int opener_routing_id =
899 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); 898 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance());
900 899
901 // We should find the pending RVH and not create a new one. 900 // We should find the pending RVH and not create a new one.
902 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), 901 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(),
903 opener_routing_id); 902 opener_routing_id);
904 } 903 }
905 904
906 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, 905 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site,
907 // to determine whether a navigation is cross-site. 906 // to determine whether a navigation is cross-site.
908 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { 907 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) {
909 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 908 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
910 SiteInstance* instance1 = contents()->GetSiteInstance(); 909 SiteInstance* instance1 = contents()->GetSiteInstance();
911 910
912 // Navigate to URL. 911 // Navigate to URL.
913 const GURL url("http://www.google.com"); 912 const GURL url("http://www.google.com");
914 controller().LoadURL( 913 controller().LoadURL(
915 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 914 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
916 contents()->GetMainFrame()->PrepareForCommit(url); 915 contents()->GetMainFrame()->PrepareForCommit();
917 contents()->TestDidNavigate( 916 contents()->TestDidNavigate(
918 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 917 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
919 918
920 // Open a related contents to a second site. 919 // Open a related contents to a second site.
921 scoped_ptr<TestWebContents> contents2( 920 scoped_ptr<TestWebContents> contents2(
922 TestWebContents::Create(browser_context(), instance1)); 921 TestWebContents::Create(browser_context(), instance1));
923 const GURL url2("http://www.yahoo.com"); 922 const GURL url2("http://www.yahoo.com");
924 contents2->GetController().LoadURL(url2, Referrer(), 923 contents2->GetController().LoadURL(url2, Referrer(),
925 ui::PAGE_TRANSITION_TYPED, 924 ui::PAGE_TRANSITION_TYPED,
926 std::string()); 925 std::string());
927 contents2->GetMainFrame()->PrepareForCommit(url2); 926 contents2->GetMainFrame()->PrepareForCommit();
928 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 927 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
929 // pending. 928 // pending.
930 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 929 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
931 EXPECT_FALSE(contents2->cross_navigation_pending()); 930 EXPECT_FALSE(contents2->cross_navigation_pending());
932 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED); 931 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED);
933 SiteInstance* instance2 = contents2->GetSiteInstance(); 932 SiteInstance* instance2 = contents2->GetSiteInstance();
934 EXPECT_NE(instance1, instance2); 933 EXPECT_NE(instance1, instance2);
935 EXPECT_FALSE(contents2->cross_navigation_pending()); 934 EXPECT_FALSE(contents2->cross_navigation_pending());
936 935
937 // Simulate a link click in first contents to second site. Doesn't switch 936 // Simulate a link click in first contents to second site. Doesn't switch
938 // SiteInstances, because we don't intercept WebKit navigations. 937 // SiteInstances, because we don't intercept WebKit navigations.
939 contents()->TestDidNavigate( 938 contents()->TestDidNavigate(
940 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 939 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED);
941 SiteInstance* instance3 = contents()->GetSiteInstance(); 940 SiteInstance* instance3 = contents()->GetSiteInstance();
942 EXPECT_EQ(instance1, instance3); 941 EXPECT_EQ(instance1, instance3);
943 EXPECT_FALSE(contents()->cross_navigation_pending()); 942 EXPECT_FALSE(contents()->cross_navigation_pending());
944 943
945 // Navigate to the new site. Doesn't switch SiteInstancees, because we 944 // Navigate to the new site. Doesn't switch SiteInstancees, because we
946 // compare against the current URL, not the SiteInstance's site. 945 // compare against the current URL, not the SiteInstance's site.
947 const GURL url3("http://mail.yahoo.com"); 946 const GURL url3("http://mail.yahoo.com");
948 controller().LoadURL( 947 controller().LoadURL(
949 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 948 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
950 EXPECT_FALSE(contents()->cross_navigation_pending()); 949 EXPECT_FALSE(contents()->cross_navigation_pending());
951 contents()->GetMainFrame()->PrepareForCommit(url3); 950 contents()->GetMainFrame()->PrepareForCommit();
952 contents()->TestDidNavigate( 951 contents()->TestDidNavigate(
953 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); 952 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED);
954 SiteInstance* instance4 = contents()->GetSiteInstance(); 953 SiteInstance* instance4 = contents()->GetSiteInstance();
955 EXPECT_EQ(instance1, instance4); 954 EXPECT_EQ(instance1, instance4);
956 } 955 }
957 956
958 // Test that the onbeforeunload and onunload handlers run when navigating 957 // Test that the onbeforeunload and onunload handlers run when navigating
959 // across site boundaries. 958 // across site boundaries.
960 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 959 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
961 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 960 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
962 SiteInstance* instance1 = contents()->GetSiteInstance(); 961 SiteInstance* instance1 = contents()->GetSiteInstance();
963 962
964 // Navigate to URL. First URL should use first RenderViewHost. 963 // Navigate to URL. First URL should use first RenderViewHost.
965 const GURL url("http://www.google.com"); 964 const GURL url("http://www.google.com");
966 controller().LoadURL( 965 controller().LoadURL(
967 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 966 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
968 contents()->GetMainFrame()->PrepareForCommit(url); 967 contents()->GetMainFrame()->PrepareForCommit();
969 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 968 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
970 EXPECT_FALSE(contents()->cross_navigation_pending()); 969 EXPECT_FALSE(contents()->cross_navigation_pending());
971 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 970 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
972 971
973 // Navigate to new site, but simulate an onbeforeunload denial. 972 // Navigate to new site, but simulate an onbeforeunload denial.
974 const GURL url2("http://www.yahoo.com"); 973 const GURL url2("http://www.yahoo.com");
975 controller().LoadURL( 974 controller().LoadURL(
976 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 975 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
977 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 976 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
978 base::TimeTicks now = base::TimeTicks::Now(); 977 base::TimeTicks now = base::TimeTicks::Now();
979 orig_rfh->OnMessageReceived( 978 orig_rfh->OnMessageReceived(
980 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 979 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
981 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 980 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
982 EXPECT_FALSE(contents()->cross_navigation_pending()); 981 EXPECT_FALSE(contents()->cross_navigation_pending());
983 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 982 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
984 983
985 // Navigate again, but simulate an onbeforeunload approval. 984 // Navigate again, but simulate an onbeforeunload approval.
986 controller().LoadURL( 985 controller().LoadURL(
987 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 986 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
988 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 987 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
989 now = base::TimeTicks::Now(); 988 now = base::TimeTicks::Now();
990 orig_rfh->PrepareForCommit(url2); 989 orig_rfh->PrepareForCommit();
991 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 990 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
992 EXPECT_TRUE(contents()->cross_navigation_pending()); 991 EXPECT_TRUE(contents()->cross_navigation_pending());
993 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 992 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
994 993
995 // We won't hear DidNavigate until the onunload handler has finished running. 994 // We won't hear DidNavigate until the onunload handler has finished running.
996 995
997 // DidNavigate from the pending page. 996 // DidNavigate from the pending page.
998 contents()->TestDidNavigate( 997 contents()->TestDidNavigate(
999 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 998 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1000 SiteInstance* instance2 = contents()->GetSiteInstance(); 999 SiteInstance* instance2 = contents()->GetSiteInstance();
1001 EXPECT_FALSE(contents()->cross_navigation_pending()); 1000 EXPECT_FALSE(contents()->cross_navigation_pending());
1002 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1001 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1003 EXPECT_NE(instance1, instance2); 1002 EXPECT_NE(instance1, instance2);
1004 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1003 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1005 } 1004 }
1006 1005
1007 // Test that during a slow cross-site navigation, the original renderer can 1006 // Test that during a slow cross-site navigation, the original renderer can
1008 // navigate to a different URL and have it displayed, canceling the slow 1007 // navigate to a different URL and have it displayed, canceling the slow
1009 // navigation. 1008 // navigation.
1010 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { 1009 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) {
1011 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1010 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1012 SiteInstance* instance1 = contents()->GetSiteInstance(); 1011 SiteInstance* instance1 = contents()->GetSiteInstance();
1013 1012
1014 // Navigate to URL. First URL should use first RenderFrameHost. 1013 // Navigate to URL. First URL should use first RenderFrameHost.
1015 const GURL url("http://www.google.com"); 1014 const GURL url("http://www.google.com");
1016 controller().LoadURL( 1015 controller().LoadURL(
1017 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1016 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1018 contents()->GetMainFrame()->PrepareForCommit(url); 1017 contents()->GetMainFrame()->PrepareForCommit();
1019 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1018 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1020 EXPECT_FALSE(contents()->cross_navigation_pending()); 1019 EXPECT_FALSE(contents()->cross_navigation_pending());
1021 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1020 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1022 1021
1023 // Navigate to new site, simulating an onbeforeunload approval. 1022 // Navigate to new site, simulating an onbeforeunload approval.
1024 const GURL url2("http://www.yahoo.com"); 1023 const GURL url2("http://www.yahoo.com");
1025 controller().LoadURL( 1024 controller().LoadURL(
1026 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1025 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1027 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1026 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1028 orig_rfh->PrepareForCommit(url2); 1027 orig_rfh->PrepareForCommit();
1029 EXPECT_TRUE(contents()->cross_navigation_pending()); 1028 EXPECT_TRUE(contents()->cross_navigation_pending());
1030 1029
1031 // Suppose the original renderer navigates before the new one is ready. 1030 // Suppose the original renderer navigates before the new one is ready.
1032 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); 1031 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo"));
1033 1032
1034 // Verify that the pending navigation is cancelled. 1033 // Verify that the pending navigation is cancelled.
1035 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1034 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1036 SiteInstance* instance2 = contents()->GetSiteInstance(); 1035 SiteInstance* instance2 = contents()->GetSiteInstance();
1037 EXPECT_FALSE(contents()->cross_navigation_pending()); 1036 EXPECT_FALSE(contents()->cross_navigation_pending());
1038 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1037 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1039 EXPECT_EQ(instance1, instance2); 1038 EXPECT_EQ(instance1, instance2);
1040 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1039 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1041 } 1040 }
1042 1041
1043 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1042 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1044 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1043 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1045 const GURL url1("chrome://blah"); 1044 const GURL url1("chrome://blah");
1046 controller().LoadURL( 1045 controller().LoadURL(
1047 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1046 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1048 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 1047 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
1049 ntp_rfh->PrepareForCommit(url1); 1048 ntp_rfh->PrepareForCommit();
1050 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); 1049 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED);
1051 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1050 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1052 SiteInstance* instance1 = contents()->GetSiteInstance(); 1051 SiteInstance* instance1 = contents()->GetSiteInstance();
1053 1052
1054 EXPECT_FALSE(contents()->cross_navigation_pending()); 1053 EXPECT_FALSE(contents()->cross_navigation_pending());
1055 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1054 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
1056 EXPECT_EQ(url1, entry1->GetURL()); 1055 EXPECT_EQ(url1, entry1->GetURL());
1057 EXPECT_EQ(instance1, 1056 EXPECT_EQ(instance1,
1058 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1057 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1059 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & 1058 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() &
1060 BINDINGS_POLICY_WEB_UI); 1059 BINDINGS_POLICY_WEB_UI);
1061 1060
1062 // Navigate to new site. 1061 // Navigate to new site.
1063 const GURL url2("http://www.google.com"); 1062 const GURL url2("http://www.google.com");
1064 controller().LoadURL( 1063 controller().LoadURL(
1065 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1064 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1066 EXPECT_TRUE(contents()->cross_navigation_pending()); 1065 EXPECT_TRUE(contents()->cross_navigation_pending());
1067 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1066 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1068 1067
1069 // Simulate beforeunload approval. 1068 // Simulate beforeunload approval.
1070 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK()); 1069 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK());
1071 base::TimeTicks now = base::TimeTicks::Now(); 1070 base::TimeTicks now = base::TimeTicks::Now();
1072 ntp_rfh->PrepareForCommit(url2); 1071 ntp_rfh->PrepareForCommit();
1073 1072
1074 // DidNavigate from the pending page. 1073 // DidNavigate from the pending page.
1075 contents()->TestDidNavigate( 1074 contents()->TestDidNavigate(
1076 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1075 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1077 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1076 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1078 SiteInstance* instance2 = contents()->GetSiteInstance(); 1077 SiteInstance* instance2 = contents()->GetSiteInstance();
1079 1078
1080 EXPECT_FALSE(contents()->cross_navigation_pending()); 1079 EXPECT_FALSE(contents()->cross_navigation_pending());
1081 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1080 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1082 EXPECT_NE(instance1, instance2); 1081 EXPECT_NE(instance1, instance2);
1083 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1082 EXPECT_FALSE(contents()->GetPendingMainFrame());
1084 EXPECT_EQ(url2, entry2->GetURL()); 1083 EXPECT_EQ(url2, entry2->GetURL());
1085 EXPECT_EQ(instance2, 1084 EXPECT_EQ(instance2,
1086 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1085 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1087 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1086 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1088 BINDINGS_POLICY_WEB_UI); 1087 BINDINGS_POLICY_WEB_UI);
1089 1088
1090 // Navigate to third page on same site. 1089 // Navigate to third page on same site.
1091 const GURL url3("http://news.google.com"); 1090 const GURL url3("http://news.google.com");
1092 controller().LoadURL( 1091 controller().LoadURL(
1093 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1092 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1094 EXPECT_FALSE(contents()->cross_navigation_pending()); 1093 EXPECT_FALSE(contents()->cross_navigation_pending());
1095 contents()->GetMainFrame()->PrepareForCommit(url3); 1094 contents()->GetMainFrame()->PrepareForCommit();
1096 contents()->TestDidNavigate( 1095 contents()->TestDidNavigate(
1097 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED); 1096 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED);
1098 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1097 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1099 SiteInstance* instance3 = contents()->GetSiteInstance(); 1098 SiteInstance* instance3 = contents()->GetSiteInstance();
1100 1099
1101 EXPECT_FALSE(contents()->cross_navigation_pending()); 1100 EXPECT_FALSE(contents()->cross_navigation_pending());
1102 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1101 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1103 EXPECT_EQ(instance2, instance3); 1102 EXPECT_EQ(instance2, instance3);
1104 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1103 EXPECT_FALSE(contents()->GetPendingMainFrame());
1105 EXPECT_EQ(url3, entry3->GetURL()); 1104 EXPECT_EQ(url3, entry3->GetURL());
1106 EXPECT_EQ(instance3, 1105 EXPECT_EQ(instance3,
1107 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1106 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1108 1107
1109 // Go back within the site. 1108 // Go back within the site.
1110 controller().GoBack(); 1109 controller().GoBack();
1111 EXPECT_FALSE(contents()->cross_navigation_pending()); 1110 EXPECT_FALSE(contents()->cross_navigation_pending());
1112 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1111 EXPECT_EQ(entry2, controller().GetPendingEntry());
1113 1112
1114 // Before that commits, go back again. 1113 // Before that commits, go back again.
1115 controller().GoBack(); 1114 controller().GoBack();
1116 EXPECT_TRUE(contents()->cross_navigation_pending()); 1115 EXPECT_TRUE(contents()->cross_navigation_pending());
1117 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1116 EXPECT_TRUE(contents()->GetPendingMainFrame());
1118 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1117 EXPECT_EQ(entry1, controller().GetPendingEntry());
1119 1118
1120 // Simulate beforeunload approval. 1119 // Simulate beforeunload approval.
1121 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK()); 1120 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK());
1122 now = base::TimeTicks::Now(); 1121 now = base::TimeTicks::Now();
1123 google_rfh->PrepareForCommit(url2); 1122 google_rfh->PrepareForCommit();
1124 google_rfh->OnMessageReceived( 1123 google_rfh->OnMessageReceived(
1125 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1124 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1126 1125
1127 // DidNavigate from the first back. This aborts the second back's pending RFH. 1126 // DidNavigate from the first back. This aborts the second back's pending RFH.
1128 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1127 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1129 1128
1130 // We should commit this page and forget about the second back. 1129 // We should commit this page and forget about the second back.
1131 EXPECT_FALSE(contents()->cross_navigation_pending()); 1130 EXPECT_FALSE(contents()->cross_navigation_pending());
1132 EXPECT_FALSE(controller().GetPendingEntry()); 1131 EXPECT_FALSE(controller().GetPendingEntry());
1133 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1132 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
(...skipping 11 matching lines...) Expand all
1145 1144
1146 // Test that during a slow cross-site navigation, a sub-frame navigation in the 1145 // Test that during a slow cross-site navigation, a sub-frame navigation in the
1147 // original renderer will not cancel the slow navigation (bug 42029). 1146 // original renderer will not cancel the slow navigation (bug 42029).
1148 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { 1147 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) {
1149 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1148 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1150 1149
1151 // Navigate to URL. First URL should use the original RenderFrameHost. 1150 // Navigate to URL. First URL should use the original RenderFrameHost.
1152 const GURL url("http://www.google.com"); 1151 const GURL url("http://www.google.com");
1153 controller().LoadURL( 1152 controller().LoadURL(
1154 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1153 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1155 contents()->GetMainFrame()->PrepareForCommit(url); 1154 contents()->GetMainFrame()->PrepareForCommit();
1156 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1155 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1157 EXPECT_FALSE(contents()->cross_navigation_pending()); 1156 EXPECT_FALSE(contents()->cross_navigation_pending());
1158 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1157 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1159 1158
1160 // Start navigating to new site. 1159 // Start navigating to new site.
1161 const GURL url2("http://www.yahoo.com"); 1160 const GURL url2("http://www.yahoo.com");
1162 controller().LoadURL( 1161 controller().LoadURL(
1163 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1162 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1164 1163
1165 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1164 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1166 // waiting for a before unload response. 1165 // waiting for a before unload response.
1167 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1166 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1168 child_rfh->SendNavigateWithTransition( 1167 child_rfh->SendNavigateWithTransition(
1169 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1168 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1170 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1169 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1171 1170
1172 // Now simulate the onbeforeunload approval and verify the navigation is 1171 // Now simulate the onbeforeunload approval and verify the navigation is
1173 // not canceled. 1172 // not canceled.
1174 orig_rfh->PrepareForCommit(url2); 1173 orig_rfh->PrepareForCommit();
1175 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1174 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1176 EXPECT_TRUE(contents()->cross_navigation_pending()); 1175 EXPECT_TRUE(contents()->cross_navigation_pending());
1177 } 1176 }
1178 1177
1179 // Test that a cross-site navigation is not preempted if the previous 1178 // Test that a cross-site navigation is not preempted if the previous
1180 // renderer sends a FrameNavigate message just before being told to stop. 1179 // renderer sends a FrameNavigate message just before being told to stop.
1181 // We should only preempt the cross-site navigation if the previous renderer 1180 // We should only preempt the cross-site navigation if the previous renderer
1182 // has started a new navigation. See http://crbug.com/79176. 1181 // has started a new navigation. See http://crbug.com/79176.
1183 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1182 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1184 // Navigate to NTP URL. 1183 // Navigate to NTP URL.
(...skipping 28 matching lines...) Expand all
1213 // Test that a cross-site navigation that doesn't commit after the unload 1212 // Test that a cross-site navigation that doesn't commit after the unload
1214 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 1213 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562
1215 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { 1214 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
1216 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1215 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1217 SiteInstance* instance1 = contents()->GetSiteInstance(); 1216 SiteInstance* instance1 = contents()->GetSiteInstance();
1218 1217
1219 // Navigate to URL. First URL should use original RenderFrameHost. 1218 // Navigate to URL. First URL should use original RenderFrameHost.
1220 const GURL url("http://www.google.com"); 1219 const GURL url("http://www.google.com");
1221 controller().LoadURL( 1220 controller().LoadURL(
1222 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1221 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1223 contents()->GetMainFrame()->PrepareForCommit(url); 1222 contents()->GetMainFrame()->PrepareForCommit();
1224 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1223 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1225 EXPECT_FALSE(contents()->cross_navigation_pending()); 1224 EXPECT_FALSE(contents()->cross_navigation_pending());
1226 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1225 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1227 1226
1228 // Navigate to new site, simulating an onbeforeunload approval. 1227 // Navigate to new site, simulating an onbeforeunload approval.
1229 const GURL url2("http://www.yahoo.com"); 1228 const GURL url2("http://www.yahoo.com");
1230 controller().LoadURL( 1229 controller().LoadURL(
1231 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1230 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1232 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1231 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1233 contents()->GetMainFrame()->PrepareForCommit(url2); 1232 contents()->GetMainFrame()->PrepareForCommit();
1234 EXPECT_TRUE(contents()->cross_navigation_pending()); 1233 EXPECT_TRUE(contents()->cross_navigation_pending());
1235 1234
1236 // Simulate swap out message when the response arrives. 1235 // Simulate swap out message when the response arrives.
1237 orig_rfh->OnSwappedOut(); 1236 orig_rfh->OnSwappedOut();
1238 1237
1239 // Suppose the navigation doesn't get a chance to commit, and the user 1238 // Suppose the navigation doesn't get a chance to commit, and the user
1240 // navigates in the current RFH's SiteInstance. 1239 // navigates in the current RFH's SiteInstance.
1241 controller().LoadURL( 1240 controller().LoadURL(
1242 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1241 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1243 1242
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { 1327 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) {
1329 FakeFullscreenDelegate fake_delegate; 1328 FakeFullscreenDelegate fake_delegate;
1330 contents()->SetDelegate(&fake_delegate); 1329 contents()->SetDelegate(&fake_delegate);
1331 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1330 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1332 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); 1331 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost();
1333 1332
1334 // Navigate to a site. 1333 // Navigate to a site.
1335 const GURL url("http://www.google.com"); 1334 const GURL url("http://www.google.com");
1336 controller().LoadURL( 1335 controller().LoadURL(
1337 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1336 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1338 contents()->GetMainFrame()->PrepareForCommit(url); 1337 contents()->GetMainFrame()->PrepareForCommit();
1339 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1338 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1340 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1339 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1341 1340
1342 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1341 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1343 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1342 EXPECT_FALSE(orig_rvh->IsFullscreen());
1344 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1343 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1345 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1344 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1346 orig_rfh->OnMessageReceived( 1345 orig_rfh->OnMessageReceived(
1347 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true)); 1346 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true));
1348 EXPECT_TRUE(orig_rvh->IsFullscreen()); 1347 EXPECT_TRUE(orig_rvh->IsFullscreen());
1349 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1348 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1350 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1349 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1351 1350
1352 // Navigate to a new site. 1351 // Navigate to a new site.
1353 const GURL url2("http://www.yahoo.com"); 1352 const GURL url2("http://www.yahoo.com");
1354 controller().LoadURL( 1353 controller().LoadURL(
1355 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1354 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1356 contents()->GetMainFrame()->PrepareForCommit(url2); 1355 contents()->GetMainFrame()->PrepareForCommit();
1357 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); 1356 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame();
1358 contents()->TestDidNavigate( 1357 contents()->TestDidNavigate(
1359 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1358 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1360 1359
1361 // Confirm fullscreen has exited. 1360 // Confirm fullscreen has exited.
1362 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1361 EXPECT_FALSE(orig_rvh->IsFullscreen());
1363 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1362 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1364 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1363 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1365 1364
1366 contents()->SetDelegate(NULL); 1365 contents()->SetDelegate(NULL);
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2692 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2694 contents->CommitPendingNavigation(); 2693 contents->CommitPendingNavigation();
2695 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2694 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2696 2695
2697 // Navigate to a URL in a different site. 2696 // Navigate to a URL in a different site.
2698 const GURL kUrl = GURL("http://b.com"); 2697 const GURL kUrl = GURL("http://b.com");
2699 contents->GetController().LoadURL(kUrl, 2698 contents->GetController().LoadURL(kUrl,
2700 Referrer(), 2699 Referrer(),
2701 ui::PAGE_TRANSITION_TYPED, 2700 ui::PAGE_TRANSITION_TYPED,
2702 std::string()); 2701 std::string());
2703 contents->GetMainFrame()->PrepareForCommit(kUrl); 2702 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2703 switches::kEnableBrowserSideNavigation)) {
2704 contents->GetMainFrame()->SendBeforeUnloadACK(true);
2705 }
2704 EXPECT_TRUE(contents->cross_navigation_pending()); 2706 EXPECT_TRUE(contents->cross_navigation_pending());
2705 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2707 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2706 contents->CommitPendingNavigation(); 2708 contents->CommitPendingNavigation();
2707 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2709 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2708 2710
2709 contents.reset(); 2711 contents.reset();
2710 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2712 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2711 } 2713 }
2712 2714
2713 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes 2715 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes
(...skipping 10 matching lines...) Expand all
2724 2726
2725 // Navigate to a URL. 2727 // Navigate to a URL.
2726 contents->NavigateAndCommit(GURL("http://a.com")); 2728 contents->NavigateAndCommit(GURL("http://a.com"));
2727 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2729 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2728 2730
2729 // Navigate to a URL with WebUI. This will change BrowsingInstances. 2731 // Navigate to a URL with WebUI. This will change BrowsingInstances.
2730 contents->GetController().LoadURL(GURL(kTestWebUIUrl), 2732 contents->GetController().LoadURL(GURL(kTestWebUIUrl),
2731 Referrer(), 2733 Referrer(),
2732 ui::PAGE_TRANSITION_TYPED, 2734 ui::PAGE_TRANSITION_TYPED,
2733 std::string()); 2735 std::string());
2734 contents->GetMainFrame()->PrepareForCommit(GURL(kTestWebUIUrl)); 2736 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2737 switches::kEnableBrowserSideNavigation)) {
2738 contents->GetMainFrame()->SendBeforeUnloadACK(true);
2739 }
2735 EXPECT_TRUE(contents->cross_navigation_pending()); 2740 EXPECT_TRUE(contents->cross_navigation_pending());
2736 scoped_refptr<SiteInstance> instance_webui( 2741 scoped_refptr<SiteInstance> instance_webui(
2737 contents->GetPendingMainFrame()->GetSiteInstance()); 2742 contents->GetPendingMainFrame()->GetSiteInstance());
2738 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); 2743 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get()));
2739 2744
2740 // At this point, contents still counts for the old BrowsingInstance. 2745 // At this point, contents still counts for the old BrowsingInstance.
2741 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2746 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2742 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); 2747 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount());
2743 2748
2744 // Commit and contents counts for the new one. 2749 // Commit and contents counts for the new one.
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 frame->SendBeforeUnloadHandlersPresent(false); 3041 frame->SendBeforeUnloadHandlersPresent(false);
3037 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3042 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3038 frame->SendBeforeUnloadHandlersPresent(true); 3043 frame->SendBeforeUnloadHandlersPresent(true);
3039 frame->SendUnloadHandlersPresent(false); 3044 frame->SendUnloadHandlersPresent(false);
3040 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3045 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3041 frame->SendBeforeUnloadHandlersPresent(false); 3046 frame->SendBeforeUnloadHandlersPresent(false);
3042 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3047 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3043 } 3048 }
3044 3049
3045 } // namespace content 3050 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager_unittest.cc ('k') | content/test/test_navigation_url_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698