OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/navigation_controller.h" | 6 #include "chrome/browser/navigation_controller.h" |
7 #include "chrome/browser/navigation_entry.h" | 7 #include "chrome/browser/navigation_entry.h" |
8 #include "chrome/browser/render_view_host.h" | 8 #include "chrome/browser/render_view_host.h" |
9 #include "chrome/browser/render_widget_host_view.h" | 9 #include "chrome/browser/render_widget_host_view.h" |
10 #include "chrome/browser/web_contents.h" | 10 #include "chrome/browser/web_contents.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // alternatives without using command-line switches. | 222 // alternatives without using command-line switches. |
223 bool ShouldTransitionCrossSite() { return transition_cross_site; } | 223 bool ShouldTransitionCrossSite() { return transition_cross_site; } |
224 | 224 |
225 // Promote DidNavigate to public. | 225 // Promote DidNavigate to public. |
226 void TestDidNavigate(TestRenderViewHost* render_view_host, | 226 void TestDidNavigate(TestRenderViewHost* render_view_host, |
227 const ViewHostMsg_FrameNavigate_Params& params) { | 227 const ViewHostMsg_FrameNavigate_Params& params) { |
228 DidNavigate(render_view_host, params); | 228 DidNavigate(render_view_host, params); |
229 render_view_host->is_loading = false; | 229 render_view_host->is_loading = false; |
230 } | 230 } |
231 | 231 |
232 // Promote IsInPageNavigation to public. | |
233 bool TestIsInPageNavigation(const GURL& url) { | |
234 return IsInPageNavigation(url); | |
235 } | |
236 | |
237 // Promote GetWebkitPrefs to public. | 232 // Promote GetWebkitPrefs to public. |
238 WebPreferences TestGetWebkitPrefs() { | 233 WebPreferences TestGetWebkitPrefs() { |
239 return GetWebkitPrefs(); | 234 return GetWebkitPrefs(); |
240 } | 235 } |
241 | 236 |
242 // Prevent interaction with views. | 237 // Prevent interaction with views. |
243 bool CreateRenderViewForRenderManager(RenderViewHost* render_view_host) { | 238 bool CreateRenderViewForRenderManager(RenderViewHost* render_view_host) { |
244 // This will go to a TestRenderViewHost. | 239 // This will go to a TestRenderViewHost. |
245 render_view_host->CreateRenderView(); | 240 render_view_host->CreateRenderView(); |
246 return true; | 241 return true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 MessageLoop::current()->RunAllPending(); | 289 MessageLoop::current()->RunAllPending(); |
295 } | 290 } |
296 | 291 |
297 scoped_ptr<WebContentsTestingProfile> profile; | 292 scoped_ptr<WebContentsTestingProfile> profile; |
298 TestWebContents* contents; | 293 TestWebContents* contents; |
299 | 294 |
300 private: | 295 private: |
301 MessageLoopForUI message_loop_; | 296 MessageLoopForUI message_loop_; |
302 }; | 297 }; |
303 | 298 |
304 // Test to make sure that title updates get stripped of whitespace | 299 // Test to make sure that title updates get stripped of whitespace. |
305 TEST_F(WebContentsTest, OnMessageReceived) { | 300 TEST_F(WebContentsTest, UpdateTitle) { |
| 301 ViewHostMsg_FrameNavigate_Params params; |
| 302 InitNavigateParams(¶ms, 0, GURL("about:blank")); |
| 303 |
306 NavigationController::LoadCommittedDetails details; | 304 NavigationController::LoadCommittedDetails details; |
307 contents->controller()->DidNavigateToEntry(new NavigationEntry( | 305 contents->controller()->RendererDidNavigate(params, false, &details); |
308 contents->type(), contents->site_instance(), 0, GURL("about:blank"), | |
309 std::wstring(), PageTransition::TYPED), &details); | |
310 | 306 |
311 contents->UpdateTitle(NULL, 0, L" Lots O' Whitespace\n"); | 307 contents->UpdateTitle(NULL, 0, L" Lots O' Whitespace\n"); |
312 EXPECT_EQ(std::wstring(L"Lots O' Whitespace"), contents->GetTitle()); | 308 EXPECT_EQ(std::wstring(L"Lots O' Whitespace"), contents->GetTitle()); |
313 } | 309 } |
314 | 310 |
315 // Test simple same-SiteInstance navigation. | 311 // Test simple same-SiteInstance navigation. |
316 TEST_F(WebContentsTest, SimpleNavigation) { | 312 TEST_F(WebContentsTest, SimpleNavigation) { |
317 TestRenderViewHost* orig_rvh = contents->rvh(); | 313 TestRenderViewHost* orig_rvh = contents->rvh(); |
318 SiteInstance* instance1 = contents->site_instance(); | 314 SiteInstance* instance1 = contents->GetSiteInstance(); |
319 EXPECT_TRUE(contents->pending_rvh() == NULL); | 315 EXPECT_TRUE(contents->pending_rvh() == NULL); |
320 EXPECT_TRUE(contents->original_rvh() == NULL); | 316 EXPECT_TRUE(contents->original_rvh() == NULL); |
321 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 317 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
322 EXPECT_FALSE(orig_rvh->is_loading); | 318 EXPECT_FALSE(orig_rvh->is_loading); |
323 | 319 |
324 // Navigate to URL | 320 // Navigate to URL |
325 const GURL url("http://www.google.com"); | 321 const GURL url("http://www.google.com"); |
326 contents->controller()->LoadURL(url, PageTransition::TYPED); | 322 contents->controller()->LoadURL(url, PageTransition::TYPED); |
327 EXPECT_TRUE(contents->state_is_normal()); | 323 EXPECT_TRUE(contents->state_is_normal()); |
328 EXPECT_TRUE(orig_rvh->is_loading); | 324 EXPECT_TRUE(orig_rvh->is_loading); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 574 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
579 } | 575 } |
580 | 576 |
581 // Test that navigating across a site boundary creates a new RenderViewHost | 577 // Test that navigating across a site boundary creates a new RenderViewHost |
582 // with a new SiteInstance. Going back should do the same. | 578 // with a new SiteInstance. Going back should do the same. |
583 TEST_F(WebContentsTest, CrossSiteBoundaries) { | 579 TEST_F(WebContentsTest, CrossSiteBoundaries) { |
584 contents->transition_cross_site = true; | 580 contents->transition_cross_site = true; |
585 TestRenderViewHost* orig_rvh = contents->rvh(); | 581 TestRenderViewHost* orig_rvh = contents->rvh(); |
586 int orig_rvh_delete_count = 0; | 582 int orig_rvh_delete_count = 0; |
587 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 583 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
588 SiteInstance* instance1 = contents->site_instance(); | 584 SiteInstance* instance1 = contents->GetSiteInstance(); |
589 | 585 |
590 // Navigate to URL. First URL should use first RenderViewHost. | 586 // Navigate to URL. First URL should use first RenderViewHost. |
591 const GURL url("http://www.google.com"); | 587 const GURL url("http://www.google.com"); |
592 contents->controller()->LoadURL(url, PageTransition::TYPED); | 588 contents->controller()->LoadURL(url, PageTransition::TYPED); |
593 ViewHostMsg_FrameNavigate_Params params1; | 589 ViewHostMsg_FrameNavigate_Params params1; |
594 InitNavigateParams(¶ms1, 1, url); | 590 InitNavigateParams(¶ms1, 1, url); |
595 contents->TestDidNavigate(orig_rvh, params1); | 591 contents->TestDidNavigate(orig_rvh, params1); |
596 | 592 |
597 EXPECT_TRUE(contents->state_is_normal()); | 593 EXPECT_TRUE(contents->state_is_normal()); |
598 EXPECT_EQ(orig_rvh, contents->render_view_host()); | 594 EXPECT_EQ(orig_rvh, contents->render_view_host()); |
599 EXPECT_TRUE(contents->original_rvh() == NULL); | 595 EXPECT_TRUE(contents->original_rvh() == NULL); |
600 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 596 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
601 | 597 |
602 // Navigate to new site | 598 // Navigate to new site |
603 const GURL url2("http://www.yahoo.com"); | 599 const GURL url2("http://www.yahoo.com"); |
604 contents->controller()->LoadURL(url2, PageTransition::TYPED); | 600 contents->controller()->LoadURL(url2, PageTransition::TYPED); |
605 EXPECT_TRUE(contents->state_is_pending()); | 601 EXPECT_TRUE(contents->state_is_pending()); |
606 TestRenderViewHost* pending_rvh = contents->pending_rvh(); | 602 TestRenderViewHost* pending_rvh = contents->pending_rvh(); |
607 int pending_rvh_delete_count = 0; | 603 int pending_rvh_delete_count = 0; |
608 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 604 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
609 | 605 |
610 // DidNavigate from the pending page | 606 // DidNavigate from the pending page |
611 ViewHostMsg_FrameNavigate_Params params2; | 607 ViewHostMsg_FrameNavigate_Params params2; |
612 InitNavigateParams(¶ms2, 1, url2); | 608 InitNavigateParams(¶ms2, 1, url2); |
613 contents->TestDidNavigate(pending_rvh, params2); | 609 contents->TestDidNavigate(pending_rvh, params2); |
614 SiteInstance* instance2 = contents->site_instance(); | 610 SiteInstance* instance2 = contents->GetSiteInstance(); |
615 | 611 |
616 EXPECT_TRUE(contents->state_is_normal()); | 612 EXPECT_TRUE(contents->state_is_normal()); |
617 EXPECT_EQ(pending_rvh, contents->render_view_host()); | 613 EXPECT_EQ(pending_rvh, contents->render_view_host()); |
618 EXPECT_NE(instance1, instance2); | 614 EXPECT_NE(instance1, instance2); |
619 EXPECT_TRUE(contents->pending_rvh() == NULL); | 615 EXPECT_TRUE(contents->pending_rvh() == NULL); |
620 EXPECT_TRUE(contents->original_rvh() == NULL); | 616 EXPECT_TRUE(contents->original_rvh() == NULL); |
621 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 617 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
622 EXPECT_EQ(orig_rvh_delete_count, 1); | 618 EXPECT_EQ(orig_rvh_delete_count, 1); |
623 | 619 |
624 // Going back should switch SiteInstances again. The first SiteInstance is | 620 // Going back should switch SiteInstances again. The first SiteInstance is |
625 // stored in the NavigationEntry, so it should be the same as at the start. | 621 // stored in the NavigationEntry, so it should be the same as at the start. |
626 contents->controller()->GoBack(); | 622 contents->controller()->GoBack(); |
627 TestRenderViewHost* goback_rvh = contents->pending_rvh(); | 623 TestRenderViewHost* goback_rvh = contents->pending_rvh(); |
628 EXPECT_TRUE(contents->state_is_pending()); | 624 EXPECT_TRUE(contents->state_is_pending()); |
629 | 625 |
630 // DidNavigate from the back action | 626 // DidNavigate from the back action |
631 contents->TestDidNavigate(goback_rvh, params1); | 627 contents->TestDidNavigate(goback_rvh, params1); |
632 EXPECT_TRUE(contents->state_is_normal()); | 628 EXPECT_TRUE(contents->state_is_normal()); |
633 EXPECT_EQ(goback_rvh, contents->render_view_host()); | 629 EXPECT_EQ(goback_rvh, contents->render_view_host()); |
634 EXPECT_EQ(pending_rvh_delete_count, 1); | 630 EXPECT_EQ(pending_rvh_delete_count, 1); |
635 EXPECT_EQ(instance1, contents->site_instance()); | 631 EXPECT_EQ(instance1, contents->GetSiteInstance()); |
636 } | 632 } |
637 | 633 |
638 // Test that navigating across a site boundary after a crash creates a new | 634 // Test that navigating across a site boundary after a crash creates a new |
639 // RVH without requiring a cross-site transition (i.e., PENDING state). | 635 // RVH without requiring a cross-site transition (i.e., PENDING state). |
640 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) { | 636 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) { |
641 contents->transition_cross_site = true; | 637 contents->transition_cross_site = true; |
642 TestRenderViewHost* orig_rvh = contents->rvh(); | 638 TestRenderViewHost* orig_rvh = contents->rvh(); |
643 int orig_rvh_delete_count = 0; | 639 int orig_rvh_delete_count = 0; |
644 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 640 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
645 SiteInstance* instance1 = contents->site_instance(); | 641 SiteInstance* instance1 = contents->GetSiteInstance(); |
646 | 642 |
647 // Navigate to URL. First URL should use first RenderViewHost. | 643 // Navigate to URL. First URL should use first RenderViewHost. |
648 const GURL url("http://www.google.com"); | 644 const GURL url("http://www.google.com"); |
649 contents->controller()->LoadURL(url, PageTransition::TYPED); | 645 contents->controller()->LoadURL(url, PageTransition::TYPED); |
650 ViewHostMsg_FrameNavigate_Params params1; | 646 ViewHostMsg_FrameNavigate_Params params1; |
651 InitNavigateParams(¶ms1, 1, url); | 647 InitNavigateParams(¶ms1, 1, url); |
652 contents->TestDidNavigate(orig_rvh, params1); | 648 contents->TestDidNavigate(orig_rvh, params1); |
653 | 649 |
654 EXPECT_TRUE(contents->state_is_normal()); | 650 EXPECT_TRUE(contents->state_is_normal()); |
655 EXPECT_EQ(orig_rvh, contents->render_view_host()); | 651 EXPECT_EQ(orig_rvh, contents->render_view_host()); |
(...skipping 11 matching lines...) Expand all Loading... |
667 EXPECT_TRUE(contents->pending_rvh() == NULL); | 663 EXPECT_TRUE(contents->pending_rvh() == NULL); |
668 EXPECT_TRUE(contents->original_rvh() == NULL); | 664 EXPECT_TRUE(contents->original_rvh() == NULL); |
669 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 665 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
670 EXPECT_NE(orig_rvh, new_rvh); | 666 EXPECT_NE(orig_rvh, new_rvh); |
671 EXPECT_EQ(orig_rvh_delete_count, 1); | 667 EXPECT_EQ(orig_rvh_delete_count, 1); |
672 | 668 |
673 // DidNavigate from the new page | 669 // DidNavigate from the new page |
674 ViewHostMsg_FrameNavigate_Params params2; | 670 ViewHostMsg_FrameNavigate_Params params2; |
675 InitNavigateParams(¶ms2, 1, url2); | 671 InitNavigateParams(¶ms2, 1, url2); |
676 contents->TestDidNavigate(new_rvh, params2); | 672 contents->TestDidNavigate(new_rvh, params2); |
677 SiteInstance* instance2 = contents->site_instance(); | 673 SiteInstance* instance2 = contents->GetSiteInstance(); |
678 | 674 |
679 EXPECT_TRUE(contents->state_is_normal()); | 675 EXPECT_TRUE(contents->state_is_normal()); |
680 EXPECT_EQ(new_rvh, contents->render_view_host()); | 676 EXPECT_EQ(new_rvh, contents->render_view_host()); |
681 EXPECT_NE(instance1, instance2); | 677 EXPECT_NE(instance1, instance2); |
682 EXPECT_TRUE(contents->pending_rvh() == NULL); | 678 EXPECT_TRUE(contents->pending_rvh() == NULL); |
683 EXPECT_TRUE(contents->original_rvh() == NULL); | 679 EXPECT_TRUE(contents->original_rvh() == NULL); |
684 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 680 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
685 } | 681 } |
686 | 682 |
687 // Test state transitions when showing an interstitial in the new process | 683 // Test state transitions when showing an interstitial in the new process |
688 // model, and then choosing DontProceed. | 684 // model, and then choosing DontProceed. |
689 TEST_F(WebContentsTest, CrossSiteInterstitialDontProceed) { | 685 TEST_F(WebContentsTest, CrossSiteInterstitialDontProceed) { |
690 contents->transition_cross_site = true; | 686 contents->transition_cross_site = true; |
691 TestRenderViewHost* orig_rvh = contents->rvh(); | 687 TestRenderViewHost* orig_rvh = contents->rvh(); |
692 SiteInstance* instance1 = contents->site_instance(); | 688 SiteInstance* instance1 = contents->GetSiteInstance(); |
693 | 689 |
694 // Navigate to URL. First URL should use first RenderViewHost. | 690 // Navigate to URL. First URL should use first RenderViewHost. |
695 const GURL url("http://www.google.com"); | 691 const GURL url("http://www.google.com"); |
696 contents->controller()->LoadURL(url, PageTransition::TYPED); | 692 contents->controller()->LoadURL(url, PageTransition::TYPED); |
697 ViewHostMsg_FrameNavigate_Params params1; | 693 ViewHostMsg_FrameNavigate_Params params1; |
698 InitNavigateParams(¶ms1, 1, url); | 694 InitNavigateParams(¶ms1, 1, url); |
699 contents->TestDidNavigate(orig_rvh, params1); | 695 contents->TestDidNavigate(orig_rvh, params1); |
700 | 696 |
701 EXPECT_TRUE(contents->state_is_normal()); | 697 EXPECT_TRUE(contents->state_is_normal()); |
702 EXPECT_EQ(orig_rvh, contents->render_view_host()); | 698 EXPECT_EQ(orig_rvh, contents->render_view_host()); |
(...skipping 30 matching lines...) Expand all Loading... |
733 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 729 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
734 } | 730 } |
735 | 731 |
736 // Test state transitions when showing an interstitial in the new process | 732 // Test state transitions when showing an interstitial in the new process |
737 // model, and then choosing Proceed. | 733 // model, and then choosing Proceed. |
738 TEST_F(WebContentsTest, CrossSiteInterstitialProceed) { | 734 TEST_F(WebContentsTest, CrossSiteInterstitialProceed) { |
739 contents->transition_cross_site = true; | 735 contents->transition_cross_site = true; |
740 int orig_rvh_delete_count = 0; | 736 int orig_rvh_delete_count = 0; |
741 TestRenderViewHost* orig_rvh = contents->rvh(); | 737 TestRenderViewHost* orig_rvh = contents->rvh(); |
742 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 738 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
743 SiteInstance* instance1 = contents->site_instance(); | 739 SiteInstance* instance1 = contents->GetSiteInstance(); |
744 | 740 |
745 // Navigate to URL. First URL should use first RenderViewHost. | 741 // Navigate to URL. First URL should use first RenderViewHost. |
746 const GURL url("http://www.google.com"); | 742 const GURL url("http://www.google.com"); |
747 contents->controller()->LoadURL(url, PageTransition::TYPED); | 743 contents->controller()->LoadURL(url, PageTransition::TYPED); |
748 ViewHostMsg_FrameNavigate_Params params1; | 744 ViewHostMsg_FrameNavigate_Params params1; |
749 InitNavigateParams(¶ms1, 1, url); | 745 InitNavigateParams(¶ms1, 1, url); |
750 contents->TestDidNavigate(orig_rvh, params1); | 746 contents->TestDidNavigate(orig_rvh, params1); |
751 | 747 |
752 // Navigate to new site | 748 // Navigate to new site |
753 const GURL url2("https://www.google.com"); | 749 const GURL url2("https://www.google.com"); |
(...skipping 21 matching lines...) Expand all Loading... |
775 EXPECT_TRUE(contents->state_is_leaving_interstitial()); | 771 EXPECT_TRUE(contents->state_is_leaving_interstitial()); |
776 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); | 772 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); |
777 EXPECT_EQ(orig_rvh, contents->original_rvh()); | 773 EXPECT_EQ(orig_rvh, contents->original_rvh()); |
778 EXPECT_EQ(pending_rvh, contents->pending_rvh()); | 774 EXPECT_EQ(pending_rvh, contents->pending_rvh()); |
779 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 775 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
780 | 776 |
781 // DidNavigate from the destination page should transition to new renderer | 777 // DidNavigate from the destination page should transition to new renderer |
782 ViewHostMsg_FrameNavigate_Params params3; | 778 ViewHostMsg_FrameNavigate_Params params3; |
783 InitNavigateParams(¶ms3, 2, url2); | 779 InitNavigateParams(¶ms3, 2, url2); |
784 contents->TestDidNavigate(pending_rvh, params3); | 780 contents->TestDidNavigate(pending_rvh, params3); |
785 SiteInstance* instance2 = contents->site_instance(); | 781 SiteInstance* instance2 = contents->GetSiteInstance(); |
786 EXPECT_TRUE(contents->state_is_normal()); | 782 EXPECT_TRUE(contents->state_is_normal()); |
787 EXPECT_EQ(pending_rvh, contents->render_view_host()); | 783 EXPECT_EQ(pending_rvh, contents->render_view_host()); |
788 EXPECT_TRUE(contents->original_rvh() == NULL); | 784 EXPECT_TRUE(contents->original_rvh() == NULL); |
789 EXPECT_TRUE(contents->pending_rvh() == NULL); | 785 EXPECT_TRUE(contents->pending_rvh() == NULL); |
790 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 786 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
791 EXPECT_NE(instance1, instance2); | 787 EXPECT_NE(instance1, instance2); |
792 EXPECT_EQ(orig_rvh_delete_count, 1); // The original should be gone. | 788 EXPECT_EQ(orig_rvh_delete_count, 1); // The original should be gone. |
793 | 789 |
794 // Since we were viewing a page before, we should be able to go back. | 790 // Since we were viewing a page before, we should be able to go back. |
795 EXPECT_TRUE(contents->controller()->CanGoBack()); | 791 EXPECT_TRUE(contents->controller()->CanGoBack()); |
796 | 792 |
797 // Going back should switch SiteInstances again. The first SiteInstance is | 793 // Going back should switch SiteInstances again. The first SiteInstance is |
798 // stored in the NavigationEntry, so it should be the same as at the start. | 794 // stored in the NavigationEntry, so it should be the same as at the start. |
799 contents->controller()->GoBack(); | 795 contents->controller()->GoBack(); |
800 TestRenderViewHost* goback_rvh = contents->pending_rvh(); | 796 TestRenderViewHost* goback_rvh = contents->pending_rvh(); |
801 EXPECT_TRUE(contents->state_is_pending()); | 797 EXPECT_TRUE(contents->state_is_pending()); |
802 | 798 |
803 // DidNavigate from the back action | 799 // DidNavigate from the back action |
804 contents->TestDidNavigate(goback_rvh, params1); | 800 contents->TestDidNavigate(goback_rvh, params1); |
805 EXPECT_TRUE(contents->state_is_normal()); | 801 EXPECT_TRUE(contents->state_is_normal()); |
806 EXPECT_EQ(goback_rvh, contents->render_view_host()); | 802 EXPECT_EQ(goback_rvh, contents->render_view_host()); |
807 EXPECT_EQ(instance1, contents->site_instance()); | 803 EXPECT_EQ(instance1, contents->GetSiteInstance()); |
808 EXPECT_EQ(pending_rvh_delete_count, 1); // The second page's rvh should die. | 804 EXPECT_EQ(pending_rvh_delete_count, 1); // The second page's rvh should die. |
809 } | 805 } |
810 | 806 |
811 // Tests that we can transition away from an interstitial page. | 807 // Tests that we can transition away from an interstitial page. |
812 TEST_F(WebContentsTest, CrossSiteInterstitialThenNavigate) { | 808 TEST_F(WebContentsTest, CrossSiteInterstitialThenNavigate) { |
813 contents->transition_cross_site = true; | 809 contents->transition_cross_site = true; |
814 int orig_rvh_delete_count = 0; | 810 int orig_rvh_delete_count = 0; |
815 TestRenderViewHost* orig_rvh = contents->rvh(); | 811 TestRenderViewHost* orig_rvh = contents->rvh(); |
816 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 812 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
817 | 813 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 contents->TestDidNavigate(new_rvh, params3); | 976 contents->TestDidNavigate(new_rvh, params3); |
981 EXPECT_TRUE(contents->state_is_normal()); | 977 EXPECT_TRUE(contents->state_is_normal()); |
982 EXPECT_EQ(new_rvh, contents->render_view_host()); | 978 EXPECT_EQ(new_rvh, contents->render_view_host()); |
983 } | 979 } |
984 | 980 |
985 // Test that opening a new tab in the same SiteInstance and then navigating | 981 // Test that opening a new tab in the same SiteInstance and then navigating |
986 // both tabs to a new site will place both tabs in a single SiteInstance. | 982 // both tabs to a new site will place both tabs in a single SiteInstance. |
987 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) { | 983 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) { |
988 contents->transition_cross_site = true; | 984 contents->transition_cross_site = true; |
989 TestRenderViewHost* orig_rvh = contents->rvh(); | 985 TestRenderViewHost* orig_rvh = contents->rvh(); |
990 SiteInstance* instance1 = contents->site_instance(); | 986 SiteInstance* instance1 = contents->GetSiteInstance(); |
991 | 987 |
992 // Navigate to URL. First URL should use first RenderViewHost. | 988 // Navigate to URL. First URL should use first RenderViewHost. |
993 const GURL url("http://www.google.com"); | 989 const GURL url("http://www.google.com"); |
994 contents->controller()->LoadURL(url, PageTransition::TYPED); | 990 contents->controller()->LoadURL(url, PageTransition::TYPED); |
995 ViewHostMsg_FrameNavigate_Params params1; | 991 ViewHostMsg_FrameNavigate_Params params1; |
996 InitNavigateParams(¶ms1, 1, url); | 992 InitNavigateParams(¶ms1, 1, url); |
997 contents->TestDidNavigate(orig_rvh, params1); | 993 contents->TestDidNavigate(orig_rvh, params1); |
998 | 994 |
999 // Open a new tab with the same SiteInstance, navigated to the same site. | 995 // Open a new tab with the same SiteInstance, navigated to the same site. |
1000 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); | 996 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); |
1001 contents2->transition_cross_site = true; | 997 contents2->transition_cross_site = true; |
1002 contents2->SetupController(profile.get()); | 998 contents2->SetupController(profile.get()); |
1003 contents2->controller()->LoadURL(url, PageTransition::TYPED); | 999 contents2->controller()->LoadURL(url, PageTransition::TYPED); |
1004 contents2->TestDidNavigate(contents2->rvh(), params1); | 1000 contents2->TestDidNavigate(contents2->rvh(), params1); |
1005 | 1001 |
1006 // Navigate first tab to a new site | 1002 // Navigate first tab to a new site |
1007 const GURL url2a("http://www.yahoo.com"); | 1003 const GURL url2a("http://www.yahoo.com"); |
1008 contents->controller()->LoadURL(url2a, PageTransition::TYPED); | 1004 contents->controller()->LoadURL(url2a, PageTransition::TYPED); |
1009 TestRenderViewHost* pending_rvh_a = contents->pending_rvh(); | 1005 TestRenderViewHost* pending_rvh_a = contents->pending_rvh(); |
1010 ViewHostMsg_FrameNavigate_Params params2a; | 1006 ViewHostMsg_FrameNavigate_Params params2a; |
1011 InitNavigateParams(¶ms2a, 1, url2a); | 1007 InitNavigateParams(¶ms2a, 1, url2a); |
1012 contents->TestDidNavigate(pending_rvh_a, params2a); | 1008 contents->TestDidNavigate(pending_rvh_a, params2a); |
1013 SiteInstance* instance2a = contents->site_instance(); | 1009 SiteInstance* instance2a = contents->GetSiteInstance(); |
1014 EXPECT_NE(instance1, instance2a); | 1010 EXPECT_NE(instance1, instance2a); |
1015 | 1011 |
1016 // Navigate second tab to the same site as the first tab | 1012 // Navigate second tab to the same site as the first tab |
1017 const GURL url2b("http://mail.yahoo.com"); | 1013 const GURL url2b("http://mail.yahoo.com"); |
1018 contents2->controller()->LoadURL(url2b, PageTransition::TYPED); | 1014 contents2->controller()->LoadURL(url2b, PageTransition::TYPED); |
1019 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh(); | 1015 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh(); |
1020 EXPECT_TRUE(pending_rvh_b != NULL); | 1016 EXPECT_TRUE(pending_rvh_b != NULL); |
1021 EXPECT_TRUE(contents2->state_is_pending()); | 1017 EXPECT_TRUE(contents2->state_is_pending()); |
1022 | 1018 |
1023 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 1019 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
1024 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 1020 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
1025 // now covered by the CrossSiteBoundariesAfterCrash test. | 1021 // now covered by the CrossSiteBoundariesAfterCrash test. |
1026 | 1022 |
1027 ViewHostMsg_FrameNavigate_Params params2b; | 1023 ViewHostMsg_FrameNavigate_Params params2b; |
1028 InitNavigateParams(¶ms2b, 2, url2b); | 1024 InitNavigateParams(¶ms2b, 2, url2b); |
1029 contents2->TestDidNavigate(pending_rvh_b, params2b); | 1025 contents2->TestDidNavigate(pending_rvh_b, params2b); |
1030 SiteInstance* instance2b = contents2->site_instance(); | 1026 SiteInstance* instance2b = contents2->GetSiteInstance(); |
1031 EXPECT_NE(instance1, instance2b); | 1027 EXPECT_NE(instance1, instance2b); |
1032 | 1028 |
1033 // Both tabs should now be in the same SiteInstance. | 1029 // Both tabs should now be in the same SiteInstance. |
1034 EXPECT_EQ(instance2a, instance2b); | 1030 EXPECT_EQ(instance2a, instance2b); |
1035 | 1031 |
1036 contents2->CloseContents(); | 1032 contents2->CloseContents(); |
1037 } | 1033 } |
1038 | 1034 |
1039 // Tests that WebContents uses the current URL, not the SiteInstance's site, to | 1035 // Tests that WebContents uses the current URL, not the SiteInstance's site, to |
1040 // determine whether a navigation is cross-site. | 1036 // determine whether a navigation is cross-site. |
1041 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) { | 1037 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) { |
1042 contents->transition_cross_site = true; | 1038 contents->transition_cross_site = true; |
1043 TestRenderViewHost* orig_rvh = contents->rvh(); | 1039 TestRenderViewHost* orig_rvh = contents->rvh(); |
1044 SiteInstance* instance1 = contents->site_instance(); | 1040 SiteInstance* instance1 = contents->GetSiteInstance(); |
1045 | 1041 |
1046 // Navigate to URL. | 1042 // Navigate to URL. |
1047 const GURL url("http://www.google.com"); | 1043 const GURL url("http://www.google.com"); |
1048 contents->controller()->LoadURL(url, PageTransition::TYPED); | 1044 contents->controller()->LoadURL(url, PageTransition::TYPED); |
1049 ViewHostMsg_FrameNavigate_Params params1; | 1045 ViewHostMsg_FrameNavigate_Params params1; |
1050 InitNavigateParams(¶ms1, 1, url); | 1046 InitNavigateParams(¶ms1, 1, url); |
1051 contents->TestDidNavigate(orig_rvh, params1); | 1047 contents->TestDidNavigate(orig_rvh, params1); |
1052 | 1048 |
1053 // Open a related tab to a second site. | 1049 // Open a related tab to a second site. |
1054 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); | 1050 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); |
1055 contents2->transition_cross_site = true; | 1051 contents2->transition_cross_site = true; |
1056 contents2->SetupController(profile.get()); | 1052 contents2->SetupController(profile.get()); |
1057 const GURL url2("http://www.yahoo.com"); | 1053 const GURL url2("http://www.yahoo.com"); |
1058 contents2->controller()->LoadURL(url2, PageTransition::TYPED); | 1054 contents2->controller()->LoadURL(url2, PageTransition::TYPED); |
1059 // The first RVH in contents2 isn't live yet, so we shortcut the PENDING | 1055 // The first RVH in contents2 isn't live yet, so we shortcut the PENDING |
1060 // state and go straight to NORMAL. | 1056 // state and go straight to NORMAL. |
1061 TestRenderViewHost* rvh2 = contents2->rvh(); | 1057 TestRenderViewHost* rvh2 = contents2->rvh(); |
1062 EXPECT_TRUE(contents2->state_is_normal()); | 1058 EXPECT_TRUE(contents2->state_is_normal()); |
1063 ViewHostMsg_FrameNavigate_Params params2; | 1059 ViewHostMsg_FrameNavigate_Params params2; |
1064 InitNavigateParams(¶ms2, 2, url2); | 1060 InitNavigateParams(¶ms2, 2, url2); |
1065 contents2->TestDidNavigate(rvh2, params2); | 1061 contents2->TestDidNavigate(rvh2, params2); |
1066 SiteInstance* instance2 = contents2->site_instance(); | 1062 SiteInstance* instance2 = contents2->GetSiteInstance(); |
1067 EXPECT_NE(instance1, instance2); | 1063 EXPECT_NE(instance1, instance2); |
1068 EXPECT_TRUE(contents2->state_is_normal()); | 1064 EXPECT_TRUE(contents2->state_is_normal()); |
1069 | 1065 |
1070 // Simulate a link click in first tab to second site. Doesn't switch | 1066 // Simulate a link click in first tab to second site. Doesn't switch |
1071 // SiteInstances, because we don't intercept WebKit navigations. | 1067 // SiteInstances, because we don't intercept WebKit navigations. |
1072 ViewHostMsg_FrameNavigate_Params params3; | 1068 ViewHostMsg_FrameNavigate_Params params3; |
1073 InitNavigateParams(¶ms3, 2, url2); | 1069 InitNavigateParams(¶ms3, 2, url2); |
1074 contents->TestDidNavigate(orig_rvh, params3); | 1070 contents->TestDidNavigate(orig_rvh, params3); |
1075 SiteInstance* instance3 = contents->site_instance(); | 1071 SiteInstance* instance3 = contents->GetSiteInstance(); |
1076 EXPECT_EQ(instance1, instance3); | 1072 EXPECT_EQ(instance1, instance3); |
1077 EXPECT_TRUE(contents->state_is_normal()); | 1073 EXPECT_TRUE(contents->state_is_normal()); |
1078 | 1074 |
1079 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 1075 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
1080 // compare against the current URL, not the SiteInstance's site. | 1076 // compare against the current URL, not the SiteInstance's site. |
1081 const GURL url3("http://mail.yahoo.com"); | 1077 const GURL url3("http://mail.yahoo.com"); |
1082 contents->controller()->LoadURL(url3, PageTransition::TYPED); | 1078 contents->controller()->LoadURL(url3, PageTransition::TYPED); |
1083 EXPECT_TRUE(contents->state_is_normal()); | 1079 EXPECT_TRUE(contents->state_is_normal()); |
1084 ViewHostMsg_FrameNavigate_Params params4; | 1080 ViewHostMsg_FrameNavigate_Params params4; |
1085 InitNavigateParams(¶ms4, 3, url3); | 1081 InitNavigateParams(¶ms4, 3, url3); |
1086 contents->TestDidNavigate(orig_rvh, params4); | 1082 contents->TestDidNavigate(orig_rvh, params4); |
1087 SiteInstance* instance4 = contents->site_instance(); | 1083 SiteInstance* instance4 = contents->GetSiteInstance(); |
1088 EXPECT_EQ(instance1, instance4); | 1084 EXPECT_EQ(instance1, instance4); |
1089 | 1085 |
1090 contents2->CloseContents(); | 1086 contents2->CloseContents(); |
1091 } | 1087 } |
1092 | 1088 |
1093 // Test that the onbeforeunload and onunload handlers run when navigating | 1089 // Test that the onbeforeunload and onunload handlers run when navigating |
1094 // across site boundaries. | 1090 // across site boundaries. |
1095 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) { | 1091 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) { |
1096 contents->transition_cross_site = true; | 1092 contents->transition_cross_site = true; |
1097 TestRenderViewHost* orig_rvh = contents->rvh(); | 1093 TestRenderViewHost* orig_rvh = contents->rvh(); |
1098 SiteInstance* instance1 = contents->site_instance(); | 1094 SiteInstance* instance1 = contents->GetSiteInstance(); |
1099 | 1095 |
1100 // Navigate to URL. First URL should use first RenderViewHost. | 1096 // Navigate to URL. First URL should use first RenderViewHost. |
1101 const GURL url("http://www.google.com"); | 1097 const GURL url("http://www.google.com"); |
1102 contents->controller()->LoadURL(url, PageTransition::TYPED); | 1098 contents->controller()->LoadURL(url, PageTransition::TYPED); |
1103 ViewHostMsg_FrameNavigate_Params params1; | 1099 ViewHostMsg_FrameNavigate_Params params1; |
1104 InitNavigateParams(¶ms1, 1, url); | 1100 InitNavigateParams(¶ms1, 1, url); |
1105 contents->TestDidNavigate(orig_rvh, params1); | 1101 contents->TestDidNavigate(orig_rvh, params1); |
1106 EXPECT_TRUE(contents->state_is_normal()); | 1102 EXPECT_TRUE(contents->state_is_normal()); |
1107 EXPECT_EQ(orig_rvh, contents->render_view_host()); | 1103 EXPECT_EQ(orig_rvh, contents->render_view_host()); |
1108 | 1104 |
(...skipping 12 matching lines...) Expand all Loading... |
1121 TestRenderViewHost* pending_rvh = contents->pending_rvh(); | 1117 TestRenderViewHost* pending_rvh = contents->pending_rvh(); |
1122 | 1118 |
1123 // We won't hear DidNavigate until the onunload handler has finished running. | 1119 // We won't hear DidNavigate until the onunload handler has finished running. |
1124 // (No way to simulate that here, but it involves a call from RDH to | 1120 // (No way to simulate that here, but it involves a call from RDH to |
1125 // WebContents::OnCrossSiteResponse.) | 1121 // WebContents::OnCrossSiteResponse.) |
1126 | 1122 |
1127 // DidNavigate from the pending page | 1123 // DidNavigate from the pending page |
1128 ViewHostMsg_FrameNavigate_Params params2; | 1124 ViewHostMsg_FrameNavigate_Params params2; |
1129 InitNavigateParams(¶ms2, 1, url2); | 1125 InitNavigateParams(¶ms2, 1, url2); |
1130 contents->TestDidNavigate(pending_rvh, params2); | 1126 contents->TestDidNavigate(pending_rvh, params2); |
1131 SiteInstance* instance2 = contents->site_instance(); | 1127 SiteInstance* instance2 = contents->GetSiteInstance(); |
1132 EXPECT_TRUE(contents->state_is_normal()); | 1128 EXPECT_TRUE(contents->state_is_normal()); |
1133 EXPECT_EQ(pending_rvh, contents->render_view_host()); | 1129 EXPECT_EQ(pending_rvh, contents->render_view_host()); |
1134 EXPECT_NE(instance1, instance2); | 1130 EXPECT_NE(instance1, instance2); |
1135 EXPECT_TRUE(contents->pending_rvh() == NULL); | 1131 EXPECT_TRUE(contents->pending_rvh() == NULL); |
1136 EXPECT_TRUE(contents->original_rvh() == NULL); | 1132 EXPECT_TRUE(contents->original_rvh() == NULL); |
1137 EXPECT_TRUE(contents->interstitial_rvh() == NULL); | 1133 EXPECT_TRUE(contents->interstitial_rvh() == NULL); |
1138 } | 1134 } |
1139 | 1135 |
1140 // Test that NavigationEntries have the correct content state after going | 1136 // Test that NavigationEntries have the correct content state after going |
1141 // forward and back. Prevents regression for bug 1116137. | 1137 // forward and back. Prevents regression for bug 1116137. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 ViewHostMsg_FrameNavigate_Params params1; | 1182 ViewHostMsg_FrameNavigate_Params params1; |
1187 InitNavigateParams(¶ms1, 1, url); | 1183 InitNavigateParams(¶ms1, 1, url); |
1188 contents->TestDidNavigate(orig_rvh, params1); | 1184 contents->TestDidNavigate(orig_rvh, params1); |
1189 contents->TestDidNavigate(orig_rvh, params1); | 1185 contents->TestDidNavigate(orig_rvh, params1); |
1190 | 1186 |
1191 // Should have a content state here. | 1187 // Should have a content state here. |
1192 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry(); | 1188 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry(); |
1193 EXPECT_FALSE(entry->content_state().empty()); | 1189 EXPECT_FALSE(entry->content_state().empty()); |
1194 } | 1190 } |
1195 | 1191 |
1196 // Tests that IsInPageNavigation returns appropriate results. Prevents | |
1197 // regression for bug 1126349. | |
1198 TEST_F(WebContentsTest, IsInPageNavigation) { | |
1199 TestRenderViewHost* rvh = contents->rvh(); | |
1200 | |
1201 // Navigate to URL with no refs. | |
1202 const GURL url("http://www.google.com/home.html"); | |
1203 contents->controller()->LoadURL(url, PageTransition::TYPED); | |
1204 ViewHostMsg_FrameNavigate_Params params; | |
1205 InitNavigateParams(¶ms, 1, url); | |
1206 contents->TestDidNavigate(rvh, params); | |
1207 | |
1208 // Reloading the page is not an in-page navigation. | |
1209 EXPECT_FALSE(contents->TestIsInPageNavigation(url)); | |
1210 const GURL other_url("http://www.google.com/add.html"); | |
1211 EXPECT_FALSE(contents->TestIsInPageNavigation(other_url)); | |
1212 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | |
1213 EXPECT_TRUE(contents->TestIsInPageNavigation(url_with_ref)); | |
1214 | |
1215 // Navigate to URL with refs. | |
1216 contents->controller()->LoadURL(url_with_ref, PageTransition::TYPED); | |
1217 InitNavigateParams(¶ms, 2, url_with_ref); | |
1218 contents->TestDidNavigate(rvh, params); | |
1219 | |
1220 // Reloading the page is not an in-page navigation. | |
1221 EXPECT_FALSE(contents->TestIsInPageNavigation(url_with_ref)); | |
1222 EXPECT_FALSE(contents->TestIsInPageNavigation(url)); | |
1223 EXPECT_FALSE(contents->TestIsInPageNavigation(other_url)); | |
1224 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | |
1225 EXPECT_TRUE(contents->TestIsInPageNavigation(other_url_with_ref)); | |
1226 } | |
1227 | |
1228 // Tests to see that webkit preferences are properly loaded and copied over | 1192 // Tests to see that webkit preferences are properly loaded and copied over |
1229 // to a WebPreferences object. | 1193 // to a WebPreferences object. |
1230 TEST_F(WebContentsTest, WebKitPrefs) { | 1194 TEST_F(WebContentsTest, WebKitPrefs) { |
1231 WebPreferences webkit_prefs = contents->TestGetWebkitPrefs(); | 1195 WebPreferences webkit_prefs = contents->TestGetWebkitPrefs(); |
1232 | 1196 |
1233 // These values have been overridden by the profile preferences. | 1197 // These values have been overridden by the profile preferences. |
1234 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding); | 1198 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding); |
1235 EXPECT_EQ(20, webkit_prefs.default_font_size); | 1199 EXPECT_EQ(20, webkit_prefs.default_font_size); |
1236 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable); | 1200 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable); |
1237 EXPECT_EQ(true, webkit_prefs.uses_universal_detector); | 1201 EXPECT_EQ(true, webkit_prefs.uses_universal_detector); |
1238 | 1202 |
1239 // These should still be the default values. | 1203 // These should still be the default values. |
1240 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); | 1204 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); |
1241 EXPECT_EQ(true, webkit_prefs.javascript_enabled); | 1205 EXPECT_EQ(true, webkit_prefs.javascript_enabled); |
1242 } | 1206 } |
1243 | 1207 |
OLD | NEW |