| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2605 ASSERT_EQ(controller.GetEntryCount(), 1); | 2605 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2606 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2606 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2607 | 2607 |
| 2608 // Load of |transient_url| completes. | 2608 // Load of |transient_url| completes. |
| 2609 test_rvh()->SendNavigate(1, transient_url); | 2609 test_rvh()->SendNavigate(1, transient_url); |
| 2610 ASSERT_EQ(controller.GetEntryCount(), 2); | 2610 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2611 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2611 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2612 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2612 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2613 } | 2613 } |
| 2614 | 2614 |
| 2615 // Ensure that renderer initiated pending entries get replaced, so that we |
| 2616 // don't show a stale virtual URL when a navigation commits. |
| 2617 // See http://crbug.com/266922. |
| 2618 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
| 2619 NavigationControllerImpl& controller = controller_impl(); |
| 2620 |
| 2621 const GURL url1("nonexistent:12121"); |
| 2622 const GURL url1_fixed("http://nonexistent:12121/"); |
| 2623 const GURL url2("http://foo"); |
| 2624 |
| 2625 // We create pending entries for renderer-initiated navigations so that we |
| 2626 // can show them in new tabs when it is safe. |
| 2627 contents()->DidStartProvisionalLoadForFrame( |
| 2628 test_rvh(), 1, -1, true, url1); |
| 2629 |
| 2630 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing |
| 2631 // the virtual URL to differ from the URL. |
| 2632 controller.GetPendingEntry()->SetURL(url1_fixed); |
| 2633 controller.GetPendingEntry()->SetVirtualURL(url1); |
| 2634 |
| 2635 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); |
| 2636 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); |
| 2637 EXPECT_TRUE( |
| 2638 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
| 2639 is_renderer_initiated()); |
| 2640 |
| 2641 // If the user clicks another link, we should replace the pending entry. |
| 2642 contents()->DidStartProvisionalLoadForFrame( |
| 2643 test_rvh(), 1, -1, true, url2); |
| 2644 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 2645 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
| 2646 |
| 2647 // Once it commits, the URL and virtual URL should reflect the actual page. |
| 2648 test_rvh()->SendNavigate(0, url2); |
| 2649 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 2650 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
| 2651 |
| 2652 // We should not replace the pending entry for an error URL. |
| 2653 contents()->DidStartProvisionalLoadForFrame( |
| 2654 test_rvh(), 1, -1, true, url1); |
| 2655 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2656 contents()->DidStartProvisionalLoadForFrame( |
| 2657 test_rvh(), 1, -1, true, GURL(kUnreachableWebDataURL)); |
| 2658 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2659 } |
| 2660 |
| 2615 // Tests that the URLs for renderer-initiated navigations are not displayed to | 2661 // Tests that the URLs for renderer-initiated navigations are not displayed to |
| 2616 // the user until the navigation commits, to prevent URL spoof attacks. | 2662 // the user until the navigation commits, to prevent URL spoof attacks. |
| 2617 // See http://crbug.com/99016. | 2663 // See http://crbug.com/99016. |
| 2618 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2664 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
| 2619 NavigationControllerImpl& controller = controller_impl(); | 2665 NavigationControllerImpl& controller = controller_impl(); |
| 2620 TestNotificationTracker notifications; | 2666 TestNotificationTracker notifications; |
| 2621 RegisterForAllNavNotifications(¬ifications, &controller); | 2667 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2622 | 2668 |
| 2623 const GURL url0("http://foo/0"); | 2669 const GURL url0("http://foo/0"); |
| 2624 const GURL url1("http://foo/1"); | 2670 const GURL url1("http://foo/1"); |
| (...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3897 PAGE_TRANSITION_LINK); | 3943 PAGE_TRANSITION_LINK); |
| 3898 session_helper_.AssertNavigationEquals(nav, | 3944 session_helper_.AssertNavigationEquals(nav, |
| 3899 windows_[0]->tabs[0]->navigations[0]); | 3945 windows_[0]->tabs[0]->navigations[0]); |
| 3900 nav.set_url(url2); | 3946 nav.set_url(url2); |
| 3901 session_helper_.AssertNavigationEquals(nav, | 3947 session_helper_.AssertNavigationEquals(nav, |
| 3902 windows_[0]->tabs[0]->navigations[1]); | 3948 windows_[0]->tabs[0]->navigations[1]); |
| 3903 } | 3949 } |
| 3904 */ | 3950 */ |
| 3905 | 3951 |
| 3906 } // namespace content | 3952 } // namespace content |
| OLD | NEW |