| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 std::vector<GURL> redirects; | 1304 std::vector<GURL> redirects; |
| 1305 redirects.push_back(GURL("http://foo2")); | 1305 redirects.push_back(GURL("http://foo2")); |
| 1306 | 1306 |
| 1307 // Set non-persisted values on the pending entry. | 1307 // Set non-persisted values on the pending entry. |
| 1308 NavigationEntryImpl* pending_entry = | 1308 NavigationEntryImpl* pending_entry = |
| 1309 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry()); | 1309 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry()); |
| 1310 pending_entry->SetBrowserInitiatedPostData(post_data.get()); | 1310 pending_entry->SetBrowserInitiatedPostData(post_data.get()); |
| 1311 pending_entry->set_is_renderer_initiated(true); | 1311 pending_entry->set_is_renderer_initiated(true); |
| 1312 pending_entry->set_transferred_global_request_id(transfer_id); | 1312 pending_entry->set_transferred_global_request_id(transfer_id); |
| 1313 pending_entry->set_should_replace_entry(true); | 1313 pending_entry->set_should_replace_entry(true); |
| 1314 pending_entry->set_redirect_chain(redirects); | 1314 pending_entry->SetRedirectChain(redirects); |
| 1315 pending_entry->set_should_clear_history_list(true); | 1315 pending_entry->set_should_clear_history_list(true); |
| 1316 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1316 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); |
| 1317 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1317 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
| 1318 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1318 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
| 1319 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1319 EXPECT_TRUE(pending_entry->should_replace_entry()); |
| 1320 EXPECT_EQ(1U, pending_entry->redirect_chain().size()); | 1320 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); |
| 1321 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1321 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
| 1322 | 1322 |
| 1323 test_rvh()->SendNavigate(0, url1); | 1323 test_rvh()->SendNavigate(0, url1); |
| 1324 | 1324 |
| 1325 // Certain values that are only used for pending entries get reset after | 1325 // Certain values that are only used for pending entries get reset after |
| 1326 // commit. | 1326 // commit. |
| 1327 NavigationEntryImpl* committed_entry = | 1327 NavigationEntryImpl* committed_entry = |
| 1328 NavigationEntryImpl::FromNavigationEntry( | 1328 NavigationEntryImpl::FromNavigationEntry( |
| 1329 controller.GetLastCommittedEntry()); | 1329 controller.GetLastCommittedEntry()); |
| 1330 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1330 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); |
| 1331 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1331 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
| 1332 EXPECT_EQ(GlobalRequestID(-1, -1), | 1332 EXPECT_EQ(GlobalRequestID(-1, -1), |
| 1333 committed_entry->transferred_global_request_id()); | 1333 committed_entry->transferred_global_request_id()); |
| 1334 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1334 EXPECT_FALSE(committed_entry->should_replace_entry()); |
| 1335 EXPECT_EQ(0U, committed_entry->redirect_chain().size()); | |
| 1336 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1335 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
| 1336 |
| 1337 // Verify new behavior -- redirects are not reset anymore. |
| 1338 EXPECT_EQ(1U, committed_entry->GetRedirectChain().size()); |
| 1337 } | 1339 } |
| 1338 | 1340 |
| 1339 // Tests what happens when we navigate back successfully | 1341 // Tests what happens when we navigate back successfully |
| 1340 TEST_F(NavigationControllerTest, Back) { | 1342 TEST_F(NavigationControllerTest, Back) { |
| 1341 NavigationControllerImpl& controller = controller_impl(); | 1343 NavigationControllerImpl& controller = controller_impl(); |
| 1342 TestNotificationTracker notifications; | 1344 TestNotificationTracker notifications; |
| 1343 RegisterForAllNavNotifications(¬ifications, &controller); | 1345 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1344 | 1346 |
| 1345 const GURL url1("http://foo1"); | 1347 const GURL url1("http://foo1"); |
| 1346 test_rvh()->SendNavigate(0, url1); | 1348 test_rvh()->SendNavigate(0, url1); |
| (...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4014 // cleared. | 4016 // cleared. |
| 4015 EXPECT_EQ(1, controller.GetEntryCount()); | 4017 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4016 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4018 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 4017 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4019 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4018 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4020 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4019 EXPECT_FALSE(controller.CanGoBack()); | 4021 EXPECT_FALSE(controller.CanGoBack()); |
| 4020 EXPECT_FALSE(controller.CanGoForward()); | 4022 EXPECT_FALSE(controller.CanGoForward()); |
| 4021 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4023 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 4022 } | 4024 } |
| 4023 | 4025 |
| 4026 // Test that GetMergedRedirectChain just returns the navigate params redirects |
| 4027 // when the user goes to a new page (by typing a URL) and the active entry has |
| 4028 // no redirects. |
| 4029 TEST_F(NavigationControllerTest, TestGetMergedRedirectChainNewPage) { |
| 4030 std::vector<GURL> active_entry_redirects; |
| 4031 ViewHostMsg_FrameNavigate_Params params; |
| 4032 std::vector<GURL> redirects; |
| 4033 redirects.push_back(GURL("http://foo0")); |
| 4034 params.redirects = redirects; |
| 4035 NavigationControllerImpl& controller = controller_impl(); |
| 4036 std::vector<GURL> result = controller.GetMergedRedirectChain( |
| 4037 params, active_entry_redirects); |
| 4038 |
| 4039 EXPECT_EQ(1U, result.size()); |
| 4040 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4041 } |
| 4042 |
| 4043 // Test that GetMergedRedirectChain just returns the active entry redirects |
| 4044 // when revisiting the same page -- the page transition was a reload or |
| 4045 // forward/back. |
| 4046 TEST_F(NavigationControllerTest, TestGetMergedRedirectChainSamePage) { |
| 4047 std::vector<GURL> active_entry_redirects; |
| 4048 active_entry_redirects.push_back(GURL("http://foo0")); |
| 4049 ViewHostMsg_FrameNavigate_Params params; |
| 4050 params.transition = content::PAGE_TRANSITION_RELOAD; |
| 4051 std::vector<GURL> redirects; |
| 4052 redirects.push_back(GURL("http://foo1")); |
| 4053 params.redirects = redirects; |
| 4054 NavigationControllerImpl& controller = controller_impl(); |
| 4055 std::vector<GURL> result = controller.GetMergedRedirectChain( |
| 4056 params, active_entry_redirects); |
| 4057 |
| 4058 EXPECT_EQ(1U, result.size()); |
| 4059 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4060 |
| 4061 params.transition = content::PAGE_TRANSITION_FORWARD_BACK; |
| 4062 result = controller.GetMergedRedirectChain(params, active_entry_redirects); |
| 4063 |
| 4064 EXPECT_EQ(1U, result.size()); |
| 4065 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4066 } |
| 4067 |
| 4068 // Test that GetMergedRedirectChain actually merges redirects from the active |
| 4069 // entry and the params when they both exist with no overlap. |
| 4070 TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeNoOverlap) { |
| 4071 std::vector<GURL> active_entry_redirects; |
| 4072 active_entry_redirects.push_back(GURL("http://foo0")); |
| 4073 active_entry_redirects.push_back(GURL("http://foo1")); |
| 4074 ViewHostMsg_FrameNavigate_Params params; |
| 4075 std::vector<GURL> redirects; |
| 4076 redirects.push_back(GURL("http://foo2")); |
| 4077 redirects.push_back(GURL("http://foo3")); |
| 4078 params.redirects = redirects; |
| 4079 NavigationControllerImpl& controller = controller_impl(); |
| 4080 std::vector<GURL> result = controller.GetMergedRedirectChain( |
| 4081 params, active_entry_redirects); |
| 4082 |
| 4083 EXPECT_EQ(4U, result.size()); |
| 4084 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4085 EXPECT_EQ(GURL("http://foo1"), result.at(1)); |
| 4086 EXPECT_EQ(GURL("http://foo2"), result.at(2)); |
| 4087 EXPECT_EQ(GURL("http://foo3"), result.at(3)); |
| 4088 } |
| 4089 |
| 4090 // Test that GetMergedRedirectChain actually merges redirects from the active |
| 4091 // entry and the params when they both exist, and that a single URL overlap |
| 4092 // is removed. |
| 4093 TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeOneOverlap) { |
| 4094 std::vector<GURL> active_entry_redirects; |
| 4095 active_entry_redirects.push_back(GURL("http://foo0")); |
| 4096 active_entry_redirects.push_back(GURL("http://foo1")); |
| 4097 ViewHostMsg_FrameNavigate_Params params; |
| 4098 std::vector<GURL> redirects; |
| 4099 redirects.push_back(GURL("http://foo1")); |
| 4100 redirects.push_back(GURL("http://foo2")); |
| 4101 params.redirects = redirects; |
| 4102 NavigationControllerImpl& controller = controller_impl(); |
| 4103 std::vector<GURL> result = controller.GetMergedRedirectChain( |
| 4104 params, active_entry_redirects); |
| 4105 |
| 4106 EXPECT_EQ(3U, result.size()); |
| 4107 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4108 EXPECT_EQ(GURL("http://foo1"), result.at(1)); |
| 4109 EXPECT_EQ(GURL("http://foo2"), result.at(2)); |
| 4110 } |
| 4111 |
| 4112 // Test that GetMergedRedirectChain actually merges redirects from the active |
| 4113 // entry and the params when they both exist, and that multiple URLs that |
| 4114 // overlap with the end of the active entry are removed. |
| 4115 TEST_F(NavigationControllerTest, TestGetMergedRedirectChainMergeTwoOverlap) { |
| 4116 std::vector<GURL> active_entry_redirects; |
| 4117 active_entry_redirects.push_back(GURL("http://foo0")); |
| 4118 active_entry_redirects.push_back(GURL("http://foo1")); |
| 4119 ViewHostMsg_FrameNavigate_Params params; |
| 4120 std::vector<GURL> redirects; |
| 4121 redirects.push_back(GURL("http://foo1")); |
| 4122 redirects.push_back(GURL("http://foo1")); |
| 4123 params.redirects = redirects; |
| 4124 NavigationControllerImpl& controller = controller_impl(); |
| 4125 std::vector<GURL> result = controller.GetMergedRedirectChain( |
| 4126 params, active_entry_redirects); |
| 4127 |
| 4128 EXPECT_EQ(2U, result.size()); |
| 4129 EXPECT_EQ(GURL("http://foo0"), result.at(0)); |
| 4130 EXPECT_EQ(GURL("http://foo1"), result.at(1)); |
| 4131 } |
| 4132 |
| 4024 } // namespace content | 4133 } // namespace content |
| OLD | NEW |