| 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 3229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3240 NavigationControllerImpl& controller = controller_impl(); | 3240 NavigationControllerImpl& controller = controller_impl(); |
| 3241 Navigator* navigator = | 3241 Navigator* navigator = |
| 3242 contents()->GetFrameTree()->root()->navigator(); | 3242 contents()->GetFrameTree()->root()->navigator(); |
| 3243 | 3243 |
| 3244 const GURL url1("nonexistent:12121"); | 3244 const GURL url1("nonexistent:12121"); |
| 3245 const GURL url1_fixed("http://nonexistent:12121/"); | 3245 const GURL url1_fixed("http://nonexistent:12121/"); |
| 3246 const GURL url2("http://foo"); | 3246 const GURL url2("http://foo"); |
| 3247 | 3247 |
| 3248 // We create pending entries for renderer-initiated navigations so that we | 3248 // We create pending entries for renderer-initiated navigations so that we |
| 3249 // can show them in new tabs when it is safe. | 3249 // can show them in new tabs when it is safe. |
| 3250 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3250 navigator->DidStartProvisionalLoad(main_test_rfh(), url1); |
| 3251 | 3251 |
| 3252 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing | 3252 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing |
| 3253 // the virtual URL to differ from the URL. | 3253 // the virtual URL to differ from the URL. |
| 3254 controller.GetPendingEntry()->SetURL(url1_fixed); | 3254 controller.GetPendingEntry()->SetURL(url1_fixed); |
| 3255 controller.GetPendingEntry()->SetVirtualURL(url1); | 3255 controller.GetPendingEntry()->SetVirtualURL(url1); |
| 3256 | 3256 |
| 3257 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); | 3257 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); |
| 3258 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); | 3258 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); |
| 3259 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3259 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 3260 | 3260 |
| 3261 // If the user clicks another link, we should replace the pending entry. | 3261 // If the user clicks another link, we should replace the pending entry. |
| 3262 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3262 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3263 main_test_rfh()->PrepareForCommit(); | 3263 main_test_rfh()->PrepareForCommit(); |
| 3264 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3264 navigator->DidStartProvisionalLoad(main_test_rfh(), url2); |
| 3265 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3265 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 3266 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3266 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
| 3267 | 3267 |
| 3268 // Once it commits, the URL and virtual URL should reflect the actual page. | 3268 // Once it commits, the URL and virtual URL should reflect the actual page. |
| 3269 main_test_rfh()->SendNavigate(0, 0, true, url2); | 3269 main_test_rfh()->SendNavigate(0, 0, true, url2); |
| 3270 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3270 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3271 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3271 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
| 3272 | 3272 |
| 3273 // We should not replace the pending entry for an error URL. | 3273 // We should not replace the pending entry for an error URL. |
| 3274 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3274 navigator->DidStartProvisionalLoad(main_test_rfh(), url1); |
| 3275 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3275 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3276 navigator->DidStartProvisionalLoad(main_test_rfh(), | 3276 navigator->DidStartProvisionalLoad(main_test_rfh(), |
| 3277 GURL(kUnreachableWebDataURL), false); | 3277 GURL(kUnreachableWebDataURL)); |
| 3278 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3278 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3279 | 3279 |
| 3280 // We should remember if the pending entry will replace the current one. | 3280 // We should remember if the pending entry will replace the current one. |
| 3281 // http://crbug.com/308444. | 3281 // http://crbug.com/308444. |
| 3282 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3282 navigator->DidStartProvisionalLoad(main_test_rfh(), url1); |
| 3283 controller.GetPendingEntry()->set_should_replace_entry(true); | 3283 controller.GetPendingEntry()->set_should_replace_entry(true); |
| 3284 | 3284 |
| 3285 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3285 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3286 main_test_rfh()->PrepareForCommit(); | 3286 main_test_rfh()->PrepareForCommit(); |
| 3287 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3287 navigator->DidStartProvisionalLoad(main_test_rfh(), url2); |
| 3288 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3288 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
| 3289 main_test_rfh()->SendNavigate(0, 0, false, url2); | 3289 main_test_rfh()->SendNavigate(0, 0, false, url2); |
| 3290 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3290 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3291 } | 3291 } |
| 3292 | 3292 |
| 3293 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3293 // Tests that the URLs for renderer-initiated navigations are not displayed to |
| 3294 // the user until the navigation commits, to prevent URL spoof attacks. | 3294 // the user until the navigation commits, to prevent URL spoof attacks. |
| 3295 // See http://crbug.com/99016. | 3295 // See http://crbug.com/99016. |
| 3296 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3296 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 3297 NavigationControllerImpl& controller = controller_impl(); | 3297 NavigationControllerImpl& controller = controller_impl(); |
| (...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4888 { | 4888 { |
| 4889 LoadCommittedDetails details; | 4889 LoadCommittedDetails details; |
| 4890 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4890 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4891 EXPECT_EQ(PAGE_TYPE_ERROR, | 4891 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4892 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4892 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4893 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4893 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
| 4894 } | 4894 } |
| 4895 } | 4895 } |
| 4896 | 4896 |
| 4897 } // namespace content | 4897 } // namespace content |
| OLD | NEW |