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

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

Issue 243493002: Clear failed browser-initiated navigations if blank tab is modified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch 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
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2862 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 browser-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, ShowBrowserURLAfterFailUntilModified) {
2888 NavigationControllerImpl& controller = controller_impl();
2889 TestNotificationTracker notifications;
2890 RegisterForAllNavNotifications(&notifications, &controller);
2891
2892 const GURL url("http://foo");
2893
2894 // For browser-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. This is possible in cases that the user types a URL into a popup
2897 // tab created with a slow URL.
2898 NavigationController::LoadURLParams load_url_params(url);
2899 load_url_params.transition_type = PAGE_TRANSITION_TYPED;
2900 load_url_params.is_renderer_initiated = false;
2901 controller.LoadURLWithParams(load_url_params);
2902 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2903 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2904 EXPECT_FALSE(
2905 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2906 is_renderer_initiated());
2907 EXPECT_TRUE(controller.IsInitialNavigation());
2908 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2909
2910 // There should be no title yet.
2911 EXPECT_TRUE(contents()->GetTitle().empty());
2912
2913 // Suppose it aborts before committing, if it's a 204 or download or due to a
2914 // stop or a new navigation from the user. The URL should remain visible.
2915 FrameHostMsg_DidFailProvisionalLoadWithError_Params params;
2916 params.error_code = net::ERR_ABORTED;
2917 params.error_description = base::string16();
2918 params.url = url;
2919 params.showing_repost_interstitial = false;
2920 main_test_rfh()->OnMessageReceived(
2921 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
Peter Kasting 2014/04/18 20:39:12 Nit: I think this EOL comment just makes reading t
Charlie Reis 2014/04/18 21:05:29 Done.
2922 params));
2923 contents()->SetIsLoading(test_rvh(), false, true, NULL);
2924 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2925
2926 // If something else later modifies the contents of the about:blank page, then
2927 // we must revert to showing about:blank to avoid a URL spoof.
2928 test_rvh()->OnMessageReceived(
2929 ViewHostMsg_DidAccessInitialDocument(0));
2930 EXPECT_TRUE(test_rvh()->has_accessed_initial_document());
2931 EXPECT_FALSE(controller.GetVisibleEntry());
2932 EXPECT_FALSE(controller.GetPendingEntry());
2933
2934 notifications.Reset();
2935 }
2936
2883 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { 2937 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) {
2884 NavigationControllerImpl& controller = controller_impl(); 2938 NavigationControllerImpl& controller = controller_impl();
2885 TestNotificationTracker notifications; 2939 TestNotificationTracker notifications;
2886 RegisterForAllNavNotifications(&notifications, &controller); 2940 RegisterForAllNavNotifications(&notifications, &controller);
2887 2941
2888 const GURL url1("http://foo/eh"); 2942 const GURL url1("http://foo/eh");
2889 const GURL url2("http://foo/bee"); 2943 const GURL url2("http://foo/bee");
2890 2944
2891 // For renderer-initiated navigations in new tabs (with no committed entries), 2945 // 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 2946 // 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()); 4093 EXPECT_EQ(1, controller.GetEntryCount());
4040 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4094 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4041 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4095 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4042 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4096 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4043 EXPECT_FALSE(controller.CanGoBack()); 4097 EXPECT_FALSE(controller.CanGoBack());
4044 EXPECT_FALSE(controller.CanGoForward()); 4098 EXPECT_FALSE(controller.CanGoForward());
4045 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4099 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4046 } 4100 }
4047 4101
4048 } // namespace content 4102 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698