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 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 // First navigation. | 2156 // First navigation. |
2157 const GURL url2("http://foo#a"); | 2157 const GURL url2("http://foo#a"); |
2158 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2158 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2159 params.page_id = 0; // Same page_id | 2159 params.page_id = 0; // Same page_id |
2160 params.url = url2; | 2160 params.url = url2; |
2161 params.transition = PAGE_TRANSITION_LINK; | 2161 params.transition = PAGE_TRANSITION_LINK; |
2162 params.should_update_history = false; | 2162 params.should_update_history = false; |
2163 params.gesture = NavigationGestureUser; | 2163 params.gesture = NavigationGestureUser; |
2164 params.is_post = false; | 2164 params.is_post = false; |
2165 params.page_state = PageState::CreateFromURL(url2); | 2165 params.page_state = PageState::CreateFromURL(url2); |
| 2166 params.was_within_same_page = true; |
2166 | 2167 |
2167 // This should NOT generate a new entry, nor prune the list. | 2168 // This should NOT generate a new entry, nor prune the list. |
2168 LoadCommittedDetails details; | 2169 LoadCommittedDetails details; |
2169 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2170 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2170 &details)); | 2171 &details)); |
2171 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2172 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2172 navigation_entry_committed_counter_ = 0; | 2173 navigation_entry_committed_counter_ = 0; |
2173 EXPECT_TRUE(details.is_in_page); | 2174 EXPECT_TRUE(details.is_in_page); |
2174 EXPECT_TRUE(details.did_replace_entry); | 2175 EXPECT_TRUE(details.did_replace_entry); |
2175 EXPECT_EQ(1, controller.GetEntryCount()); | 2176 EXPECT_EQ(1, controller.GetEntryCount()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 const GURL url("http://foo2/#a"); | 2208 const GURL url("http://foo2/#a"); |
2208 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2209 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2209 params.page_id = 1; // Same page_id | 2210 params.page_id = 1; // Same page_id |
2210 params.url = url; | 2211 params.url = url; |
2211 params.transition = PAGE_TRANSITION_LINK; | 2212 params.transition = PAGE_TRANSITION_LINK; |
2212 params.redirects.push_back(url); | 2213 params.redirects.push_back(url); |
2213 params.should_update_history = true; | 2214 params.should_update_history = true; |
2214 params.gesture = NavigationGestureUnknown; | 2215 params.gesture = NavigationGestureUnknown; |
2215 params.is_post = false; | 2216 params.is_post = false; |
2216 params.page_state = PageState::CreateFromURL(url); | 2217 params.page_state = PageState::CreateFromURL(url); |
| 2218 params.was_within_same_page = true; |
2217 | 2219 |
2218 // This should NOT generate a new entry, nor prune the list. | 2220 // This should NOT generate a new entry, nor prune the list. |
2219 LoadCommittedDetails details; | 2221 LoadCommittedDetails details; |
2220 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2222 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2221 &details)); | 2223 &details)); |
2222 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2224 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2223 navigation_entry_committed_counter_ = 0; | 2225 navigation_entry_committed_counter_ = 0; |
2224 EXPECT_TRUE(details.is_in_page); | 2226 EXPECT_TRUE(details.is_in_page); |
2225 EXPECT_TRUE(details.did_replace_entry); | 2227 EXPECT_TRUE(details.did_replace_entry); |
2226 EXPECT_EQ(2, controller.GetEntryCount()); | 2228 EXPECT_EQ(2, controller.GetEntryCount()); |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 | 3059 |
3058 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3060 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3059 // regression for bug 1126349. | 3061 // regression for bug 1126349. |
3060 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3062 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
3061 NavigationControllerImpl& controller = controller_impl(); | 3063 NavigationControllerImpl& controller = controller_impl(); |
3062 // Navigate to URL with no refs. | 3064 // Navigate to URL with no refs. |
3063 const GURL url("http://www.google.com/home.html"); | 3065 const GURL url("http://www.google.com/home.html"); |
3064 main_test_rfh()->SendNavigate(0, url); | 3066 main_test_rfh()->SendNavigate(0, url); |
3065 | 3067 |
3066 // Reloading the page is not an in-page navigation. | 3068 // Reloading the page is not an in-page navigation. |
3067 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 3069 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3070 NAVIGATION_TYPE_UNKNOWN)); |
3068 const GURL other_url("http://www.google.com/add.html"); | 3071 const GURL other_url("http://www.google.com/add.html"); |
3069 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 3072 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3073 NAVIGATION_TYPE_UNKNOWN)); |
3070 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3074 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3071 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); | 3075 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
| 3076 NAVIGATION_TYPE_UNKNOWN)); |
3072 | 3077 |
3073 // Navigate to URL with refs. | 3078 // Navigate to URL with refs. |
3074 main_test_rfh()->SendNavigate(1, url_with_ref); | 3079 main_test_rfh()->SendNavigate(1, url_with_ref); |
3075 | 3080 |
3076 // Reloading the page is not an in-page navigation. | 3081 // Reloading the page is not an in-page navigation. |
3077 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); | 3082 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3078 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 3083 NAVIGATION_TYPE_UNKNOWN)); |
3079 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 3084 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3085 NAVIGATION_TYPE_UNKNOWN)); |
| 3086 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3087 NAVIGATION_TYPE_UNKNOWN)); |
3080 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3088 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3081 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref)); | 3089 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
| 3090 NAVIGATION_TYPE_UNKNOWN)); |
3082 | 3091 |
3083 // Going to the same url again will be considered in-page | 3092 // Going to the same url again will be considered in-page |
3084 // if the renderer says it is even if the navigation type isn't IN_PAGE. | 3093 // if the renderer says it is even if the navigation type isn't IN_PAGE. |
3085 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3094 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3086 NAVIGATION_TYPE_UNKNOWN)); | 3095 NAVIGATION_TYPE_UNKNOWN)); |
3087 | 3096 |
3088 // Going back to the non ref url will be considered in-page if the navigation | 3097 // Going back to the non ref url will be considered in-page if the navigation |
3089 // type is IN_PAGE. | 3098 // type is IN_PAGE. |
3090 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3099 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3091 NAVIGATION_TYPE_IN_PAGE)); | 3100 NAVIGATION_TYPE_IN_PAGE)); |
| 3101 |
| 3102 // If the renderer says this is a same-origin in-page navigation, believe it. |
| 3103 // This is the pushState/replaceState case. |
| 3104 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, |
| 3105 NAVIGATION_TYPE_UNKNOWN)); |
| 3106 |
| 3107 // Don't believe the renderer if it claims a cross-origin navigation is |
| 3108 // in-page. |
| 3109 const GURL different_origin_url("http://www.example.com"); |
| 3110 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
| 3111 NAVIGATION_TYPE_UNKNOWN)); |
3092 } | 3112 } |
3093 | 3113 |
3094 // Some pages can have subframes with the same base URL (minus the reference) as | 3114 // Some pages can have subframes with the same base URL (minus the reference) as |
3095 // the main page. Even though this is hard, it can happen, and we don't want | 3115 // the main page. Even though this is hard, it can happen, and we don't want |
3096 // these subframe navigations to affect the toplevel document. They should | 3116 // these subframe navigations to affect the toplevel document. They should |
3097 // instead be ignored. http://crbug.com/5585 | 3117 // instead be ignored. http://crbug.com/5585 |
3098 TEST_F(NavigationControllerTest, SameSubframe) { | 3118 TEST_F(NavigationControllerTest, SameSubframe) { |
3099 NavigationControllerImpl& controller = controller_impl(); | 3119 NavigationControllerImpl& controller = controller_impl(); |
3100 // Navigate the main frame. | 3120 // Navigate the main frame. |
3101 const GURL url("http://www.google.com/"); | 3121 const GURL url("http://www.google.com/"); |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4290 params.post_id = -1; | 4310 params.post_id = -1; |
4291 test_rvh()->SendNavigateWithParams(¶ms); | 4311 test_rvh()->SendNavigateWithParams(¶ms); |
4292 | 4312 |
4293 // Now reload. replaceState overrides the POST, so we should not show a | 4313 // Now reload. replaceState overrides the POST, so we should not show a |
4294 // repost warning dialog. | 4314 // repost warning dialog. |
4295 controller_impl().Reload(true); | 4315 controller_impl().Reload(true); |
4296 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4316 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4297 } | 4317 } |
4298 | 4318 |
4299 } // namespace content | 4319 } // namespace content |
OLD | NEW |