Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: content/browser/web_contents/navigation_controller_impl_unittest.cc

Issue 21913003: Ensure that renderer-initiated pending entries can be replaced when a new (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoid memory error when replacing pending entry. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(&notifications, &controller); 2658 RegisterForAllNavNotifications(&notifications, &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
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
OLDNEW
« no previous file with comments | « content/browser/renderer_host/test_render_view_host.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698