| 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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 3472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3483 contents()->GetFrameTree()->root()->navigator(); | 3483 contents()->GetFrameTree()->root()->navigator(); |
| 3484 | 3484 |
| 3485 const GURL url1("nonexistent:12121"); | 3485 const GURL url1("nonexistent:12121"); |
| 3486 const GURL url1_fixed("http://nonexistent:12121/"); | 3486 const GURL url1_fixed("http://nonexistent:12121/"); |
| 3487 const GURL url2("http://foo"); | 3487 const GURL url2("http://foo"); |
| 3488 | 3488 |
| 3489 // We create pending entries for renderer-initiated navigations so that we | 3489 // We create pending entries for renderer-initiated navigations so that we |
| 3490 // can show them in new tabs when it is safe. | 3490 // can show them in new tabs when it is safe. |
| 3491 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); | 3491 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); |
| 3492 main_test_rfh()->PrepareForCommit(); | 3492 main_test_rfh()->PrepareForCommit(); |
| 3493 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, | 3493 navigator->DidStartProvisionalLoad( |
| 3494 base::TimeTicks::Now()); | 3494 main_test_rfh(), url1, base::TimeTicks::Now(), NavigationGestureAuto); |
| 3495 | 3495 |
| 3496 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing | 3496 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing |
| 3497 // the virtual URL to differ from the URL. | 3497 // the virtual URL to differ from the URL. |
| 3498 controller.GetPendingEntry()->SetURL(url1_fixed); | 3498 controller.GetPendingEntry()->SetURL(url1_fixed); |
| 3499 controller.GetPendingEntry()->SetVirtualURL(url1); | 3499 controller.GetPendingEntry()->SetVirtualURL(url1); |
| 3500 | 3500 |
| 3501 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); | 3501 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); |
| 3502 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); | 3502 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); |
| 3503 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3503 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 3504 | 3504 |
| 3505 // If the user clicks another link, we should replace the pending entry. | 3505 // If the user clicks another link, we should replace the pending entry. |
| 3506 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3506 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3507 main_test_rfh()->PrepareForCommit(); | 3507 main_test_rfh()->PrepareForCommit(); |
| 3508 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, | 3508 navigator->DidStartProvisionalLoad( |
| 3509 base::TimeTicks::Now()); | 3509 main_test_rfh(), url2, base::TimeTicks::Now(), NavigationGestureAuto); |
| 3510 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3510 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 3511 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3511 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
| 3512 | 3512 |
| 3513 // Once it commits, the URL and virtual URL should reflect the actual page. | 3513 // Once it commits, the URL and virtual URL should reflect the actual page. |
| 3514 main_test_rfh()->SendNavigate(0, true, url2); | 3514 main_test_rfh()->SendNavigate(0, true, url2); |
| 3515 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3515 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3516 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3516 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
| 3517 | 3517 |
| 3518 // We should not replace the pending entry for an error URL. | 3518 // We should not replace the pending entry for an error URL. |
| 3519 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, | 3519 navigator->DidStartProvisionalLoad( |
| 3520 base::TimeTicks::Now()); | 3520 main_test_rfh(), url1, base::TimeTicks::Now(), NavigationGestureAuto); |
| 3521 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3521 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3522 navigator->DidStartProvisionalLoad( | 3522 navigator->DidStartProvisionalLoad( |
| 3523 main_test_rfh(), GURL(kUnreachableWebDataURL), base::TimeTicks::Now()); | 3523 main_test_rfh(), GURL(kUnreachableWebDataURL), base::TimeTicks::Now(), |
| 3524 NavigationGestureAuto); |
| 3524 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3525 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 3525 | 3526 |
| 3526 // We should remember if the pending entry will replace the current one. | 3527 // We should remember if the pending entry will replace the current one. |
| 3527 // http://crbug.com/308444. | 3528 // http://crbug.com/308444. |
| 3528 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, | 3529 navigator->DidStartProvisionalLoad( |
| 3529 base::TimeTicks::Now()); | 3530 main_test_rfh(), url1, base::TimeTicks::Now(), NavigationGestureAuto); |
| 3530 controller.GetPendingEntry()->set_should_replace_entry(true); | 3531 controller.GetPendingEntry()->set_should_replace_entry(true); |
| 3531 | 3532 |
| 3532 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3533 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
| 3533 main_test_rfh()->PrepareForCommit(); | 3534 main_test_rfh()->PrepareForCommit(); |
| 3534 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, | 3535 navigator->DidStartProvisionalLoad( |
| 3535 base::TimeTicks::Now()); | 3536 main_test_rfh(), url2, base::TimeTicks::Now(), NavigationGestureAuto); |
| 3536 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3537 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
| 3537 main_test_rfh()->SendNavigateWithReplacement(0, false, url2); | 3538 main_test_rfh()->SendNavigateWithReplacement(0, false, url2); |
| 3538 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3539 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 3539 } | 3540 } |
| 3540 | 3541 |
| 3541 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3542 // Tests that the URLs for renderer-initiated navigations are not displayed to |
| 3542 // the user until the navigation commits, to prevent URL spoof attacks. | 3543 // the user until the navigation commits, to prevent URL spoof attacks. |
| 3543 // See http://crbug.com/99016. | 3544 // See http://crbug.com/99016. |
| 3544 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3545 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 3545 NavigationControllerImpl& controller = controller_impl(); | 3546 NavigationControllerImpl& controller = controller_impl(); |
| (...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5204 // means that occasionally a navigation conflict will end up with one entry | 5205 // means that occasionally a navigation conflict will end up with one entry |
| 5205 // bubbling to the end of the entry list, but that's the least-bad option. | 5206 // bubbling to the end of the entry list, but that's the least-bad option. |
| 5206 EXPECT_EQ(3, controller.GetEntryCount()); | 5207 EXPECT_EQ(3, controller.GetEntryCount()); |
| 5207 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 5208 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 5208 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); | 5209 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); |
| 5209 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); | 5210 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); |
| 5210 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); | 5211 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); |
| 5211 } | 5212 } |
| 5212 | 5213 |
| 5213 } // namespace content | 5214 } // namespace content |
| OLD | NEW |