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

Unified Diff: content/browser/web_contents/navigation_controller_impl_unittest.cc

Issue 10704048: [RDS] Reloads a page using the original request URL (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase fix 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/navigation_controller_impl_unittest.cc
diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc
index f2f5017488727319674da65813aafe22290b81d3..2c7069b80979c1ef22f7b683d77660988a57f907 100644
--- a/content/browser/web_contents/navigation_controller_impl_unittest.cc
+++ b/content/browser/web_contents/navigation_controller_impl_unittest.cc
@@ -26,6 +26,8 @@
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_view_host_observer.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_notification_tracker.h"
@@ -664,6 +666,82 @@ TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
EXPECT_FALSE(controller.CanGoForward());
}
+class TestNavigationObserver : public content::RenderViewHostObserver {
+ public:
+ TestNavigationObserver(content::RenderViewHost* render_view_host)
+ : RenderViewHostObserver(render_view_host) {
+ }
+
+ const GURL& navigated_url() const {
+ return navigated_url_;
+ }
+
+ protected:
+ virtual void Navigate(const GURL& url) OVERRIDE {
+ navigated_url_ = url;
+ }
+
+ private:
+ GURL navigated_url_;
+};
+
+TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) {
+ NavigationControllerImpl& controller = controller_impl();
+ TestNotificationTracker notifications;
+ RegisterForAllNavNotifications(&notifications, &controller);
+ TestNavigationObserver observer(test_rvh());
+
+ const GURL original_url("http://foo1");
+ const GURL final_url("http://foo2");
+
+ // Load up the original URL, but get redirected.
+ controller.LoadURL(original_url, content::Referrer(),
+ content::PAGE_TRANSITION_TYPED, std::string());
+ EXPECT_EQ(0U, notifications.size());
+ test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url);
+ EXPECT_TRUE(notifications.Check1AndReset(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED));
+
+ // The NavigationEntry should save both the original URL and the final
+ // redirected URL.
+ EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL());
+ EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL());
+
+ // Reload using the original URL.
+ controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title"));
+ controller.ReloadOriginalRequestURL(false);
+ EXPECT_EQ(0U, notifications.size());
+
+ // The reload is pending. The request should point to the original URL.
+ EXPECT_EQ(original_url, observer.navigated_url());
+ EXPECT_EQ(controller.GetEntryCount(), 1);
+ EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
+ EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
+ EXPECT_TRUE(controller.GetLastCommittedEntry());
+ EXPECT_TRUE(controller.GetPendingEntry());
+ EXPECT_FALSE(controller.CanGoBack());
+ EXPECT_FALSE(controller.CanGoForward());
+
+ // Make sure the title has been cleared (will be redrawn just after reload).
+ // Avoids a stale cached title when the new page being reloaded has no title.
+ // See http://crbug.com/96041.
+ EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty());
+
+ // Send that the navigation has proceeded; say it got redirected again.
+ test_rvh()->SendNavigate(0, final_url);
+ EXPECT_TRUE(notifications.Check1AndReset(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED));
+
+ // Now the reload is committed.
+ EXPECT_EQ(controller.GetEntryCount(), 1);
+ EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
+ EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
+ EXPECT_TRUE(controller.GetLastCommittedEntry());
+ EXPECT_FALSE(controller.GetPendingEntry());
+ EXPECT_FALSE(controller.CanGoBack());
+ EXPECT_FALSE(controller.CanGoForward());
+}
+
// Tests what happens when we navigate back successfully
TEST_F(NavigationControllerTest, Back) {
NavigationControllerImpl& controller = controller_impl();
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.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