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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 3178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3189 // Going back to the non ref url will be considered in-page if the navigation | 3189 // Going back to the non ref url will be considered in-page if the navigation |
3190 // type is IN_PAGE. | 3190 // type is IN_PAGE. |
3191 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3191 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3192 main_test_rfh())); | 3192 main_test_rfh())); |
3193 | 3193 |
3194 // If the renderer says this is a same-origin in-page navigation, believe it. | 3194 // If the renderer says this is a same-origin in-page navigation, believe it. |
3195 // This is the pushState/replaceState case. | 3195 // This is the pushState/replaceState case. |
3196 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, | 3196 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url, true, |
3197 main_test_rfh())); | 3197 main_test_rfh())); |
3198 | 3198 |
3199 // Don't believe the renderer if it claims a cross-origin navigation is | 3199 // Test allow_universal_access_from_file_urls flag. |
3200 // in-page. | |
3201 const GURL different_origin_url("http://www.example.com"); | 3200 const GURL different_origin_url("http://www.example.com"); |
3202 MockRenderProcessHost* rph = | 3201 MockRenderProcessHost* rph = |
3203 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); | 3202 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); |
3203 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); | |
3204 prefs.allow_universal_access_from_file_urls = true; | |
3205 test_rvh()->UpdateWebkitPreferences(prefs); | |
3206 prefs = test_rvh()->GetWebkitPreferences(); | |
3207 EXPECT_EQ(true, prefs.allow_universal_access_from_file_urls); | |
Charlie Reis
2015/01/23 22:58:30
nit: EXPECT_TRUE
nhu
2015/01/26 01:11:25
Done.
| |
3208 // Allow in page navigation if existing URL is file scheme. | |
3209 const GURL file_url("file:///foo/index.html"); | |
3210 main_test_rfh()->SendNavigate(0, file_url); | |
3204 EXPECT_EQ(0, rph->bad_msg_count()); | 3211 EXPECT_EQ(0, rph->bad_msg_count()); |
3212 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, | |
3213 main_test_rfh())); | |
3214 EXPECT_EQ(0, rph->bad_msg_count()); | |
3215 // Don't honor allow_universal_access_from_file_urls if existing URL is | |
3216 // not file scheme. | |
3217 main_test_rfh()->SendNavigate(0, url); | |
3205 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3218 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3206 main_test_rfh())); | 3219 main_test_rfh())); |
3207 EXPECT_EQ(1, rph->bad_msg_count()); | 3220 EXPECT_EQ(1, rph->bad_msg_count()); |
3221 | |
3222 // Remove allow_universal_access_from_file_urls flag. | |
3223 prefs.allow_universal_access_from_file_urls = false; | |
3224 test_rvh()->UpdateWebkitPreferences(prefs); | |
3225 prefs = test_rvh()->GetWebkitPreferences(); | |
3226 EXPECT_EQ(false, prefs.allow_universal_access_from_file_urls); | |
Charlie Reis
2015/01/23 22:58:30
nit: EXPECT_FALSE
nhu
2015/01/26 01:11:25
Done.
| |
3227 | |
3228 // Don't believe the renderer if it claims a cross-origin navigation is | |
3229 // in-page. | |
3230 EXPECT_EQ(1, rph->bad_msg_count()); | |
3231 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | |
3232 main_test_rfh())); | |
3233 EXPECT_EQ(2, rph->bad_msg_count()); | |
3208 } | 3234 } |
3209 | 3235 |
3210 // Some pages can have subframes with the same base URL (minus the reference) as | 3236 // Some pages can have subframes with the same base URL (minus the reference) as |
3211 // the main page. Even though this is hard, it can happen, and we don't want | 3237 // the main page. Even though this is hard, it can happen, and we don't want |
3212 // these subframe navigations to affect the toplevel document. They should | 3238 // these subframe navigations to affect the toplevel document. They should |
3213 // instead be ignored. http://crbug.com/5585 | 3239 // instead be ignored. http://crbug.com/5585 |
3214 TEST_F(NavigationControllerTest, SameSubframe) { | 3240 TEST_F(NavigationControllerTest, SameSubframe) { |
3215 NavigationControllerImpl& controller = controller_impl(); | 3241 NavigationControllerImpl& controller = controller_impl(); |
3216 // Navigate the main frame. | 3242 // Navigate the main frame. |
3217 const GURL url("http://www.google.com/"); | 3243 const GURL url("http://www.google.com/"); |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4416 params.post_id = -1; | 4442 params.post_id = -1; |
4417 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4443 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4418 | 4444 |
4419 // Now reload. replaceState overrides the POST, so we should not show a | 4445 // Now reload. replaceState overrides the POST, so we should not show a |
4420 // repost warning dialog. | 4446 // repost warning dialog. |
4421 controller_impl().Reload(true); | 4447 controller_impl().Reload(true); |
4422 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4448 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4423 } | 4449 } |
4424 | 4450 |
4425 } // namespace content | 4451 } // namespace content |
OLD | NEW |