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

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

Issue 101573003: Add the navigation redirect-chain to Sync sessions proto for offline analysis. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android unit test (state_serializer_unittests.cc). Created 6 years, 11 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/frame_host/navigation_controller_impl_unittest.cc
diff --git a/content/browser/frame_host/navigation_controller_impl_unittest.cc b/content/browser/frame_host/navigation_controller_impl_unittest.cc
index 318fb62f16bc980634bf89b757205924d5524707..49531bf9ffb4cccb415a48dfcae5f73df4ab64d9 100644
--- a/content/browser/frame_host/navigation_controller_impl_unittest.cc
+++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc
@@ -1311,13 +1311,13 @@ TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) {
pending_entry->set_is_renderer_initiated(true);
pending_entry->set_transferred_global_request_id(transfer_id);
pending_entry->set_should_replace_entry(true);
- pending_entry->set_redirect_chain(redirects);
+ pending_entry->SetRedirectChain(redirects);
pending_entry->set_should_clear_history_list(true);
EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData());
EXPECT_TRUE(pending_entry->is_renderer_initiated());
EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id());
EXPECT_TRUE(pending_entry->should_replace_entry());
- EXPECT_EQ(1U, pending_entry->redirect_chain().size());
+ EXPECT_EQ(1U, pending_entry->GetRedirectChain().size());
EXPECT_TRUE(pending_entry->should_clear_history_list());
test_rvh()->SendNavigate(0, url1);
@@ -1332,8 +1332,10 @@ TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) {
EXPECT_EQ(GlobalRequestID(-1, -1),
committed_entry->transferred_global_request_id());
EXPECT_FALSE(committed_entry->should_replace_entry());
- EXPECT_EQ(0U, committed_entry->redirect_chain().size());
EXPECT_FALSE(committed_entry->should_clear_history_list());
+
+ // Verify new behavior -- redirects are not reset anymore.
+ EXPECT_EQ(1U, committed_entry->GetRedirectChain().size());
}
// Tests what happens when we navigate back successfully
@@ -4021,4 +4023,111 @@ TEST_F(NavigationControllerTest, ClearHistoryList) {
EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
}
+// Test that GetMergedRedirectChain just returns the navigate params redirects
+// when the user goes to a new page (by typing a URL) and the active entry has
+// no redirects.
+TEST_F(NavigationControllerTest, TestGetMergedRedirectChainNewPage) {
+ std::vector<GURL> active_entry_redirects;
+ ViewHostMsg_FrameNavigate_Params params;
+ std::vector<GURL> redirects;
+ redirects.push_back(GURL("http://foo0"));
+ params.redirects = redirects;
+ NavigationControllerImpl& controller = controller_impl();
+ std::vector<GURL> result = controller.GetMergedRedirectChain(
+ params, active_entry_redirects);
+
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+}
+
+// Test that GetMergedRedirectChain just returns the active entry redirects
+// when revisiting the same page -- the page transition was a reload or
+// forward/back.
+TEST_F(NavigationControllerTest, TestGetMergedRedirectChainSamePage) {
+ std::vector<GURL> active_entry_redirects;
+ active_entry_redirects.push_back(GURL("http://foo0"));
+ ViewHostMsg_FrameNavigate_Params params;
+ params.transition = content::PAGE_TRANSITION_RELOAD;
+ std::vector<GURL> redirects;
+ redirects.push_back(GURL("http://foo1"));
+ params.redirects = redirects;
+ NavigationControllerImpl& controller = controller_impl();
+ std::vector<GURL> result = controller.GetMergedRedirectChain(
+ params, active_entry_redirects);
+
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+
+ params.transition = content::PAGE_TRANSITION_FORWARD_BACK;
+ result = controller.GetMergedRedirectChain(params, active_entry_redirects);
+
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+}
+
+// Test that GetMergedRedirectChain actually merges redirects from the active
+// entry and the params when they both exist with no overlap.
+TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeNoOverlap) {
+ std::vector<GURL> active_entry_redirects;
+ active_entry_redirects.push_back(GURL("http://foo0"));
+ active_entry_redirects.push_back(GURL("http://foo1"));
+ ViewHostMsg_FrameNavigate_Params params;
+ std::vector<GURL> redirects;
+ redirects.push_back(GURL("http://foo2"));
+ redirects.push_back(GURL("http://foo3"));
+ params.redirects = redirects;
+ NavigationControllerImpl& controller = controller_impl();
+ std::vector<GURL> result = controller.GetMergedRedirectChain(
+ params, active_entry_redirects);
+
+ EXPECT_EQ(4U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+ EXPECT_EQ(GURL("http://foo1"), result.at(1));
+ EXPECT_EQ(GURL("http://foo2"), result.at(2));
+ EXPECT_EQ(GURL("http://foo3"), result.at(3));
+}
+
+// Test that GetMergedRedirectChain actually merges redirects from the active
+// entry and the params when they both exist, and that a single URL overlap
+// is removed.
+TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeOneOverlap) {
+ std::vector<GURL> active_entry_redirects;
+ active_entry_redirects.push_back(GURL("http://foo0"));
+ active_entry_redirects.push_back(GURL("http://foo1"));
+ ViewHostMsg_FrameNavigate_Params params;
+ std::vector<GURL> redirects;
+ redirects.push_back(GURL("http://foo1"));
+ redirects.push_back(GURL("http://foo2"));
+ params.redirects = redirects;
+ NavigationControllerImpl& controller = controller_impl();
+ std::vector<GURL> result = controller.GetMergedRedirectChain(
+ params, active_entry_redirects);
+
+ EXPECT_EQ(3U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+ EXPECT_EQ(GURL("http://foo1"), result.at(1));
+ EXPECT_EQ(GURL("http://foo2"), result.at(2));
+}
+
+// Test that GetMergedRedirectChain actually merges redirects from the active
+// entry and the params when they both exist, and that multiple URLs that
+// overlap with the end of the active entry are removed.
+TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeTwoOverlap) {
+ std::vector<GURL> active_entry_redirects;
+ active_entry_redirects.push_back(GURL("http://foo0"));
+ active_entry_redirects.push_back(GURL("http://foo1"));
+ ViewHostMsg_FrameNavigate_Params params;
+ std::vector<GURL> redirects;
+ redirects.push_back(GURL("http://foo1"));
+ redirects.push_back(GURL("http://foo1"));
+ params.redirects = redirects;
+ NavigationControllerImpl& controller = controller_impl();
+ std::vector<GURL> result = controller.GetMergedRedirectChain(
+ params, active_entry_redirects);
+
+ EXPECT_EQ(2U, result.size());
+ EXPECT_EQ(GURL("http://foo0"), result.at(0));
+ EXPECT_EQ(GURL("http://foo1"), result.at(1));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698