| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/prefs/pref_value_store.h" | 10 #include "chrome/browser/prefs/pref_value_store.h" |
| 11 #include "chrome/common/bindings_policy.h" |
| 11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.h" |
| 15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/testing_pref_service.h" | 17 #include "chrome/test/testing_pref_service.h" |
| 17 #include "chrome/test/testing_profile.h" | 18 #include "chrome/test/testing_profile.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_view.h" | 21 #include "content/browser/renderer_host/render_widget_host_view.h" |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 570 |
| 570 // Verify that the pending navigation is cancelled. | 571 // Verify that the pending navigation is cancelled. |
| 571 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 572 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
| 572 SiteInstance* instance2 = contents()->GetSiteInstance(); | 573 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 573 EXPECT_FALSE(contents()->cross_navigation_pending()); | 574 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 574 EXPECT_EQ(orig_rvh, rvh()); | 575 EXPECT_EQ(orig_rvh, rvh()); |
| 575 EXPECT_EQ(instance1, instance2); | 576 EXPECT_EQ(instance1, instance2); |
| 576 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 577 EXPECT_TRUE(contents()->pending_rvh() == NULL); |
| 577 } | 578 } |
| 578 | 579 |
| 580 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
| 581 contents()->transition_cross_site = true; |
| 582 |
| 583 // Start with NTP, which gets a new RVH with WebUI bindings. |
| 584 const GURL url1("chrome://newtab"); |
| 585 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
| 586 TestRenderViewHost* ntp_rvh = rvh(); |
| 587 ViewHostMsg_FrameNavigate_Params params1; |
| 588 InitNavigateParams(¶ms1, 1, url1); |
| 589 contents()->TestDidNavigate(ntp_rvh, params1); |
| 590 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
| 591 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 592 |
| 593 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 594 EXPECT_EQ(ntp_rvh, contents()->render_view_host()); |
| 595 EXPECT_EQ(url1, entry1->url()); |
| 596 EXPECT_EQ(instance1, entry1->site_instance()); |
| 597 EXPECT_TRUE(BindingsPolicy::is_web_ui_enabled(ntp_rvh->enabled_bindings())); |
| 598 |
| 599 // Navigate to new site. |
| 600 const GURL url2("http://www.google.com"); |
| 601 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
| 602 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 603 TestRenderViewHost* google_rvh = contents()->pending_rvh(); |
| 604 |
| 605 // Simulate beforeunload approval. |
| 606 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
| 607 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 608 |
| 609 // DidNavigate from the pending page. |
| 610 ViewHostMsg_FrameNavigate_Params params2; |
| 611 InitNavigateParams(¶ms2, 1, url2); |
| 612 contents()->TestDidNavigate(google_rvh, params2); |
| 613 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
| 614 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 615 |
| 616 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 617 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
| 618 EXPECT_NE(instance1, instance2); |
| 619 EXPECT_FALSE(contents()->pending_rvh()); |
| 620 EXPECT_EQ(url2, entry2->url()); |
| 621 EXPECT_EQ(instance2, entry2->site_instance()); |
| 622 EXPECT_FALSE(BindingsPolicy::is_web_ui_enabled( |
| 623 google_rvh->enabled_bindings())); |
| 624 |
| 625 // Navigate to third page on same site. |
| 626 const GURL url3("http://news.google.com"); |
| 627 controller().LoadURL(url3, GURL(), PageTransition::TYPED); |
| 628 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 629 ViewHostMsg_FrameNavigate_Params params3; |
| 630 InitNavigateParams(¶ms3, 2, url3); |
| 631 contents()->TestDidNavigate(google_rvh, params3); |
| 632 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
| 633 SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 634 |
| 635 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 636 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
| 637 EXPECT_EQ(instance2, instance3); |
| 638 EXPECT_FALSE(contents()->pending_rvh()); |
| 639 EXPECT_EQ(url3, entry3->url()); |
| 640 EXPECT_EQ(instance3, entry3->site_instance()); |
| 641 |
| 642 // Go back within the site. |
| 643 controller().GoBack(); |
| 644 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 645 EXPECT_EQ(entry2, controller().pending_entry()); |
| 646 |
| 647 // Before that commits, go back again. |
| 648 controller().GoBack(); |
| 649 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 650 EXPECT_TRUE(contents()->pending_rvh()); |
| 651 EXPECT_EQ(entry1, controller().pending_entry()); |
| 652 |
| 653 // Simulate beforeunload approval. |
| 654 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); |
| 655 google_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); |
| 656 |
| 657 // DidNavigate from the first back. This aborts the second back's pending RVH. |
| 658 contents()->TestDidNavigate(google_rvh, params2); |
| 659 |
| 660 // We should commit this page and forget about the second back. |
| 661 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 662 EXPECT_FALSE(controller().pending_entry()); |
| 663 EXPECT_EQ(google_rvh, contents()->render_view_host()); |
| 664 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->url()); |
| 665 |
| 666 // We should not have corrupted the NTP entry. |
| 667 EXPECT_EQ(instance3, entry3->site_instance()); |
| 668 EXPECT_EQ(instance2, entry2->site_instance()); |
| 669 EXPECT_EQ(instance1, entry1->site_instance()); |
| 670 EXPECT_EQ(url1, entry1->url()); |
| 671 } |
| 672 |
| 579 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 673 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
| 580 // original renderer will not cancel the slow navigation (bug 42029). | 674 // original renderer will not cancel the slow navigation (bug 42029). |
| 581 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { | 675 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { |
| 582 contents()->transition_cross_site = true; | 676 contents()->transition_cross_site = true; |
| 583 TestRenderViewHost* orig_rvh = rvh(); | 677 TestRenderViewHost* orig_rvh = rvh(); |
| 584 | 678 |
| 585 // Navigate to URL. First URL should use first RenderViewHost. | 679 // Navigate to URL. First URL should use first RenderViewHost. |
| 586 const GURL url("http://www.google.com"); | 680 const GURL url("http://www.google.com"); |
| 587 controller().LoadURL(url, GURL(), PageTransition::TYPED); | 681 controller().LoadURL(url, GURL(), PageTransition::TYPED); |
| 588 ViewHostMsg_FrameNavigate_Params params1; | 682 ViewHostMsg_FrameNavigate_Params params1; |
| (...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 window.close_count = 0; | 1738 window.close_count = 0; |
| 1645 | 1739 |
| 1646 const int kWindowCount = 4; | 1740 const int kWindowCount = 4; |
| 1647 for (int i = 0; i < kWindowCount; i++) { | 1741 for (int i = 0; i < kWindowCount; i++) { |
| 1648 tab_contents->AddConstrainedDialog(&window); | 1742 tab_contents->AddConstrainedDialog(&window); |
| 1649 } | 1743 } |
| 1650 EXPECT_EQ(window.close_count, 0); | 1744 EXPECT_EQ(window.close_count, 0); |
| 1651 delete tab_contents; | 1745 delete tab_contents; |
| 1652 EXPECT_EQ(window.close_count, kWindowCount); | 1746 EXPECT_EQ(window.close_count, kWindowCount); |
| 1653 } | 1747 } |
| OLD | NEW |