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

Side by Side Diff: trunk/src/content/browser/web_contents/navigation_controller_impl_unittest.cc

Issue 13966012: Revert 195553 "Allow showing pending URL for new tab navigations..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) { 805 TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) {
806 NavigationControllerImpl& controller = controller_impl(); 806 NavigationControllerImpl& controller = controller_impl();
807 TestNotificationTracker notifications; 807 TestNotificationTracker notifications;
808 RegisterForAllNavNotifications(&notifications, &controller); 808 RegisterForAllNavNotifications(&notifications, &controller);
809 809
810 // Set a WebContentsDelegate to listen for state changes. 810 // Set a WebContentsDelegate to listen for state changes.
811 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 811 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
812 EXPECT_FALSE(contents()->GetDelegate()); 812 EXPECT_FALSE(contents()->GetDelegate());
813 contents()->SetDelegate(delegate.get()); 813 contents()->SetDelegate(delegate.get());
814 814
815 // Start with a pending new navigation. 815 // Without any navigations, the renderer starts at about:blank.
816 const GURL kExistingURL("about:blank");
817
818 // Now make a pending new navigation.
816 const GURL kNewURL("http://eh"); 819 const GURL kNewURL("http://eh");
817 controller.LoadURL( 820 controller.LoadURL(
818 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 821 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string());
819 EXPECT_EQ(0U, notifications.size()); 822 EXPECT_EQ(0U, notifications.size());
820 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 823 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
821 EXPECT_TRUE(controller.GetPendingEntry()); 824 EXPECT_TRUE(controller.GetPendingEntry());
822 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 825 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
823 EXPECT_EQ(1, delegate->navigation_state_change_count()); 826 EXPECT_EQ(1, delegate->navigation_state_change_count());
824 827
825 // It may abort before committing, if it's a download or due to a stop or 828 // It may abort before committing, if it's a download or due to a stop or
826 // a new navigation from the user. 829 // a new navigation from the user.
827 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; 830 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
828 params.frame_id = 1; 831 params.frame_id = 1;
829 params.is_main_frame = true; 832 params.is_main_frame = true;
830 params.error_code = net::ERR_ABORTED; 833 params.error_code = net::ERR_ABORTED;
831 params.error_description = string16(); 834 params.error_description = string16();
832 params.url = kNewURL; 835 params.url = kNewURL;
833 params.showing_repost_interstitial = false; 836 params.showing_repost_interstitial = false;
834 test_rvh()->OnMessageReceived( 837 test_rvh()->OnMessageReceived(
835 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 838 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
836 params)); 839 params));
837 840
838 // This should not clear the pending entry or notify of a navigation state 841 // This should not clear the pending entry or notify of a navigation state
839 // change, so that we keep displaying kNewURL (until the user clears it). 842 // change, so that we keep displaying kNewURL (until the user clears it).
840 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 843 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
841 EXPECT_TRUE(controller.GetPendingEntry()); 844 EXPECT_TRUE(controller.GetPendingEntry());
842 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 845 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
843 EXPECT_EQ(1, delegate->navigation_state_change_count()); 846 EXPECT_EQ(1, delegate->navigation_state_change_count());
844 NavigationEntry* pending_entry = controller.GetPendingEntry();
845
846 // Ensure that a reload keeps the same pending entry.
847 controller.Reload(true);
848 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
849 EXPECT_TRUE(controller.GetPendingEntry());
850 EXPECT_EQ(pending_entry, controller.GetPendingEntry());
851 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
852 847
853 contents()->SetDelegate(NULL); 848 contents()->SetDelegate(NULL);
854 } 849 }
855 850
856 // Tests that the pending URL is not visible during a renderer-initiated 851 // Tests that the pending URL is not visible during a renderer-initiated
857 // redirect and abort. See http://crbug.com/83031. 852 // redirect and abort. See http://crbug.com/83031.
858 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { 853 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
859 NavigationControllerImpl& controller = controller_impl(); 854 NavigationControllerImpl& controller = controller_impl();
860 TestNotificationTracker notifications; 855 TestNotificationTracker notifications;
861 RegisterForAllNavNotifications(&notifications, &controller); 856 RegisterForAllNavNotifications(&notifications, &controller);
862 857
863 // First make an existing committed entry.
864 const GURL kExistingURL("http://foo/eh");
865 controller.LoadURL(kExistingURL, content::Referrer(),
866 content::PAGE_TRANSITION_TYPED, std::string());
867 test_rvh()->SendNavigate(0, kExistingURL);
868 EXPECT_TRUE(notifications.Check1AndReset(
869 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
870
871 // Set a WebContentsDelegate to listen for state changes. 858 // Set a WebContentsDelegate to listen for state changes.
872 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 859 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
873 EXPECT_FALSE(contents()->GetDelegate()); 860 EXPECT_FALSE(contents()->GetDelegate());
874 contents()->SetDelegate(delegate.get()); 861 contents()->SetDelegate(delegate.get());
875 862
863 // Without any navigations, the renderer starts at about:blank.
864 const GURL kExistingURL("about:blank");
865
876 // Now make a pending new navigation, initiated by the renderer. 866 // Now make a pending new navigation, initiated by the renderer.
877 const GURL kNewURL("http://foo/bee"); 867 const GURL kNewURL("http://eh");
878 NavigationController::LoadURLParams load_url_params(kNewURL); 868 NavigationController::LoadURLParams load_url_params(kNewURL);
879 load_url_params.transition_type = PAGE_TRANSITION_TYPED; 869 load_url_params.transition_type = PAGE_TRANSITION_TYPED;
880 load_url_params.is_renderer_initiated = true; 870 load_url_params.is_renderer_initiated = true;
881 controller.LoadURLWithParams(load_url_params); 871 controller.LoadURLWithParams(load_url_params);
882 EXPECT_EQ(0U, notifications.size()); 872 EXPECT_EQ(0U, notifications.size());
883 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 873 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
884 EXPECT_TRUE(controller.GetPendingEntry()); 874 EXPECT_TRUE(controller.GetPendingEntry());
885 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 875 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
886 EXPECT_EQ(0, delegate->navigation_state_change_count()); 876 EXPECT_EQ(1, delegate->navigation_state_change_count());
887 877
888 // The visible entry should be the last committed URL, not the pending one. 878 // There should be no visible entry (resulting in about:blank in the
889 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL()); 879 // omnibox), because it was renderer-initiated and there's no last committed
880 // entry.
881 EXPECT_FALSE(controller.GetVisibleEntry());
890 882
891 // Now the navigation redirects. 883 // Now the navigation redirects.
892 const GURL kRedirectURL("http://foo/see"); 884 const GURL kRedirectURL("http://bee");
893 test_rvh()->OnMessageReceived( 885 test_rvh()->OnMessageReceived(
894 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id 886 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id
895 -1, // pending page_id 887 -1, // pending page_id
896 kNewURL, // old url 888 kNewURL, // old url
897 kRedirectURL)); // new url 889 kRedirectURL)); // new url
898 890
899 // We don't want to change the NavigationEntry's url, in case it cancels. 891 // We don't want to change the NavigationEntry's url, in case it cancels.
900 // Prevents regression of http://crbug.com/77786. 892 // Prevents regression of http://crbug.com/77786.
901 EXPECT_EQ(kNewURL, controller.GetPendingEntry()->GetURL()); 893 EXPECT_EQ(kNewURL, controller.GetPendingEntry()->GetURL());
902 894
903 // It may abort before committing, if it's a download or due to a stop or 895 // It may abort before committing, if it's a download or due to a stop or
904 // a new navigation from the user. 896 // a new navigation from the user.
905 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; 897 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
906 params.frame_id = 1; 898 params.frame_id = 1;
907 params.is_main_frame = true; 899 params.is_main_frame = true;
908 params.error_code = net::ERR_ABORTED; 900 params.error_code = net::ERR_ABORTED;
909 params.error_description = string16(); 901 params.error_description = string16();
910 params.url = kRedirectURL; 902 params.url = kRedirectURL;
911 params.showing_repost_interstitial = false; 903 params.showing_repost_interstitial = false;
912 test_rvh()->OnMessageReceived( 904 test_rvh()->OnMessageReceived(
913 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 905 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
914 params)); 906 params));
915 907
916 // This should not clear the pending entry or notify of a navigation state 908 // This should not clear the pending entry or notify of a navigation state
917 // change. 909 // change.
918 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 910 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
919 EXPECT_TRUE(controller.GetPendingEntry()); 911 EXPECT_TRUE(controller.GetPendingEntry());
920 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 912 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
921 EXPECT_EQ(0, delegate->navigation_state_change_count()); 913 EXPECT_EQ(1, delegate->navigation_state_change_count());
922 914
923 // The visible entry should be the last committed URL, not the pending one, 915 // There should be no visible entry (resulting in about:blank in the
924 // so that no spoof is possible. 916 // omnibox), ensuring no spoof is possible.
925 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL()); 917 EXPECT_FALSE(controller.GetVisibleEntry());
926 918
927 contents()->SetDelegate(NULL); 919 contents()->SetDelegate(NULL);
928 } 920 }
929 921
930 // Ensure that NavigationEntries track which bindings their RenderViewHost had 922 // Ensure that NavigationEntries track which bindings their RenderViewHost had
931 // at the time they committed. http://crbug.com/173672. 923 // at the time they committed. http://crbug.com/173672.
932 TEST_F(NavigationControllerTest, LoadURL_WithBindings) { 924 TEST_F(NavigationControllerTest, LoadURL_WithBindings) {
933 NavigationControllerImpl& controller = controller_impl(); 925 NavigationControllerImpl& controller = controller_impl();
934 TestNotificationTracker notifications; 926 TestNotificationTracker notifications;
935 RegisterForAllNavNotifications(&notifications, &controller); 927 RegisterForAllNavNotifications(&notifications, &controller);
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 test_rvh()->SendNavigate(1, url1); 2484 test_rvh()->SendNavigate(1, url1);
2493 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 2485 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
2494 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2486 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2495 EXPECT_FALSE( 2487 EXPECT_FALSE(
2496 NavigationEntryImpl::FromNavigationEntry( 2488 NavigationEntryImpl::FromNavigationEntry(
2497 controller.GetLastCommittedEntry())->is_renderer_initiated()); 2489 controller.GetLastCommittedEntry())->is_renderer_initiated());
2498 2490
2499 notifications.Reset(); 2491 notifications.Reset();
2500 } 2492 }
2501 2493
2502 // Tests that the URLs for renderer-initiated navigations in new tabs are
2503 // displayed to the user before commit, as long as the initial about:blank
2504 // page has not been modified. If so, we must revert to showing about:blank.
2505 // See http://crbug.com/9682.
2506 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) {
2507 NavigationControllerImpl& controller = controller_impl();
2508 TestNotificationTracker notifications;
2509 RegisterForAllNavNotifications(&notifications, &controller);
2510
2511 const GURL url("http://foo");
2512
2513 // For renderer-initiated navigations in new tabs (with no committed entries),
2514 // we show the pending entry's URL as long as the about:blank page is not
2515 // modified.
2516 NavigationController::LoadURLParams load_url_params(url);
2517 load_url_params.transition_type = PAGE_TRANSITION_LINK;
2518 load_url_params.is_renderer_initiated = true;
2519 controller.LoadURLWithParams(load_url_params);
2520 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL());
2521 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2522 EXPECT_TRUE(
2523 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2524 is_renderer_initiated());
2525 EXPECT_TRUE(controller.IsInitialNavigation());
2526 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2527
2528 // There should be no title yet.
2529 EXPECT_TRUE(contents()->GetTitle().empty());
2530
2531 // If something else modifies the contents of the about:blank page, then
2532 // we must revert to showing about:blank to avoid a URL spoof.
2533 test_rvh()->OnMessageReceived(
2534 ViewHostMsg_DidAccessInitialDocument(0));
2535 EXPECT_TRUE(test_rvh()->has_accessed_initial_document());
2536 EXPECT_FALSE(controller.GetVisibleEntry());
2537 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL());
2538
2539 notifications.Reset();
2540 }
2541
2542 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) {
2543 NavigationControllerImpl& controller = controller_impl();
2544 TestNotificationTracker notifications;
2545 RegisterForAllNavNotifications(&notifications, &controller);
2546
2547 const GURL url1("http://foo/eh");
2548 const GURL url2("http://foo/bee");
2549
2550 // For renderer-initiated navigations in new tabs (with no committed entries),
2551 // we show the pending entry's URL as long as the about:blank page is not
2552 // modified.
2553 NavigationController::LoadURLParams load_url_params(url1);
2554 load_url_params.transition_type = PAGE_TRANSITION_LINK;
2555 load_url_params.is_renderer_initiated = true;
2556 controller.LoadURLWithParams(load_url_params);
2557 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
2558 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2559 EXPECT_TRUE(
2560 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2561 is_renderer_initiated());
2562 EXPECT_TRUE(controller.IsInitialNavigation());
2563 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2564
2565 // Simulate a commit and then starting a new pending navigation.
2566 test_rvh()->SendNavigate(0, url1);
2567 NavigationController::LoadURLParams load_url2_params(url2);
2568 load_url2_params.transition_type = PAGE_TRANSITION_LINK;
2569 load_url2_params.is_renderer_initiated = true;
2570 controller.LoadURLWithParams(load_url2_params);
2571
2572 // We should not consider this an initial navigation, and thus should
2573 // not show the pending URL.
2574 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2575 EXPECT_FALSE(controller.IsInitialNavigation());
2576 EXPECT_TRUE(controller.GetVisibleEntry());
2577 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2578
2579 notifications.Reset();
2580 }
2581
2582 // Tests that IsInPageNavigation returns appropriate results. Prevents 2494 // Tests that IsInPageNavigation returns appropriate results. Prevents
2583 // regression for bug 1126349. 2495 // regression for bug 1126349.
2584 TEST_F(NavigationControllerTest, IsInPageNavigation) { 2496 TEST_F(NavigationControllerTest, IsInPageNavigation) {
2585 NavigationControllerImpl& controller = controller_impl(); 2497 NavigationControllerImpl& controller = controller_impl();
2586 // Navigate to URL with no refs. 2498 // Navigate to URL with no refs.
2587 const GURL url("http://www.google.com/home.html"); 2499 const GURL url("http://www.google.com/home.html");
2588 test_rvh()->SendNavigate(0, url); 2500 test_rvh()->SendNavigate(0, url);
2589 2501
2590 // Reloading the page is not an in-page navigation. 2502 // Reloading the page is not an in-page navigation.
2591 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); 2503 EXPECT_FALSE(controller.IsURLInPageNavigation(url));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 EXPECT_EQ(controller.GetEntryCount(), 1); 2549 EXPECT_EQ(controller.GetEntryCount(), 1);
2638 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2550 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2639 } 2551 }
2640 2552
2641 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 2553 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
2642 // false. 2554 // false.
2643 TEST_F(NavigationControllerTest, CloneAndGoBack) { 2555 TEST_F(NavigationControllerTest, CloneAndGoBack) {
2644 NavigationControllerImpl& controller = controller_impl(); 2556 NavigationControllerImpl& controller = controller_impl();
2645 const GURL url1("http://foo1"); 2557 const GURL url1("http://foo1");
2646 const GURL url2("http://foo2"); 2558 const GURL url2("http://foo2");
2647 const string16 title(ASCIIToUTF16("Title"));
2648 2559
2649 NavigateAndCommit(url1); 2560 NavigateAndCommit(url1);
2650 controller.GetActiveEntry()->SetTitle(title);
2651 NavigateAndCommit(url2); 2561 NavigateAndCommit(url2);
2652 2562
2653 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); 2563 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone());
2654 2564
2655 ASSERT_EQ(2, clone->GetController().GetEntryCount()); 2565 ASSERT_EQ(2, clone->GetController().GetEntryCount());
2656 EXPECT_TRUE(clone->GetController().NeedsReload()); 2566 EXPECT_TRUE(clone->GetController().NeedsReload());
2657 clone->GetController().GoBack(); 2567 clone->GetController().GoBack();
2658 // Navigating back should have triggered needs_reload_ to go false. 2568 // Navigating back should have triggered needs_reload_ to go false.
2659 EXPECT_FALSE(clone->GetController().NeedsReload()); 2569 EXPECT_FALSE(clone->GetController().NeedsReload());
2660
2661 // Ensure that the pending URL and its title are visible.
2662 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL());
2663 EXPECT_EQ(title, clone->GetTitle());
2664 } 2570 }
2665 2571
2666 // Make sure that cloning a WebContentsImpl doesn't copy interstitials. 2572 // Make sure that cloning a WebContentsImpl doesn't copy interstitials.
2667 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { 2573 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) {
2668 NavigationControllerImpl& controller = controller_impl(); 2574 NavigationControllerImpl& controller = controller_impl();
2669 const GURL url1("http://foo1"); 2575 const GURL url1("http://foo1");
2670 const GURL url2("http://foo2"); 2576 const GURL url2("http://foo2");
2671 2577
2672 NavigateAndCommit(url1); 2578 NavigateAndCommit(url1);
2673 NavigateAndCommit(url2); 2579 NavigateAndCommit(url2);
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3540 PAGE_TRANSITION_LINK); 3446 PAGE_TRANSITION_LINK);
3541 session_helper_.AssertNavigationEquals(nav, 3447 session_helper_.AssertNavigationEquals(nav,
3542 windows_[0]->tabs[0]->navigations[0]); 3448 windows_[0]->tabs[0]->navigations[0]);
3543 nav.set_url(url2); 3449 nav.set_url(url2);
3544 session_helper_.AssertNavigationEquals(nav, 3450 session_helper_.AssertNavigationEquals(nav,
3545 windows_[0]->tabs[0]->navigations[1]); 3451 windows_[0]->tabs[0]->navigations[1]);
3546 } 3452 }
3547 */ 3453 */
3548 3454
3549 } // namespace content 3455 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698