summaryrefslogtreecommitdiffstats
path: root/content/browser/web_contents/navigation_controller_impl_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/web_contents/navigation_controller_impl_unittest.cc')
-rw-r--r--content/browser/web_contents/navigation_controller_impl_unittest.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc
index f2f5017..2c7069b 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();