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 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3073 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3073 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3074 // regression for bug 1126349. | 3074 // regression for bug 1126349. |
3075 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3075 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
3076 NavigationControllerImpl& controller = controller_impl(); | 3076 NavigationControllerImpl& controller = controller_impl(); |
3077 // Navigate to URL with no refs. | 3077 // Navigate to URL with no refs. |
3078 const GURL url("http://www.google.com/home.html"); | 3078 const GURL url("http://www.google.com/home.html"); |
3079 main_test_rfh()->SendNavigate(0, url); | 3079 main_test_rfh()->SendNavigate(0, url); |
3080 | 3080 |
3081 // Reloading the page is not an in-page navigation. | 3081 // Reloading the page is not an in-page navigation. |
3082 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3082 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3083 NAVIGATION_TYPE_UNKNOWN)); | 3083 main_test_rfh())); |
3084 const GURL other_url("http://www.google.com/add.html"); | 3084 const GURL other_url("http://www.google.com/add.html"); |
3085 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3085 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3086 NAVIGATION_TYPE_UNKNOWN)); | 3086 main_test_rfh())); |
3087 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3087 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3088 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3088 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3089 NAVIGATION_TYPE_UNKNOWN)); | 3089 main_test_rfh())); |
3090 | 3090 |
3091 // Navigate to URL with refs. | 3091 // Navigate to URL with refs. |
3092 main_test_rfh()->SendNavigate(1, url_with_ref); | 3092 main_test_rfh()->SendNavigate(1, url_with_ref); |
3093 | 3093 |
3094 // Reloading the page is not an in-page navigation. | 3094 // Reloading the page is not an in-page navigation. |
3095 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, | 3095 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3096 NAVIGATION_TYPE_UNKNOWN)); | 3096 main_test_rfh())); |
3097 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3097 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3098 NAVIGATION_TYPE_UNKNOWN)); | 3098 main_test_rfh())); |
3099 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3099 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3100 NAVIGATION_TYPE_UNKNOWN)); | 3100 main_test_rfh())); |
3101 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3101 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3102 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, | 3102 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
3103 NAVIGATION_TYPE_UNKNOWN)); | 3103 main_test_rfh())); |
3104 | 3104 |
3105 // Going to the same url again will be considered in-page | 3105 // Going to the same url again will be considered in-page |
3106 // if the renderer says it is even if the navigation type isn't IN_PAGE. | 3106 // if the renderer says it is even if the navigation type isn't IN_PAGE. |
3107 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3107 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3108 NAVIGATION_TYPE_UNKNOWN)); | 3108 main_test_rfh())); |
3109 | 3109 |
3110 // Going back to the non ref url will be considered in-page if the navigation | 3110 // Going back to the non ref url will be considered in-page if the navigation |
3111 // type is IN_PAGE. | 3111 // type is IN_PAGE. |
3112 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3112 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3113 NAVIGATION_TYPE_IN_PAGE)); | 3113 main_test_rfh())); |
3114 | 3114 |
3115 // If the renderer says this is a same-origin in-page navigation, believe it. | 3115 // If the renderer says this is a same-origin in-page navigation, believe it. |
3116 // This is the pushState/replaceState case. | 3116 // This is the pushState/replaceState case. |
3117 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, | 3117 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, |
3118 NAVIGATION_TYPE_UNKNOWN)); | 3118 main_test_rfh())); |
3119 | 3119 |
3120 // Don't believe the renderer if it claims a cross-origin navigation is | 3120 // Don't believe the renderer if it claims a cross-origin navigation is |
3121 // in-page. | 3121 // in-page. |
3122 const GURL different_origin_url("http://www.example.com"); | 3122 const GURL different_origin_url("http://www.example.com"); |
| 3123 MockRenderProcessHost* rph = |
| 3124 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); |
| 3125 EXPECT_EQ(0, rph->bad_msg_count()); |
3123 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3126 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3124 NAVIGATION_TYPE_UNKNOWN)); | 3127 main_test_rfh())); |
| 3128 EXPECT_EQ(1, rph->bad_msg_count()); |
3125 } | 3129 } |
3126 | 3130 |
3127 // Some pages can have subframes with the same base URL (minus the reference) as | 3131 // Some pages can have subframes with the same base URL (minus the reference) as |
3128 // the main page. Even though this is hard, it can happen, and we don't want | 3132 // the main page. Even though this is hard, it can happen, and we don't want |
3129 // these subframe navigations to affect the toplevel document. They should | 3133 // these subframe navigations to affect the toplevel document. They should |
3130 // instead be ignored. http://crbug.com/5585 | 3134 // instead be ignored. http://crbug.com/5585 |
3131 TEST_F(NavigationControllerTest, SameSubframe) { | 3135 TEST_F(NavigationControllerTest, SameSubframe) { |
3132 NavigationControllerImpl& controller = controller_impl(); | 3136 NavigationControllerImpl& controller = controller_impl(); |
3133 // Navigate the main frame. | 3137 // Navigate the main frame. |
3134 const GURL url("http://www.google.com/"); | 3138 const GURL url("http://www.google.com/"); |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4323 params.post_id = -1; | 4327 params.post_id = -1; |
4324 test_rvh()->SendNavigateWithParams(¶ms); | 4328 test_rvh()->SendNavigateWithParams(¶ms); |
4325 | 4329 |
4326 // Now reload. replaceState overrides the POST, so we should not show a | 4330 // Now reload. replaceState overrides the POST, so we should not show a |
4327 // repost warning dialog. | 4331 // repost warning dialog. |
4328 controller_impl().Reload(true); | 4332 controller_impl().Reload(true); |
4329 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4333 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4330 } | 4334 } |
4331 | 4335 |
4332 } // namespace content | 4336 } // namespace content |
OLD | NEW |