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

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

Issue 10870073: Change how NavigationController reloads transient entries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove outdated comment Created 8 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 controller.AddTransientEntry(transient_entry); 2057 controller.AddTransientEntry(transient_entry);
2058 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2058 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL());
2059 EXPECT_TRUE(controller.CanGoForward()); 2059 EXPECT_TRUE(controller.CanGoForward());
2060 controller.GoForward(); 2060 controller.GoForward();
2061 // We should have navigated, transient entry should be gone. 2061 // We should have navigated, transient entry should be gone.
2062 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); 2062 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL());
2063 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2063 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2064 test_rvh()->SendNavigate(3, url3); 2064 test_rvh()->SendNavigate(3, url3);
2065 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2065 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2066 2066
2067 // Ensure the URLS are correct. 2067 // Ensure the URLs are correct.
2068 EXPECT_EQ(controller.GetEntryCount(), 5); 2068 EXPECT_EQ(controller.GetEntryCount(), 5);
2069 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2069 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2070 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); 2070 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1);
2071 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); 2071 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2);
2072 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3); 2072 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3);
2073 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); 2073 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4);
2074 } 2074 }
2075 2075
2076 // Test that Reload initiates a new navigation to a transient entry's URL.
2077 TEST_F(NavigationControllerTest, ReloadTransient) {
2078 NavigationControllerImpl& controller = controller_impl();
2079 const GURL url0("http://foo/0");
2080 const GURL url1("http://foo/1");
2081 const GURL transient_url("http://foo/transient");
2082
2083 // Load |url0|, and start a pending navigation to |url1|.
2084 controller.LoadURL(
2085 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
2086 test_rvh()->SendNavigate(0, url0);
2087 controller.LoadURL(
2088 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
2089
2090 // A transient entry is added, interrupting the navigation.
2091 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
2092 transient_entry->SetURL(transient_url);
2093 controller.AddTransientEntry(transient_entry);
2094 EXPECT_TRUE(controller.GetTransientEntry());
2095 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL());
2096
2097 // The page is reloaded, which should remove the pending entry for |url1| and
2098 // the transient entry for |transient_url|, and start a navigation to
2099 // |transient_url|.
2100 controller.Reload(true);
2101 EXPECT_FALSE(controller.GetTransientEntry());
2102 EXPECT_TRUE(controller.GetPendingEntry());
2103 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL());
2104 ASSERT_EQ(controller.GetEntryCount(), 1);
2105 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2106
2107 // Load of |transient_url| completes.
2108 test_rvh()->SendNavigate(1, transient_url);
2109 ASSERT_EQ(controller.GetEntryCount(), 2);
2110 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2111 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url);
2112 }
2113
2076 // Tests that the URLs for renderer-initiated navigations are not displayed to 2114 // Tests that the URLs for renderer-initiated navigations are not displayed to
2077 // the user until the navigation commits, to prevent URL spoof attacks. 2115 // the user until the navigation commits, to prevent URL spoof attacks.
2078 // See http://crbug.com/99016. 2116 // See http://crbug.com/99016.
2079 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 2117 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
2080 NavigationControllerImpl& controller = controller_impl(); 2118 NavigationControllerImpl& controller = controller_impl();
2081 TestNotificationTracker notifications; 2119 TestNotificationTracker notifications;
2082 RegisterForAllNavNotifications(&notifications, &controller); 2120 RegisterForAllNavNotifications(&notifications, &controller);
2083 2121
2084 const GURL url0("http://foo/0"); 2122 const GURL url0("http://foo/0");
2085 const GURL url1("http://foo/1"); 2123 const GURL url1("http://foo/1");
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 TabNavigation nav(0, url0, GURL(), string16(), 2877 TabNavigation nav(0, url0, GURL(), string16(),
2840 webkit_glue::CreateHistoryStateForURL(url0), 2878 webkit_glue::CreateHistoryStateForURL(url0),
2841 content::PAGE_TRANSITION_LINK); 2879 content::PAGE_TRANSITION_LINK);
2842 session_helper_.AssertNavigationEquals(nav, 2880 session_helper_.AssertNavigationEquals(nav,
2843 windows_[0]->tabs[0]->navigations[0]); 2881 windows_[0]->tabs[0]->navigations[0]);
2844 nav.set_url(url2); 2882 nav.set_url(url2);
2845 session_helper_.AssertNavigationEquals(nav, 2883 session_helper_.AssertNavigationEquals(nav,
2846 windows_[0]->tabs[0]->navigations[1]); 2884 windows_[0]->tabs[0]->navigations[1]);
2847 } 2885 }
2848 */ 2886 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698