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