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 | |
2653 // Tests that the URLs for renderer-initiated navigations are not displayed to | 2615 // Tests that the URLs for renderer-initiated navigations are not displayed to |
2654 // the user until the navigation commits, to prevent URL spoof attacks. | 2616 // the user until the navigation commits, to prevent URL spoof attacks. |
2655 // See http://crbug.com/99016. | 2617 // See http://crbug.com/99016. |
2656 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2618 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
2657 NavigationControllerImpl& controller = controller_impl(); | 2619 NavigationControllerImpl& controller = controller_impl(); |
2658 TestNotificationTracker notifications; | 2620 TestNotificationTracker notifications; |
2659 RegisterForAllNavNotifications(¬ifications, &controller); | 2621 RegisterForAllNavNotifications(¬ifications, &controller); |
2660 | 2622 |
2661 const GURL url0("http://foo/0"); | 2623 const GURL url0("http://foo/0"); |
2662 const GURL url1("http://foo/1"); | 2624 const GURL url1("http://foo/1"); |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3935 PAGE_TRANSITION_LINK); | 3897 PAGE_TRANSITION_LINK); |
3936 session_helper_.AssertNavigationEquals(nav, | 3898 session_helper_.AssertNavigationEquals(nav, |
3937 windows_[0]->tabs[0]->navigations[0]); | 3899 windows_[0]->tabs[0]->navigations[0]); |
3938 nav.set_url(url2); | 3900 nav.set_url(url2); |
3939 session_helper_.AssertNavigationEquals(nav, | 3901 session_helper_.AssertNavigationEquals(nav, |
3940 windows_[0]->tabs[0]->navigations[1]); | 3902 windows_[0]->tabs[0]->navigations[1]); |
3941 } | 3903 } |
3942 */ | 3904 */ |
3943 | 3905 |
3944 } // namespace content | 3906 } // namespace content |
OLD | NEW |