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