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