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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 232463007: Don't leave aborted URLs in the omnibox unless we're on a new tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 params.showing_repost_interstitial = false; 1039 params.showing_repost_interstitial = false;
1040 main_test_rfh()->OnMessageReceived( 1040 main_test_rfh()->OnMessageReceived(
1041 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 1041 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
1042 params)); 1042 params));
1043 1043
1044 // Because the pending entry is renderer initiated and not visible, we 1044 // Because the pending entry is renderer initiated and not visible, we
1045 // clear it when it fails. 1045 // clear it when it fails.
1046 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1046 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1047 EXPECT_FALSE(controller.GetPendingEntry()); 1047 EXPECT_FALSE(controller.GetPendingEntry());
1048 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1048 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1049 EXPECT_EQ(0, delegate->navigation_state_change_count()); 1049 EXPECT_EQ(1, delegate->navigation_state_change_count());
1050 1050
1051 // The visible entry should be the last committed URL, not the pending one, 1051 // The visible entry should be the last committed URL, not the pending one,
1052 // so that no spoof is possible. 1052 // so that no spoof is possible.
1053 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL()); 1053 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL());
1054 1054
1055 contents()->SetDelegate(NULL); 1055 contents()->SetDelegate(NULL);
1056 } 1056 }
1057 1057
1058 // Ensure that NavigationEntries track which bindings their RenderViewHost had 1058 // Ensure that NavigationEntries track which bindings their RenderViewHost had
1059 // at the time they committed. http://crbug.com/173672. 1059 // at the time they committed. http://crbug.com/173672.
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 // we must revert to showing about:blank to avoid a URL spoof. 2873 // we must revert to showing about:blank to avoid a URL spoof.
2874 test_rvh()->OnMessageReceived( 2874 test_rvh()->OnMessageReceived(
2875 ViewHostMsg_DidAccessInitialDocument(0)); 2875 ViewHostMsg_DidAccessInitialDocument(0));
2876 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); 2876 EXPECT_TRUE(test_rvh()->has_accessed_initial_document());
2877 EXPECT_FALSE(controller.GetVisibleEntry()); 2877 EXPECT_FALSE(controller.GetVisibleEntry());
2878 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); 2878 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2879 2879
2880 notifications.Reset(); 2880 notifications.Reset();
2881 } 2881 }
2882 2882
2883 // Tests that the URLs for renderer-initiated navigations in new tabs are
2884 // displayed to the user even after they fail, as long as the initial
2885 // about:blank page has not been modified. If so, we must revert to showing
2886 // about:blank. See http://crbug.com/355537.
2887 TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) {
2888 NavigationControllerImpl& controller = controller_impl();
2889 TestNotificationTracker notifications;
2890 RegisterForAllNavNotifications(&notifications, &controller);
2891
2892 const GURL url("http://foo");
2893
2894 // For renderer-initiated navigations in new tabs (with no committed entries),
2895 // we show the pending entry's URL as long as the about:blank page is not
2896 // modified.
2897 NavigationController::LoadURLParams load_url_params(url);
2898 load_url_params.transition_type = PAGE_TRANSITION_LINK;
2899 load_url_params.is_renderer_initiated = true;
2900 controller.LoadURLWithParams(load_url_params);
2901 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2902 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2903 EXPECT_TRUE(
2904 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2905 is_renderer_initiated());
2906 EXPECT_TRUE(controller.IsInitialNavigation());
2907 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2908
2909 // There should be no title yet.
2910 EXPECT_TRUE(contents()->GetTitle().empty());
2911
2912 // Suppose it aborts before committing, if it's a 204 or download or due to a
2913 // stop or a new navigation from the user. The URL should remain visible.
2914 FrameHostMsg_DidFailProvisionalLoadWithError_Params params;
2915 params.error_code = net::ERR_ABORTED;
2916 params.error_description = base::string16();
2917 params.url = url;
2918 params.showing_repost_interstitial = false;
2919 main_test_rfh()->OnMessageReceived(
2920 FrameHostMsg_DidFailProvisionalLoadWithError(0, params));
Charlie Reis 2014/04/21 17:29:00 Also fixed this based on Peter's comment in https:
2921 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2922
2923 // If something else later modifies the contents of the about:blank page, then
2924 // we must revert to showing about:blank to avoid a URL spoof.
2925 test_rvh()->OnMessageReceived(
2926 ViewHostMsg_DidAccessInitialDocument(0));
2927 EXPECT_TRUE(test_rvh()->has_accessed_initial_document());
2928 EXPECT_FALSE(controller.GetVisibleEntry());
2929 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2930
2931 notifications.Reset();
2932 }
2933
2883 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { 2934 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) {
2884 NavigationControllerImpl& controller = controller_impl(); 2935 NavigationControllerImpl& controller = controller_impl();
2885 TestNotificationTracker notifications; 2936 TestNotificationTracker notifications;
2886 RegisterForAllNavNotifications(&notifications, &controller); 2937 RegisterForAllNavNotifications(&notifications, &controller);
2887 2938
2888 const GURL url1("http://foo/eh"); 2939 const GURL url1("http://foo/eh");
2889 const GURL url2("http://foo/bee"); 2940 const GURL url2("http://foo/bee");
2890 2941
2891 // For renderer-initiated navigations in new tabs (with no committed entries), 2942 // For renderer-initiated navigations in new tabs (with no committed entries),
2892 // we show the pending entry's URL as long as the about:blank page is not 2943 // we show the pending entry's URL as long as the about:blank page is not
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
4039 EXPECT_EQ(1, controller.GetEntryCount()); 4090 EXPECT_EQ(1, controller.GetEntryCount());
4040 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4091 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4041 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4092 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4042 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4093 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4043 EXPECT_FALSE(controller.CanGoBack()); 4094 EXPECT_FALSE(controller.CanGoBack());
4044 EXPECT_FALSE(controller.CanGoForward()); 4095 EXPECT_FALSE(controller.CanGoForward());
4045 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4096 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4046 } 4097 }
4047 4098
4048 } // namespace content 4099 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/browser/frame_host/navigator_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698