summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/history/redirect_uitest.cc13
-rw-r--r--chrome/browser/tab_contents/navigation_controller.cc9
-rw-r--r--chrome/browser/tab_contents/navigation_controller_unittest.cc53
3 files changed, 71 insertions, 4 deletions
diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc
index 301acc3..7f3e7be 100644
--- a/chrome/browser/history/redirect_uitest.cc
+++ b/chrome/browser/history/redirect_uitest.cc
@@ -71,6 +71,19 @@ TEST_F(RedirectTest, Client) {
ASSERT_EQ(1U, redirects.size());
EXPECT_EQ(final_url.spec(), redirects[0].spec());
+
+ // The address bar should display the final URL.
+ GURL tab_url;
+ EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url));
+ EXPECT_TRUE(final_url == tab_url);
+
+ // Navigate one more time.
+ NavigateToURL(first_url);
+ PlatformThread::Sleep(action_timeout_ms());
+
+ // The address bar should still display the final URL.
+ EXPECT_TRUE(tab_proxy->GetCurrentURL(&tab_url));
+ EXPECT_TRUE(final_url == tab_url);
}
TEST_F(RedirectTest, ClientEmptyReferer) {
diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc
index 4a19e58..e33898d 100644
--- a/chrome/browser/tab_contents/navigation_controller.cc
+++ b/chrome/browser/tab_contents/navigation_controller.cc
@@ -552,10 +552,8 @@ NavigationType::Type NavigationController::ClassifyNavigation(
NavigationEntry* existing_entry = entries_[existing_entry_index].get();
if (pending_entry_ &&
- pending_entry_->url() == params.url &&
existing_entry != pending_entry_ &&
- pending_entry_->page_id() == -1 &&
- pending_entry_->url() == existing_entry->url()) {
+ pending_entry_->page_id() == -1) {
// In this case, we have a pending entry for a URL but WebCore didn't do a
// new navigation. This happens when you press enter in the URL bar to
// reload. We will create a pending entry, but WebKit will convert it to
@@ -668,6 +666,9 @@ void NavigationController::RendererDidNavigateToSamePage(
// a regular user-initiated navigation.
existing_entry->set_unique_id(pending_entry_->unique_id());
+ // The URL may have changed due to redirects.
+ existing_entry->set_url(params.url);
+
DiscardNonCommittedEntries();
}
@@ -961,7 +962,7 @@ void NavigationController::DiscardNonCommittedEntriesInternal() {
void NavigationController::DiscardTransientEntry() {
if (transient_entry_index_ == -1)
return;
- entries_.erase(entries_.begin() + transient_entry_index_ );
+ entries_.erase(entries_.begin() + transient_entry_index_);
transient_entry_index_ = -1;
}
diff --git a/chrome/browser/tab_contents/navigation_controller_unittest.cc b/chrome/browser/tab_contents/navigation_controller_unittest.cc
index 38c539a..fb0761f 100644
--- a/chrome/browser/tab_contents/navigation_controller_unittest.cc
+++ b/chrome/browser/tab_contents/navigation_controller_unittest.cc
@@ -714,6 +714,59 @@ TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) {
EXPECT_FALSE(controller().CanGoForward());
}
+// Two consequent navigation for the same URL entered in should be considered
+// as SAME_PAGE navigation even when we are redirected to some other page.
+TEST_F(NavigationControllerTest, Redirect) {
+ TestNotificationTracker notifications;
+ RegisterForAllNavNotifications(&notifications, &controller());
+
+ const GURL url1("http://foo1");
+ const GURL url2("http://foo2"); // Redirection target
+
+ // First request
+ controller().LoadURL(url1, GURL(), PageTransition::TYPED);
+
+ EXPECT_EQ(0U, notifications.size());
+ rvh()->SendNavigate(0, url2);
+ EXPECT_TRUE(notifications.Check1AndReset(
+ NotificationType::NAV_ENTRY_COMMITTED));
+
+ // Second request
+ controller().LoadURL(url1, GURL(), PageTransition::TYPED);
+
+ EXPECT_TRUE(controller().pending_entry());
+ EXPECT_EQ(controller().pending_entry_index(), -1);
+ EXPECT_EQ(url1, controller().GetActiveEntry()->url());
+
+ ViewHostMsg_FrameNavigate_Params params;
+ params.page_id = 0;
+ params.url = url2;
+ params.transition = PageTransition::SERVER_REDIRECT;
+ params.redirects.push_back(GURL("http://foo1"));
+ params.redirects.push_back(GURL("http://foo2"));
+ params.should_update_history = false;
+ params.gesture = NavigationGestureAuto;
+ params.is_post = false;
+
+ NavigationController::LoadCommittedDetails details;
+
+ EXPECT_EQ(0U, notifications.size());
+ EXPECT_TRUE(controller().RendererDidNavigate(params, &details));
+ EXPECT_TRUE(notifications.Check1AndReset(
+ NotificationType::NAV_ENTRY_COMMITTED));
+
+ EXPECT_TRUE(details.type == NavigationType::SAME_PAGE);
+ EXPECT_EQ(controller().entry_count(), 1);
+ EXPECT_EQ(controller().last_committed_entry_index(), 0);
+ EXPECT_TRUE(controller().GetLastCommittedEntry());
+ EXPECT_EQ(controller().pending_entry_index(), -1);
+ EXPECT_FALSE(controller().pending_entry());
+ EXPECT_EQ(url2, controller().GetActiveEntry()->url());
+
+ EXPECT_FALSE(controller().CanGoBack());
+ EXPECT_FALSE(controller().CanGoForward());
+}
+
// Tests navigation via link click within a subframe. A new navigation entry
// should be created.
TEST_F(NavigationControllerTest, NewSubframe) {