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