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 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 // First navigation. | 2144 // First navigation. |
2145 const GURL url2("http://foo#a"); | 2145 const GURL url2("http://foo#a"); |
2146 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2146 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2147 params.page_id = 0; // Same page_id | 2147 params.page_id = 0; // Same page_id |
2148 params.url = url2; | 2148 params.url = url2; |
2149 params.transition = PAGE_TRANSITION_LINK; | 2149 params.transition = PAGE_TRANSITION_LINK; |
2150 params.should_update_history = false; | 2150 params.should_update_history = false; |
2151 params.gesture = NavigationGestureUser; | 2151 params.gesture = NavigationGestureUser; |
2152 params.is_post = false; | 2152 params.is_post = false; |
2153 params.page_state = PageState::CreateFromURL(url2); | 2153 params.page_state = PageState::CreateFromURL(url2); |
| 2154 params.was_within_same_page = true; |
2154 | 2155 |
2155 // This should NOT generate a new entry, nor prune the list. | 2156 // This should NOT generate a new entry, nor prune the list. |
2156 LoadCommittedDetails details; | 2157 LoadCommittedDetails details; |
2157 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2158 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2158 &details)); | 2159 &details)); |
2159 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2160 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2160 navigation_entry_committed_counter_ = 0; | 2161 navigation_entry_committed_counter_ = 0; |
2161 EXPECT_TRUE(details.is_in_page); | 2162 EXPECT_TRUE(details.is_in_page); |
2162 EXPECT_TRUE(details.did_replace_entry); | 2163 EXPECT_TRUE(details.did_replace_entry); |
2163 EXPECT_EQ(1, controller.GetEntryCount()); | 2164 EXPECT_EQ(1, controller.GetEntryCount()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 const GURL url("http://foo2/#a"); | 2196 const GURL url("http://foo2/#a"); |
2196 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2197 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2197 params.page_id = 1; // Same page_id | 2198 params.page_id = 1; // Same page_id |
2198 params.url = url; | 2199 params.url = url; |
2199 params.transition = PAGE_TRANSITION_LINK; | 2200 params.transition = PAGE_TRANSITION_LINK; |
2200 params.redirects.push_back(url); | 2201 params.redirects.push_back(url); |
2201 params.should_update_history = true; | 2202 params.should_update_history = true; |
2202 params.gesture = NavigationGestureUnknown; | 2203 params.gesture = NavigationGestureUnknown; |
2203 params.is_post = false; | 2204 params.is_post = false; |
2204 params.page_state = PageState::CreateFromURL(url); | 2205 params.page_state = PageState::CreateFromURL(url); |
| 2206 params.was_within_same_page = true; |
2205 | 2207 |
2206 // This should NOT generate a new entry, nor prune the list. | 2208 // This should NOT generate a new entry, nor prune the list. |
2207 LoadCommittedDetails details; | 2209 LoadCommittedDetails details; |
2208 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2210 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2209 &details)); | 2211 &details)); |
2210 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2212 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2211 navigation_entry_committed_counter_ = 0; | 2213 navigation_entry_committed_counter_ = 0; |
2212 EXPECT_TRUE(details.is_in_page); | 2214 EXPECT_TRUE(details.is_in_page); |
2213 EXPECT_TRUE(details.did_replace_entry); | 2215 EXPECT_TRUE(details.did_replace_entry); |
2214 EXPECT_EQ(2, controller.GetEntryCount()); | 2216 EXPECT_EQ(2, controller.GetEntryCount()); |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3045 | 3047 |
3046 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3048 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3047 // regression for bug 1126349. | 3049 // regression for bug 1126349. |
3048 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3050 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
3049 NavigationControllerImpl& controller = controller_impl(); | 3051 NavigationControllerImpl& controller = controller_impl(); |
3050 // Navigate to URL with no refs. | 3052 // Navigate to URL with no refs. |
3051 const GURL url("http://www.google.com/home.html"); | 3053 const GURL url("http://www.google.com/home.html"); |
3052 main_test_rfh()->SendNavigate(0, url); | 3054 main_test_rfh()->SendNavigate(0, url); |
3053 | 3055 |
3054 // Reloading the page is not an in-page navigation. | 3056 // Reloading the page is not an in-page navigation. |
3055 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 3057 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3058 NAVIGATION_TYPE_UNKNOWN)); |
3056 const GURL other_url("http://www.google.com/add.html"); | 3059 const GURL other_url("http://www.google.com/add.html"); |
3057 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 3060 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3061 NAVIGATION_TYPE_UNKNOWN)); |
3058 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3062 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3059 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); | 3063 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
| 3064 NAVIGATION_TYPE_UNKNOWN)); |
3060 | 3065 |
3061 // Navigate to URL with refs. | 3066 // Navigate to URL with refs. |
3062 main_test_rfh()->SendNavigate(1, url_with_ref); | 3067 main_test_rfh()->SendNavigate(1, url_with_ref); |
3063 | 3068 |
3064 // Reloading the page is not an in-page navigation. | 3069 // Reloading the page is not an in-page navigation. |
3065 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); | 3070 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3066 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 3071 NAVIGATION_TYPE_UNKNOWN)); |
3067 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 3072 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3073 NAVIGATION_TYPE_UNKNOWN)); |
| 3074 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
| 3075 NAVIGATION_TYPE_UNKNOWN)); |
3068 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3076 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3069 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref)); | 3077 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
| 3078 NAVIGATION_TYPE_UNKNOWN)); |
3070 | 3079 |
3071 // Going to the same url again will be considered in-page | 3080 // Going to the same url again will be considered in-page |
3072 // if the renderer says it is even if the navigation type isn't IN_PAGE. | 3081 // if the renderer says it is even if the navigation type isn't IN_PAGE. |
3073 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3082 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3074 NAVIGATION_TYPE_UNKNOWN)); | 3083 NAVIGATION_TYPE_UNKNOWN)); |
3075 | 3084 |
3076 // Going back to the non ref url will be considered in-page if the navigation | 3085 // Going back to the non ref url will be considered in-page if the navigation |
3077 // type is IN_PAGE. | 3086 // type is IN_PAGE. |
3078 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3087 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3079 NAVIGATION_TYPE_IN_PAGE)); | 3088 NAVIGATION_TYPE_IN_PAGE)); |
| 3089 |
| 3090 // If the renderer says this is a same-origin in-page navigation, believe it. |
| 3091 // This is the pushState/replaceState case. |
| 3092 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, |
| 3093 NAVIGATION_TYPE_UNKNOWN)); |
| 3094 |
| 3095 // Don't believe the renderer if it claims a cross-origin navigation is |
| 3096 // in-page. |
| 3097 const GURL different_origin_url("http://www.example.com"); |
| 3098 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
| 3099 NAVIGATION_TYPE_UNKNOWN)); |
3080 } | 3100 } |
3081 | 3101 |
3082 // Some pages can have subframes with the same base URL (minus the reference) as | 3102 // Some pages can have subframes with the same base URL (minus the reference) as |
3083 // the main page. Even though this is hard, it can happen, and we don't want | 3103 // the main page. Even though this is hard, it can happen, and we don't want |
3084 // these subframe navigations to affect the toplevel document. They should | 3104 // these subframe navigations to affect the toplevel document. They should |
3085 // instead be ignored. http://crbug.com/5585 | 3105 // instead be ignored. http://crbug.com/5585 |
3086 TEST_F(NavigationControllerTest, SameSubframe) { | 3106 TEST_F(NavigationControllerTest, SameSubframe) { |
3087 NavigationControllerImpl& controller = controller_impl(); | 3107 NavigationControllerImpl& controller = controller_impl(); |
3088 // Navigate the main frame. | 3108 // Navigate the main frame. |
3089 const GURL url("http://www.google.com/"); | 3109 const GURL url("http://www.google.com/"); |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4218 EXPECT_EQ(1, controller.GetEntryCount()); | 4238 EXPECT_EQ(1, controller.GetEntryCount()); |
4219 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4239 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4220 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4240 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4221 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4241 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4222 EXPECT_FALSE(controller.CanGoBack()); | 4242 EXPECT_FALSE(controller.CanGoBack()); |
4223 EXPECT_FALSE(controller.CanGoForward()); | 4243 EXPECT_FALSE(controller.CanGoForward()); |
4224 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4244 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
4225 } | 4245 } |
4226 | 4246 |
4227 } // namespace content | 4247 } // namespace content |
OLD | NEW |