Chromium Code Reviews| 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()); |
|
Charlie Reis
2014/04/18 01:23:53
We're now triggering a state change in DidFail so
| |
| 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 Loading... | |
| 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) { | |
|
Charlie Reis
2014/04/18 01:23:53
This is similar to the test above but checks the D
| |
| 2888 NavigationControllerImpl& controller = controller_impl(); | |
| 2889 TestNotificationTracker notifications; | |
| 2890 RegisterForAllNavNotifications(¬ifications, &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, // routing_id | |
| 2921 params)); | |
| 2922 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | |
| 2923 | |
| 2924 // If something else later modifies the contents of the about:blank page, then | |
| 2925 // we must revert to showing about:blank to avoid a URL spoof. | |
| 2926 test_rvh()->OnMessageReceived( | |
| 2927 ViewHostMsg_DidAccessInitialDocument(0)); | |
| 2928 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | |
| 2929 EXPECT_FALSE(controller.GetVisibleEntry()); | |
| 2930 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | |
| 2931 | |
| 2932 notifications.Reset(); | |
| 2933 } | |
| 2934 | |
| 2883 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { | 2935 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { |
| 2884 NavigationControllerImpl& controller = controller_impl(); | 2936 NavigationControllerImpl& controller = controller_impl(); |
| 2885 TestNotificationTracker notifications; | 2937 TestNotificationTracker notifications; |
| 2886 RegisterForAllNavNotifications(¬ifications, &controller); | 2938 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2887 | 2939 |
| 2888 const GURL url1("http://foo/eh"); | 2940 const GURL url1("http://foo/eh"); |
| 2889 const GURL url2("http://foo/bee"); | 2941 const GURL url2("http://foo/bee"); |
| 2890 | 2942 |
| 2891 // For renderer-initiated navigations in new tabs (with no committed entries), | 2943 // 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 | 2944 // 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... | |
| 4039 EXPECT_EQ(1, controller.GetEntryCount()); | 4091 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4040 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4092 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 4041 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4093 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4042 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4094 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4043 EXPECT_FALSE(controller.CanGoBack()); | 4095 EXPECT_FALSE(controller.CanGoBack()); |
| 4044 EXPECT_FALSE(controller.CanGoForward()); | 4096 EXPECT_FALSE(controller.CanGoForward()); |
| 4045 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4097 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 4046 } | 4098 } |
| 4047 | 4099 |
| 4048 } // namespace content | 4100 } // namespace content |
| OLD | NEW |