| 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 2869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 NavigationController::LoadURLParams load_url_params(url); | 2880 NavigationController::LoadURLParams load_url_params(url); |
| 2881 load_url_params.transition_type = PAGE_TRANSITION_LINK; | 2881 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 2882 load_url_params.is_renderer_initiated = true; | 2882 load_url_params.is_renderer_initiated = true; |
| 2883 controller.LoadURLWithParams(load_url_params); | 2883 controller.LoadURLWithParams(load_url_params); |
| 2884 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2884 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2885 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 2885 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2886 EXPECT_TRUE( | 2886 EXPECT_TRUE( |
| 2887 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2887 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2888 is_renderer_initiated()); | 2888 is_renderer_initiated()); |
| 2889 EXPECT_TRUE(controller.IsInitialNavigation()); | 2889 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2890 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2890 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 2891 | 2891 |
| 2892 // There should be no title yet. | 2892 // There should be no title yet. |
| 2893 EXPECT_TRUE(contents()->GetTitle().empty()); | 2893 EXPECT_TRUE(contents()->GetTitle().empty()); |
| 2894 | 2894 |
| 2895 // If something else modifies the contents of the about:blank page, then | 2895 // If something else modifies the contents of the about:blank page, then |
| 2896 // we must revert to showing about:blank to avoid a URL spoof. | 2896 // we must revert to showing about:blank to avoid a URL spoof. |
| 2897 test_rvh()->OnMessageReceived( | 2897 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
| 2898 ViewHostMsg_DidAccessInitialDocument(0)); | 2898 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
| 2899 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | |
| 2900 EXPECT_FALSE(controller.GetVisibleEntry()); | 2899 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 2901 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 2900 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2902 | 2901 |
| 2903 notifications.Reset(); | 2902 notifications.Reset(); |
| 2904 } | 2903 } |
| 2905 | 2904 |
| 2906 // Tests that the URLs for browser-initiated navigations in new tabs are | 2905 // Tests that the URLs for browser-initiated navigations in new tabs are |
| 2907 // displayed to the user even after they fail, as long as the initial | 2906 // displayed to the user even after they fail, as long as the initial |
| 2908 // about:blank page has not been modified. If so, we must revert to showing | 2907 // about:blank page has not been modified. If so, we must revert to showing |
| 2909 // about:blank. See http://crbug.com/355537. | 2908 // about:blank. See http://crbug.com/355537. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2921 NavigationController::LoadURLParams load_url_params(url); | 2920 NavigationController::LoadURLParams load_url_params(url); |
| 2922 load_url_params.transition_type = PAGE_TRANSITION_TYPED; | 2921 load_url_params.transition_type = PAGE_TRANSITION_TYPED; |
| 2923 load_url_params.is_renderer_initiated = false; | 2922 load_url_params.is_renderer_initiated = false; |
| 2924 controller.LoadURLWithParams(load_url_params); | 2923 controller.LoadURLWithParams(load_url_params); |
| 2925 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2924 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2926 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 2925 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2927 EXPECT_FALSE( | 2926 EXPECT_FALSE( |
| 2928 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2927 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2929 is_renderer_initiated()); | 2928 is_renderer_initiated()); |
| 2930 EXPECT_TRUE(controller.IsInitialNavigation()); | 2929 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2931 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2930 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 2932 | 2931 |
| 2933 // There should be no title yet. | 2932 // There should be no title yet. |
| 2934 EXPECT_TRUE(contents()->GetTitle().empty()); | 2933 EXPECT_TRUE(contents()->GetTitle().empty()); |
| 2935 | 2934 |
| 2936 // Suppose it aborts before committing, if it's a 204 or download or due to a | 2935 // Suppose it aborts before committing, if it's a 204 or download or due to a |
| 2937 // stop or a new navigation from the user. The URL should remain visible. | 2936 // stop or a new navigation from the user. The URL should remain visible. |
| 2938 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; | 2937 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 2939 params.error_code = net::ERR_ABORTED; | 2938 params.error_code = net::ERR_ABORTED; |
| 2940 params.error_description = base::string16(); | 2939 params.error_description = base::string16(); |
| 2941 params.url = url; | 2940 params.url = url; |
| 2942 params.showing_repost_interstitial = false; | 2941 params.showing_repost_interstitial = false; |
| 2943 main_test_rfh()->OnMessageReceived( | 2942 main_test_rfh()->OnMessageReceived( |
| 2944 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); | 2943 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); |
| 2945 contents()->SetIsLoading(test_rvh(), false, true, NULL); | 2944 contents()->SetIsLoading(test_rvh(), false, true, NULL); |
| 2946 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2945 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2947 | 2946 |
| 2948 // If something else later modifies the contents of the about:blank page, then | 2947 // If something else later modifies the contents of the about:blank page, then |
| 2949 // we must revert to showing about:blank to avoid a URL spoof. | 2948 // we must revert to showing about:blank to avoid a URL spoof. |
| 2950 test_rvh()->OnMessageReceived( | 2949 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
| 2951 ViewHostMsg_DidAccessInitialDocument(0)); | 2950 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
| 2952 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | |
| 2953 EXPECT_FALSE(controller.GetVisibleEntry()); | 2951 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 2954 EXPECT_FALSE(controller.GetPendingEntry()); | 2952 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2955 | 2953 |
| 2956 notifications.Reset(); | 2954 notifications.Reset(); |
| 2957 } | 2955 } |
| 2958 | 2956 |
| 2959 // Tests that the URLs for renderer-initiated navigations in new tabs are | 2957 // Tests that the URLs for renderer-initiated navigations in new tabs are |
| 2960 // displayed to the user even after they fail, as long as the initial | 2958 // displayed to the user even after they fail, as long as the initial |
| 2961 // about:blank page has not been modified. If so, we must revert to showing | 2959 // about:blank page has not been modified. If so, we must revert to showing |
| 2962 // about:blank. See http://crbug.com/355537. | 2960 // about:blank. See http://crbug.com/355537. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2973 NavigationController::LoadURLParams load_url_params(url); | 2971 NavigationController::LoadURLParams load_url_params(url); |
| 2974 load_url_params.transition_type = PAGE_TRANSITION_LINK; | 2972 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 2975 load_url_params.is_renderer_initiated = true; | 2973 load_url_params.is_renderer_initiated = true; |
| 2976 controller.LoadURLWithParams(load_url_params); | 2974 controller.LoadURLWithParams(load_url_params); |
| 2977 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2975 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2978 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 2976 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 2979 EXPECT_TRUE( | 2977 EXPECT_TRUE( |
| 2980 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2978 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2981 is_renderer_initiated()); | 2979 is_renderer_initiated()); |
| 2982 EXPECT_TRUE(controller.IsInitialNavigation()); | 2980 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 2983 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2981 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 2984 | 2982 |
| 2985 // There should be no title yet. | 2983 // There should be no title yet. |
| 2986 EXPECT_TRUE(contents()->GetTitle().empty()); | 2984 EXPECT_TRUE(contents()->GetTitle().empty()); |
| 2987 | 2985 |
| 2988 // Suppose it aborts before committing, if it's a 204 or download or due to a | 2986 // Suppose it aborts before committing, if it's a 204 or download or due to a |
| 2989 // stop or a new navigation from the user. The URL should remain visible. | 2987 // stop or a new navigation from the user. The URL should remain visible. |
| 2990 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; | 2988 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 2991 params.error_code = net::ERR_ABORTED; | 2989 params.error_code = net::ERR_ABORTED; |
| 2992 params.error_description = base::string16(); | 2990 params.error_description = base::string16(); |
| 2993 params.url = url; | 2991 params.url = url; |
| 2994 params.showing_repost_interstitial = false; | 2992 params.showing_repost_interstitial = false; |
| 2995 main_test_rfh()->OnMessageReceived( | 2993 main_test_rfh()->OnMessageReceived( |
| 2996 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); | 2994 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); |
| 2997 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2995 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
| 2998 | 2996 |
| 2999 // If something else later modifies the contents of the about:blank page, then | 2997 // If something else later modifies the contents of the about:blank page, then |
| 3000 // we must revert to showing about:blank to avoid a URL spoof. | 2998 // we must revert to showing about:blank to avoid a URL spoof. |
| 3001 test_rvh()->OnMessageReceived( | 2999 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
| 3002 ViewHostMsg_DidAccessInitialDocument(0)); | 3000 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
| 3003 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); | |
| 3004 EXPECT_FALSE(controller.GetVisibleEntry()); | 3001 EXPECT_FALSE(controller.GetVisibleEntry()); |
| 3005 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3002 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
| 3006 | 3003 |
| 3007 notifications.Reset(); | 3004 notifications.Reset(); |
| 3008 } | 3005 } |
| 3009 | 3006 |
| 3010 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { | 3007 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { |
| 3011 NavigationControllerImpl& controller = controller_impl(); | 3008 NavigationControllerImpl& controller = controller_impl(); |
| 3012 TestNotificationTracker notifications; | 3009 TestNotificationTracker notifications; |
| 3013 RegisterForAllNavNotifications(¬ifications, &controller); | 3010 RegisterForAllNavNotifications(¬ifications, &controller); |
| 3014 | 3011 |
| 3015 const GURL url1("http://foo/eh"); | 3012 const GURL url1("http://foo/eh"); |
| 3016 const GURL url2("http://foo/bee"); | 3013 const GURL url2("http://foo/bee"); |
| 3017 | 3014 |
| 3018 // For renderer-initiated navigations in new tabs (with no committed entries), | 3015 // For renderer-initiated navigations in new tabs (with no committed entries), |
| 3019 // we show the pending entry's URL as long as the about:blank page is not | 3016 // we show the pending entry's URL as long as the about:blank page is not |
| 3020 // modified. | 3017 // modified. |
| 3021 NavigationController::LoadURLParams load_url_params(url1); | 3018 NavigationController::LoadURLParams load_url_params(url1); |
| 3022 load_url_params.transition_type = PAGE_TRANSITION_LINK; | 3019 load_url_params.transition_type = PAGE_TRANSITION_LINK; |
| 3023 load_url_params.is_renderer_initiated = true; | 3020 load_url_params.is_renderer_initiated = true; |
| 3024 controller.LoadURLWithParams(load_url_params); | 3021 controller.LoadURLWithParams(load_url_params); |
| 3025 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3022 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 3026 EXPECT_TRUE( | 3023 EXPECT_TRUE( |
| 3027 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 3024 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 3028 is_renderer_initiated()); | 3025 is_renderer_initiated()); |
| 3029 EXPECT_TRUE(controller.IsInitialNavigation()); | 3026 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 3030 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 3027 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 3031 | 3028 |
| 3032 // Simulate a commit and then starting a new pending navigation. | 3029 // Simulate a commit and then starting a new pending navigation. |
| 3033 main_test_rfh()->SendNavigate(0, url1); | 3030 main_test_rfh()->SendNavigate(0, url1); |
| 3034 NavigationController::LoadURLParams load_url2_params(url2); | 3031 NavigationController::LoadURLParams load_url2_params(url2); |
| 3035 load_url2_params.transition_type = PAGE_TRANSITION_LINK; | 3032 load_url2_params.transition_type = PAGE_TRANSITION_LINK; |
| 3036 load_url2_params.is_renderer_initiated = true; | 3033 load_url2_params.is_renderer_initiated = true; |
| 3037 controller.LoadURLWithParams(load_url2_params); | 3034 controller.LoadURLWithParams(load_url2_params); |
| 3038 | 3035 |
| 3039 // We should not consider this an initial navigation, and thus should | 3036 // We should not consider this an initial navigation, and thus should |
| 3040 // not show the pending URL. | 3037 // not show the pending URL. |
| 3041 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 3038 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
| 3042 EXPECT_FALSE(controller.IsInitialNavigation()); | 3039 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 3043 EXPECT_TRUE(controller.GetVisibleEntry()); | 3040 EXPECT_TRUE(controller.GetVisibleEntry()); |
| 3044 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3041 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 3045 | 3042 |
| 3046 notifications.Reset(); | 3043 notifications.Reset(); |
| 3047 } | 3044 } |
| 3048 | 3045 |
| 3049 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3046 // Tests that IsInPageNavigation returns appropriate results. Prevents |
| 3050 // regression for bug 1126349. | 3047 // regression for bug 1126349. |
| 3051 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3048 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4166 EXPECT_EQ(1, controller.GetEntryCount()); | 4163 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4167 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4164 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 4168 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4165 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4169 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4166 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4170 EXPECT_FALSE(controller.CanGoBack()); | 4167 EXPECT_FALSE(controller.CanGoBack()); |
| 4171 EXPECT_FALSE(controller.CanGoForward()); | 4168 EXPECT_FALSE(controller.CanGoForward()); |
| 4172 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4169 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 4173 } | 4170 } |
| 4174 | 4171 |
| 4175 } // namespace content | 4172 } // namespace content |
| OLD | NEW |