| OLD | NEW |
| 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 Loading... |
| 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 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2926 // we must revert to showing about:blank to avoid a URL spoof. | 2926 // we must revert to showing about:blank to avoid a URL spoof. |
| 2927 test_rvh()->OnMessageReceived( | 2927 test_rvh()->OnMessageReceived( |
| 2928 ViewHostMsg_DidAccessInitialDocument(0)); | 2928 ViewHostMsg_DidAccessInitialDocument(0)); |
| 2929 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | 2929 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); |
| 2930 EXPECT_FALSE(controller.GetVisibleEntry()); | 2930 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 2931 EXPECT_FALSE(controller.GetPendingEntry()); | 2931 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2932 | 2932 |
| 2933 notifications.Reset(); | 2933 notifications.Reset(); |
| 2934 } | 2934 } |
| 2935 | 2935 |
| 2936 // Tests that the URLs for renderer-initiated navigations in new tabs are |
| 2937 // displayed to the user even after they fail, as long as the initial |
| 2938 // about:blank page has not been modified. If so, we must revert to showing |
| 2939 // about:blank. See http://crbug.com/355537. |
| 2940 TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) { |
| 2941 NavigationControllerImpl& controller = controller_impl(); |
| 2942 TestNotificationTracker notifications; |
| 2943 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2944 |
| 2945 const GURL url("http://foo"); |
| 2946 |
| 2947 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 2948 // we show the pending entry's URL as long as the about:blank page is not |
| 2949 // modified. |
| 2950 NavigationController::LoadURLParams load_url_params(url); |
| 2951 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 2952 load_url_params.is_renderer_initiated = true; |
| 2953 controller.LoadURLWithParams(load_url_params); |
| 2954 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2955 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2956 EXPECT_TRUE( |
| 2957 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2958 is_renderer_initiated()); |
| 2959 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2960 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); |
| 2961 |
| 2962 // There should be no title yet. |
| 2963 EXPECT_TRUE(contents()->GetTitle().empty()); |
| 2964 |
| 2965 // Suppose it aborts before committing, if it's a 204 or download or due to a |
| 2966 // stop or a new navigation from the user. The URL should remain visible. |
| 2967 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 2968 params.error_code = net::ERR_ABORTED; |
| 2969 params.error_description = base::string16(); |
| 2970 params.url = url; |
| 2971 params.showing_repost_interstitial = false; |
| 2972 main_test_rfh()->OnMessageReceived( |
| 2973 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); |
| 2974 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2975 |
| 2976 // If something else later modifies the contents of the about:blank page, then |
| 2977 // we must revert to showing about:blank to avoid a URL spoof. |
| 2978 test_rvh()->OnMessageReceived( |
| 2979 ViewHostMsg_DidAccessInitialDocument(0)); |
| 2980 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); |
| 2981 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 2982 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2983 |
| 2984 notifications.Reset(); |
| 2985 } |
| 2986 |
| 2936 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { | 2987 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { |
| 2937 NavigationControllerImpl& controller = controller_impl(); | 2988 NavigationControllerImpl& controller = controller_impl(); |
| 2938 TestNotificationTracker notifications; | 2989 TestNotificationTracker notifications; |
| 2939 RegisterForAllNavNotifications(¬ifications, &controller); | 2990 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2940 | 2991 |
| 2941 const GURL url1("http://foo/eh"); | 2992 const GURL url1("http://foo/eh"); |
| 2942 const GURL url2("http://foo/bee"); | 2993 const GURL url2("http://foo/bee"); |
| 2943 | 2994 |
| 2944 // For renderer-initiated navigations in new tabs (with no committed entries), | 2995 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 2945 // we show the pending entry's URL as long as the about:blank page is not | 2996 // 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 Loading... |
| 4092 EXPECT_EQ(1, controller.GetEntryCount()); | 4143 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4093 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4144 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 4094 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4145 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4095 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4146 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4096 EXPECT_FALSE(controller.CanGoBack()); | 4147 EXPECT_FALSE(controller.CanGoBack()); |
| 4097 EXPECT_FALSE(controller.CanGoForward()); | 4148 EXPECT_FALSE(controller.CanGoForward()); |
| 4098 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4149 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 4099 } | 4150 } |
| 4100 | 4151 |
| 4101 } // namespace content | 4152 } // namespace content |
| OLD | NEW |