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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 }; | 251 }; |
252 | 252 |
253 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 253 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
254 NavigationController* controller) { | 254 NavigationController* controller) { |
255 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, | 255 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, |
256 Source<NavigationController>(controller)); | 256 Source<NavigationController>(controller)); |
257 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, | 257 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, |
258 Source<NavigationController>(controller)); | 258 Source<NavigationController>(controller)); |
259 } | 259 } |
260 | 260 |
261 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { | |
262 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); | |
263 } | |
264 | |
265 class TestWebContentsDelegate : public WebContentsDelegate { | 261 class TestWebContentsDelegate : public WebContentsDelegate { |
266 public: | 262 public: |
267 explicit TestWebContentsDelegate() : | 263 explicit TestWebContentsDelegate() : |
268 navigation_state_change_count_(0), | 264 navigation_state_change_count_(0), |
269 repost_form_warning_count_(0) {} | 265 repost_form_warning_count_(0) {} |
270 | 266 |
271 int navigation_state_change_count() { | 267 int navigation_state_change_count() { |
272 return navigation_state_change_count_; | 268 return navigation_state_change_count_; |
273 } | 269 } |
274 | 270 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // The load should now be committed. | 415 // The load should now be committed. |
420 EXPECT_EQ(controller.GetEntryCount(), 1); | 416 EXPECT_EQ(controller.GetEntryCount(), 1); |
421 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 417 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
422 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 418 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
423 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 419 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
424 EXPECT_FALSE(controller.GetPendingEntry()); | 420 EXPECT_FALSE(controller.GetPendingEntry()); |
425 ASSERT_TRUE(controller.GetVisibleEntry()); | 421 ASSERT_TRUE(controller.GetVisibleEntry()); |
426 EXPECT_FALSE(controller.CanGoBack()); | 422 EXPECT_FALSE(controller.CanGoBack()); |
427 EXPECT_FALSE(controller.CanGoForward()); | 423 EXPECT_FALSE(controller.CanGoForward()); |
428 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 424 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
429 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 425 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
430 controller.GetLastCommittedEntry())->bindings()); | |
431 | 426 |
432 // The timestamp should have been set. | 427 // The timestamp should have been set. |
433 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); | 428 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); |
434 | 429 |
435 // Load another... | 430 // Load another... |
436 controller.LoadURL( | 431 controller.LoadURL( |
437 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 432 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
438 | 433 |
439 // The load should now be pending. | 434 // The load should now be pending. |
440 EXPECT_EQ(controller.GetEntryCount(), 1); | 435 EXPECT_EQ(controller.GetEntryCount(), 1); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 load_params.referrer = | 549 load_params.referrer = |
555 Referrer(GURL("http://referrer"), blink::WebReferrerPolicyDefault); | 550 Referrer(GURL("http://referrer"), blink::WebReferrerPolicyDefault); |
556 load_params.transition_type = ui::PAGE_TRANSITION_GENERATED; | 551 load_params.transition_type = ui::PAGE_TRANSITION_GENERATED; |
557 load_params.extra_headers = "content-type: text/plain"; | 552 load_params.extra_headers = "content-type: text/plain"; |
558 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | 553 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; |
559 load_params.is_renderer_initiated = true; | 554 load_params.is_renderer_initiated = true; |
560 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 555 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
561 load_params.transferred_global_request_id = GlobalRequestID(2, 3); | 556 load_params.transferred_global_request_id = GlobalRequestID(2, 3); |
562 | 557 |
563 controller.LoadURLWithParams(load_params); | 558 controller.LoadURLWithParams(load_params); |
564 NavigationEntryImpl* entry = | 559 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
565 NavigationEntryImpl::FromNavigationEntry( | |
566 controller.GetPendingEntry()); | |
567 | 560 |
568 // The timestamp should not have been set yet. | 561 // The timestamp should not have been set yet. |
569 ASSERT_TRUE(entry); | 562 ASSERT_TRUE(entry); |
570 EXPECT_TRUE(entry->GetTimestamp().is_null()); | 563 EXPECT_TRUE(entry->GetTimestamp().is_null()); |
571 | 564 |
572 CheckNavigationEntryMatchLoadParams(load_params, entry); | 565 CheckNavigationEntryMatchLoadParams(load_params, entry); |
573 } | 566 } |
574 | 567 |
575 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { | 568 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { |
576 NavigationControllerImpl& controller = controller_impl(); | 569 NavigationControllerImpl& controller = controller_impl(); |
577 | 570 |
578 NavigationController::LoadURLParams load_params( | 571 NavigationController::LoadURLParams load_params( |
579 GURL("data:text/html,dataurl")); | 572 GURL("data:text/html,dataurl")); |
580 load_params.load_type = NavigationController::LOAD_TYPE_DATA; | 573 load_params.load_type = NavigationController::LOAD_TYPE_DATA; |
581 load_params.base_url_for_data_url = GURL("http://foo"); | 574 load_params.base_url_for_data_url = GURL("http://foo"); |
582 load_params.virtual_url_for_data_url = GURL(url::kAboutBlankURL); | 575 load_params.virtual_url_for_data_url = GURL(url::kAboutBlankURL); |
583 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; | 576 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; |
584 | 577 |
585 controller.LoadURLWithParams(load_params); | 578 controller.LoadURLWithParams(load_params); |
586 NavigationEntryImpl* entry = | 579 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
587 NavigationEntryImpl::FromNavigationEntry( | |
588 controller.GetPendingEntry()); | |
589 | 580 |
590 CheckNavigationEntryMatchLoadParams(load_params, entry); | 581 CheckNavigationEntryMatchLoadParams(load_params, entry); |
591 } | 582 } |
592 | 583 |
593 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { | 584 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { |
594 NavigationControllerImpl& controller = controller_impl(); | 585 NavigationControllerImpl& controller = controller_impl(); |
595 | 586 |
596 NavigationController::LoadURLParams load_params(GURL("https://posturl")); | 587 NavigationController::LoadURLParams load_params(GURL("https://posturl")); |
597 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 588 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
598 load_params.load_type = | 589 load_params.load_type = |
599 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | 590 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
600 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 591 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
601 | 592 |
602 | 593 |
603 const unsigned char* raw_data = | 594 const unsigned char* raw_data = |
604 reinterpret_cast<const unsigned char*>("d\n\0a2"); | 595 reinterpret_cast<const unsigned char*>("d\n\0a2"); |
605 const int length = 5; | 596 const int length = 5; |
606 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 597 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); |
607 scoped_refptr<base::RefCountedBytes> data = | 598 scoped_refptr<base::RefCountedBytes> data = |
608 base::RefCountedBytes::TakeVector(&post_data_vector); | 599 base::RefCountedBytes::TakeVector(&post_data_vector); |
609 load_params.browser_initiated_post_data = data.get(); | 600 load_params.browser_initiated_post_data = data.get(); |
610 | 601 |
611 controller.LoadURLWithParams(load_params); | 602 controller.LoadURLWithParams(load_params); |
612 NavigationEntryImpl* entry = | 603 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
613 NavigationEntryImpl::FromNavigationEntry( | |
614 controller.GetPendingEntry()); | |
615 | 604 |
616 CheckNavigationEntryMatchLoadParams(load_params, entry); | 605 CheckNavigationEntryMatchLoadParams(load_params, entry); |
617 } | 606 } |
618 | 607 |
619 // Tests what happens when the same page is loaded again. Should not create a | 608 // Tests what happens when the same page is loaded again. Should not create a |
620 // new session history entry. This is what happens when you press enter in the | 609 // new session history entry. This is what happens when you press enter in the |
621 // URL bar to reload: a pending entry is created and then it is discarded when | 610 // URL bar to reload: a pending entry is created and then it is discarded when |
622 // the load commits (because WebCore didn't actually make a new entry). | 611 // the load commits (because WebCore didn't actually make a new entry). |
623 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 612 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
624 NavigationControllerImpl& controller = controller_impl(); | 613 NavigationControllerImpl& controller = controller_impl(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 874 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
886 navigation_entry_committed_counter_ = 0; | 875 navigation_entry_committed_counter_ = 0; |
887 | 876 |
888 // Now make a pending back/forward navigation to a privileged entry. | 877 // Now make a pending back/forward navigation to a privileged entry. |
889 // The zeroth entry should be pending. | 878 // The zeroth entry should be pending. |
890 controller.GoBack(); | 879 controller.GoBack(); |
891 foo_rfh->SendBeforeUnloadACK(true); | 880 foo_rfh->SendBeforeUnloadACK(true); |
892 EXPECT_EQ(0U, notifications.size()); | 881 EXPECT_EQ(0U, notifications.size()); |
893 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 882 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
894 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 883 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
895 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( | 884 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); |
896 controller.GetPendingEntry())->bindings()); | |
897 | 885 |
898 // Before that commits, do a new navigation. | 886 // Before that commits, do a new navigation. |
899 const GURL kNewURL("http://foo/bee"); | 887 const GURL kNewURL("http://foo/bee"); |
900 foo_rfh->PrepareForCommit(kNewURL); | 888 foo_rfh->PrepareForCommit(kNewURL); |
901 foo_rfh->SendNavigate(3, kNewURL); | 889 foo_rfh->SendNavigate(3, kNewURL); |
902 | 890 |
903 // There should no longer be any pending entry, and the third navigation we | 891 // There should no longer be any pending entry, and the third navigation we |
904 // just made should be committed. | 892 // just made should be committed. |
905 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 893 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
906 navigation_entry_committed_counter_ = 0; | 894 navigation_entry_committed_counter_ = 0; |
907 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 895 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
908 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 896 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
909 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 897 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
910 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 898 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
911 controller.GetLastCommittedEntry())->bindings()); | |
912 } | 899 } |
913 | 900 |
914 // Tests navigating to an existing URL when there is a pending new navigation. | 901 // Tests navigating to an existing URL when there is a pending new navigation. |
915 // This will happen if the user enters a URL, but before that commits, the | 902 // This will happen if the user enters a URL, but before that commits, the |
916 // current page fires history.back(). | 903 // current page fires history.back(). |
917 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 904 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
918 NavigationControllerImpl& controller = controller_impl(); | 905 NavigationControllerImpl& controller = controller_impl(); |
919 TestNotificationTracker notifications; | 906 TestNotificationTracker notifications; |
920 RegisterForAllNavNotifications(¬ifications, &controller); | 907 RegisterForAllNavNotifications(¬ifications, &controller); |
921 | 908 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 RegisterForAllNavNotifications(¬ifications, &controller); | 1112 RegisterForAllNavNotifications(¬ifications, &controller); |
1126 std::vector<GURL> url_chain; | 1113 std::vector<GURL> url_chain; |
1127 | 1114 |
1128 const GURL url1("http://foo1"); | 1115 const GURL url1("http://foo1"); |
1129 const GURL url2("http://foo2"); | 1116 const GURL url2("http://foo2"); |
1130 | 1117 |
1131 // Navigate to a first, unprivileged URL. | 1118 // Navigate to a first, unprivileged URL. |
1132 controller.LoadURL( | 1119 controller.LoadURL( |
1133 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1120 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1134 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1121 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
1135 NavigationEntryImpl::FromNavigationEntry( | 1122 controller.GetPendingEntry()->bindings()); |
1136 controller.GetPendingEntry())->bindings()); | |
1137 | 1123 |
1138 // Commit. | 1124 // Commit. |
1139 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1125 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1140 orig_rfh->PrepareForCommit(url1); | 1126 orig_rfh->PrepareForCommit(url1); |
1141 orig_rfh->SendNavigate(0, url1); | 1127 orig_rfh->SendNavigate(0, url1); |
1142 EXPECT_EQ(controller.GetEntryCount(), 1); | 1128 EXPECT_EQ(controller.GetEntryCount(), 1); |
1143 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1129 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1144 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1130 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
1145 controller.GetLastCommittedEntry())->bindings()); | |
1146 | 1131 |
1147 // Manually increase the number of active frames in the SiteInstance | 1132 // Manually increase the number of active frames in the SiteInstance |
1148 // that orig_rfh belongs to, to prevent it from being destroyed when | 1133 // that orig_rfh belongs to, to prevent it from being destroyed when |
1149 // it gets swapped out, so that we can reuse orig_rfh when the | 1134 // it gets swapped out, so that we can reuse orig_rfh when the |
1150 // controller goes back. | 1135 // controller goes back. |
1151 orig_rfh->GetSiteInstance()->increment_active_frame_count(); | 1136 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
1152 | 1137 |
1153 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1138 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
1154 // transition, and set bindings on the pending RenderViewHost to simulate a | 1139 // transition, and set bindings on the pending RenderViewHost to simulate a |
1155 // privileged url. | 1140 // privileged url. |
1156 controller.LoadURL( | 1141 controller.LoadURL( |
1157 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1142 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1158 orig_rfh->PrepareForCommit(url2); | 1143 orig_rfh->PrepareForCommit(url2); |
1159 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1144 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
1160 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1145 new_rfh->GetRenderViewHost()->AllowBindings(1); |
1161 new_rfh->SendNavigate(1, url2); | 1146 new_rfh->SendNavigate(1, url2); |
1162 | 1147 |
1163 // The second load should be committed, and bindings should be remembered. | 1148 // The second load should be committed, and bindings should be remembered. |
1164 EXPECT_EQ(controller.GetEntryCount(), 2); | 1149 EXPECT_EQ(controller.GetEntryCount(), 2); |
1165 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1150 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1166 EXPECT_TRUE(controller.CanGoBack()); | 1151 EXPECT_TRUE(controller.CanGoBack()); |
1167 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( | 1152 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); |
1168 controller.GetLastCommittedEntry())->bindings()); | |
1169 | 1153 |
1170 // Going back, the first entry should still appear unprivileged. | 1154 // Going back, the first entry should still appear unprivileged. |
1171 controller.GoBack(); | 1155 controller.GoBack(); |
1172 new_rfh->PrepareForCommit(url1); | 1156 new_rfh->PrepareForCommit(url1); |
1173 orig_rfh->SendNavigate(0, url1); | 1157 orig_rfh->SendNavigate(0, url1); |
1174 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1158 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1175 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1159 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
1176 controller.GetLastCommittedEntry())->bindings()); | |
1177 } | 1160 } |
1178 | 1161 |
1179 TEST_F(NavigationControllerTest, Reload) { | 1162 TEST_F(NavigationControllerTest, Reload) { |
1180 NavigationControllerImpl& controller = controller_impl(); | 1163 NavigationControllerImpl& controller = controller_impl(); |
1181 TestNotificationTracker notifications; | 1164 TestNotificationTracker notifications; |
1182 RegisterForAllNavNotifications(¬ifications, &controller); | 1165 RegisterForAllNavNotifications(¬ifications, &controller); |
1183 | 1166 |
1184 const GURL url1("http://foo1"); | 1167 const GURL url1("http://foo1"); |
1185 | 1168 |
1186 controller.LoadURL( | 1169 controller.LoadURL( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 TEST_F(NavigationControllerTest, ReloadWithGuest) { | 1253 TEST_F(NavigationControllerTest, ReloadWithGuest) { |
1271 NavigationControllerImpl& controller = controller_impl(); | 1254 NavigationControllerImpl& controller = controller_impl(); |
1272 | 1255 |
1273 const GURL url1("http://foo1"); | 1256 const GURL url1("http://foo1"); |
1274 controller.LoadURL( | 1257 controller.LoadURL( |
1275 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1258 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1276 main_test_rfh()->SendNavigate(0, url1); | 1259 main_test_rfh()->SendNavigate(0, url1); |
1277 ASSERT_TRUE(controller.GetVisibleEntry()); | 1260 ASSERT_TRUE(controller.GetVisibleEntry()); |
1278 | 1261 |
1279 // Make the entry believe its RenderProcessHost is a guest. | 1262 // Make the entry believe its RenderProcessHost is a guest. |
1280 NavigationEntryImpl* entry1 = | 1263 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); |
1281 NavigationEntryImpl::FromNavigationEntry(controller.GetVisibleEntry()); | |
1282 reinterpret_cast<MockRenderProcessHost*>( | 1264 reinterpret_cast<MockRenderProcessHost*>( |
1283 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); | 1265 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); |
1284 | 1266 |
1285 // And reload. | 1267 // And reload. |
1286 controller.Reload(true); | 1268 controller.Reload(true); |
1287 | 1269 |
1288 // The reload is pending. Check that the NavigationEntry didn't get replaced | 1270 // The reload is pending. Check that the NavigationEntry didn't get replaced |
1289 // because of having the wrong process. | 1271 // because of having the wrong process. |
1290 EXPECT_EQ(controller.GetEntryCount(), 1); | 1272 EXPECT_EQ(controller.GetEntryCount(), 1); |
1291 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1273 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1292 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1274 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1293 | 1275 |
1294 NavigationEntryImpl* entry2 = | 1276 NavigationEntryImpl* entry2 = controller.GetPendingEntry(); |
1295 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry()); | |
1296 EXPECT_EQ(entry1, entry2); | 1277 EXPECT_EQ(entry1, entry2); |
1297 } | 1278 } |
1298 | 1279 |
1299 #if !defined(OS_ANDROID) // http://crbug.com/157428 | 1280 #if !defined(OS_ANDROID) // http://crbug.com/157428 |
1300 TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { | 1281 TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { |
1301 NavigationControllerImpl& controller = controller_impl(); | 1282 NavigationControllerImpl& controller = controller_impl(); |
1302 TestNotificationTracker notifications; | 1283 TestNotificationTracker notifications; |
1303 RegisterForAllNavNotifications(¬ifications, &controller); | 1284 RegisterForAllNavNotifications(¬ifications, &controller); |
1304 | 1285 |
1305 const GURL original_url("http://foo1"); | 1286 const GURL original_url("http://foo1"); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 // Set up some sample values. | 1360 // Set up some sample values. |
1380 const unsigned char* raw_data = | 1361 const unsigned char* raw_data = |
1381 reinterpret_cast<const unsigned char*>("post\n\n\0data"); | 1362 reinterpret_cast<const unsigned char*>("post\n\n\0data"); |
1382 const int length = 11; | 1363 const int length = 11; |
1383 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 1364 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); |
1384 scoped_refptr<base::RefCountedBytes> post_data = | 1365 scoped_refptr<base::RefCountedBytes> post_data = |
1385 base::RefCountedBytes::TakeVector(&post_data_vector); | 1366 base::RefCountedBytes::TakeVector(&post_data_vector); |
1386 GlobalRequestID transfer_id(3, 4); | 1367 GlobalRequestID transfer_id(3, 4); |
1387 | 1368 |
1388 // Set non-persisted values on the pending entry. | 1369 // Set non-persisted values on the pending entry. |
1389 NavigationEntryImpl* pending_entry = | 1370 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
1390 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry()); | |
1391 pending_entry->SetBrowserInitiatedPostData(post_data.get()); | 1371 pending_entry->SetBrowserInitiatedPostData(post_data.get()); |
1392 pending_entry->set_is_renderer_initiated(true); | 1372 pending_entry->set_is_renderer_initiated(true); |
1393 pending_entry->set_transferred_global_request_id(transfer_id); | 1373 pending_entry->set_transferred_global_request_id(transfer_id); |
1394 pending_entry->set_should_replace_entry(true); | 1374 pending_entry->set_should_replace_entry(true); |
1395 pending_entry->set_should_clear_history_list(true); | 1375 pending_entry->set_should_clear_history_list(true); |
1396 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1376 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); |
1397 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1377 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
1398 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1378 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
1399 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1379 EXPECT_TRUE(pending_entry->should_replace_entry()); |
1400 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1380 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
1401 | 1381 |
1402 // Fake a commit response. | 1382 // Fake a commit response. |
1403 main_test_rfh()->SendNavigate(1, url1); | 1383 main_test_rfh()->SendNavigate(1, url1); |
1404 | 1384 |
1405 // Certain values that are only used for pending entries get reset after | 1385 // Certain values that are only used for pending entries get reset after |
1406 // commit. | 1386 // commit. |
1407 NavigationEntryImpl* committed_entry = | 1387 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
1408 NavigationEntryImpl::FromNavigationEntry( | |
1409 controller.GetLastCommittedEntry()); | |
1410 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1388 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); |
1411 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1389 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
1412 EXPECT_EQ(GlobalRequestID(-1, -1), | 1390 EXPECT_EQ(GlobalRequestID(-1, -1), |
1413 committed_entry->transferred_global_request_id()); | 1391 committed_entry->transferred_global_request_id()); |
1414 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1392 EXPECT_FALSE(committed_entry->should_replace_entry()); |
1415 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1393 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
1416 } | 1394 } |
1417 | 1395 |
1418 // Test that Redirects are preserved after a commit. | 1396 // Test that Redirects are preserved after a commit. |
1419 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { | 1397 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { |
1420 NavigationControllerImpl& controller = controller_impl(); | 1398 NavigationControllerImpl& controller = controller_impl(); |
1421 const GURL url1("http://foo1"); | 1399 const GURL url1("http://foo1"); |
1422 controller.LoadURL( | 1400 controller.LoadURL( |
1423 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1401 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1424 | 1402 |
1425 // Set up some redirect values. | 1403 // Set up some redirect values. |
1426 std::vector<GURL> redirects; | 1404 std::vector<GURL> redirects; |
1427 redirects.push_back(GURL("http://foo2")); | 1405 redirects.push_back(GURL("http://foo2")); |
1428 | 1406 |
1429 // Set redirects on the pending entry. | 1407 // Set redirects on the pending entry. |
1430 NavigationEntryImpl* pending_entry = | 1408 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
1431 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry()); | |
1432 pending_entry->SetRedirectChain(redirects); | 1409 pending_entry->SetRedirectChain(redirects); |
1433 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); | 1410 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); |
1434 EXPECT_EQ(GURL("http://foo2"), pending_entry->GetRedirectChain()[0]); | 1411 EXPECT_EQ(GURL("http://foo2"), pending_entry->GetRedirectChain()[0]); |
1435 | 1412 |
1436 // Normal navigation will preserve redirects in the committed entry. | 1413 // Normal navigation will preserve redirects in the committed entry. |
1437 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); | 1414 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); |
1438 NavigationEntryImpl* committed_entry = | 1415 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
1439 NavigationEntryImpl::FromNavigationEntry( | |
1440 controller.GetLastCommittedEntry()); | |
1441 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); | 1416 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); |
1442 EXPECT_EQ(GURL("http://foo2"), committed_entry->GetRedirectChain()[0]); | 1417 EXPECT_EQ(GURL("http://foo2"), committed_entry->GetRedirectChain()[0]); |
1443 } | 1418 } |
1444 | 1419 |
1445 // Tests what happens when we navigate back successfully | 1420 // Tests what happens when we navigate back successfully |
1446 TEST_F(NavigationControllerTest, Back) { | 1421 TEST_F(NavigationControllerTest, Back) { |
1447 NavigationControllerImpl& controller = controller_impl(); | 1422 NavigationControllerImpl& controller = controller_impl(); |
1448 TestNotificationTracker notifications; | 1423 TestNotificationTracker notifications; |
1449 RegisterForAllNavNotifications(¬ifications, &controller); | 1424 RegisterForAllNavNotifications(¬ifications, &controller); |
1450 | 1425 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 main_test_rfh()->PrepareForCommit(kUrl3); | 1576 main_test_rfh()->PrepareForCommit(kUrl3); |
1602 main_test_rfh()->SendNavigate(2, kUrl3); | 1577 main_test_rfh()->SendNavigate(2, kUrl3); |
1603 | 1578 |
1604 // With nothing pending, say we get a navigation to the second entry. | 1579 // With nothing pending, say we get a navigation to the second entry. |
1605 main_test_rfh()->PrepareForCommit(kUrl2); | 1580 main_test_rfh()->PrepareForCommit(kUrl2); |
1606 main_test_rfh()->SendNavigate(1, kUrl2); | 1581 main_test_rfh()->SendNavigate(1, kUrl2); |
1607 | 1582 |
1608 // We know all the entries have the same site instance, so we can just grab | 1583 // We know all the entries have the same site instance, so we can just grab |
1609 // a random one for looking up other entries. | 1584 // a random one for looking up other entries. |
1610 SiteInstance* site_instance = | 1585 SiteInstance* site_instance = |
1611 NavigationEntryImpl::FromNavigationEntry( | 1586 controller.GetLastCommittedEntry()->site_instance(); |
1612 controller.GetLastCommittedEntry())->site_instance(); | |
1613 | 1587 |
1614 // That second URL should be the last committed and it should have gotten the | 1588 // That second URL should be the last committed and it should have gotten the |
1615 // new title. | 1589 // new title. |
1616 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1590 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
1617 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1591 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1618 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1592 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1619 | 1593 |
1620 // Now go forward to the last item again and say it was committed. | 1594 // Now go forward to the last item again and say it was committed. |
1621 controller.GoForward(); | 1595 controller.GoForward(); |
1622 main_test_rfh()->PrepareForCommit(kUrl3); | 1596 main_test_rfh()->PrepareForCommit(kUrl3); |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 our_controller.Restore( | 2449 our_controller.Restore( |
2476 0, | 2450 0, |
2477 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2451 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
2478 &entries); | 2452 &entries); |
2479 ASSERT_EQ(0u, entries.size()); | 2453 ASSERT_EQ(0u, entries.size()); |
2480 | 2454 |
2481 // Before navigating to the restored entry, it should have a restore_type | 2455 // Before navigating to the restored entry, it should have a restore_type |
2482 // and no SiteInstance. | 2456 // and no SiteInstance. |
2483 ASSERT_EQ(1, our_controller.GetEntryCount()); | 2457 ASSERT_EQ(1, our_controller.GetEntryCount()); |
2484 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2458 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
2485 NavigationEntryImpl::FromNavigationEntry( | 2459 our_controller.GetEntryAtIndex(0)->restore_type()); |
2486 our_controller.GetEntryAtIndex(0))->restore_type()); | 2460 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2487 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( | |
2488 our_controller.GetEntryAtIndex(0))->site_instance()); | |
2489 | 2461 |
2490 // After navigating, we should have one entry, and it should be "pending". | 2462 // After navigating, we should have one entry, and it should be "pending". |
2491 // It should now have a SiteInstance and no restore_type. | 2463 // It should now have a SiteInstance and no restore_type. |
2492 our_controller.GoToIndex(0); | 2464 our_controller.GoToIndex(0); |
2493 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2465 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2494 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 2466 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
2495 our_controller.GetPendingEntry()); | 2467 our_controller.GetPendingEntry()); |
2496 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 2468 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
2497 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2469 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2498 NavigationEntryImpl::FromNavigationEntry | 2470 our_controller.GetEntryAtIndex(0)->restore_type()); |
2499 (our_controller.GetEntryAtIndex(0))->restore_type()); | 2471 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2500 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( | |
2501 our_controller.GetEntryAtIndex(0))->site_instance()); | |
2502 | 2472 |
2503 // Timestamp should remain the same before the navigation finishes. | 2473 // Timestamp should remain the same before the navigation finishes. |
2504 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 2474 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
2505 | 2475 |
2506 // Say we navigated to that entry. | 2476 // Say we navigated to that entry. |
2507 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2477 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2508 params.page_id = 0; | 2478 params.page_id = 0; |
2509 params.url = url; | 2479 params.url = url; |
2510 params.transition = ui::PAGE_TRANSITION_LINK; | 2480 params.transition = ui::PAGE_TRANSITION_LINK; |
2511 params.should_update_history = false; | 2481 params.should_update_history = false; |
2512 params.gesture = NavigationGestureUser; | 2482 params.gesture = NavigationGestureUser; |
2513 params.is_post = false; | 2483 params.is_post = false; |
2514 params.page_state = PageState::CreateFromURL(url); | 2484 params.page_state = PageState::CreateFromURL(url); |
2515 LoadCommittedDetails details; | 2485 LoadCommittedDetails details; |
2516 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2486 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2517 &details); | 2487 &details); |
2518 | 2488 |
2519 // There should be no longer any pending entry and one committed one. This | 2489 // There should be no longer any pending entry and one committed one. This |
2520 // means that we were able to locate the entry, assign its site instance, and | 2490 // means that we were able to locate the entry, assign its site instance, and |
2521 // commit it properly. | 2491 // commit it properly. |
2522 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2492 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2523 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2493 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2524 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2494 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2525 EXPECT_EQ(url, | 2495 EXPECT_EQ( |
2526 NavigationEntryImpl::FromNavigationEntry( | 2496 url, |
2527 our_controller.GetLastCommittedEntry())->site_instance()-> | 2497 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
2528 GetSiteURL()); | |
2529 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2498 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2530 NavigationEntryImpl::FromNavigationEntry( | 2499 our_controller.GetEntryAtIndex(0)->restore_type()); |
2531 our_controller.GetEntryAtIndex(0))->restore_type()); | |
2532 | 2500 |
2533 // Timestamp should have been updated. | 2501 // Timestamp should have been updated. |
2534 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); | 2502 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); |
2535 } | 2503 } |
2536 | 2504 |
2537 // Tests that we can still navigate to a restored entry after a different | 2505 // Tests that we can still navigate to a restored entry after a different |
2538 // navigation fails and clears the pending entry. http://crbug.com/90085 | 2506 // navigation fails and clears the pending entry. http://crbug.com/90085 |
2539 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 2507 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
2540 // Create a NavigationController with a restored set of tabs. | 2508 // Create a NavigationController with a restored set of tabs. |
2541 GURL url("http://foo"); | 2509 GURL url("http://foo"); |
2542 std::vector<NavigationEntry*> entries; | 2510 std::vector<NavigationEntry*> entries; |
2543 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 2511 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
2544 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), | 2512 url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), |
2545 browser_context()); | 2513 browser_context()); |
2546 entry->SetPageID(0); | 2514 entry->SetPageID(0); |
2547 entry->SetTitle(base::ASCIIToUTF16("Title")); | 2515 entry->SetTitle(base::ASCIIToUTF16("Title")); |
2548 entry->SetPageState(PageState::CreateFromEncodedData("state")); | 2516 entry->SetPageState(PageState::CreateFromEncodedData("state")); |
2549 entries.push_back(entry); | 2517 entries.push_back(entry); |
2550 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2518 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
2551 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2519 WebContents::Create(WebContents::CreateParams(browser_context())))); |
2552 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2520 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2553 our_controller.Restore( | 2521 our_controller.Restore( |
2554 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 2522 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
2555 ASSERT_EQ(0u, entries.size()); | 2523 ASSERT_EQ(0u, entries.size()); |
2556 | 2524 |
2557 // Before navigating to the restored entry, it should have a restore_type | 2525 // Before navigating to the restored entry, it should have a restore_type |
2558 // and no SiteInstance. | 2526 // and no SiteInstance. |
2559 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2527 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
2560 NavigationEntryImpl::FromNavigationEntry( | 2528 our_controller.GetEntryAtIndex(0)->restore_type()); |
2561 our_controller.GetEntryAtIndex(0))->restore_type()); | 2529 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2562 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( | |
2563 our_controller.GetEntryAtIndex(0))->site_instance()); | |
2564 | 2530 |
2565 // After navigating, we should have one entry, and it should be "pending". | 2531 // After navigating, we should have one entry, and it should be "pending". |
2566 // It should now have a SiteInstance and no restore_type. | 2532 // It should now have a SiteInstance and no restore_type. |
2567 our_controller.GoToIndex(0); | 2533 our_controller.GoToIndex(0); |
2568 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2534 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2569 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 2535 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
2570 our_controller.GetPendingEntry()); | 2536 our_controller.GetPendingEntry()); |
2571 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 2537 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
2572 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2538 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2573 NavigationEntryImpl::FromNavigationEntry( | 2539 our_controller.GetEntryAtIndex(0)->restore_type()); |
2574 our_controller.GetEntryAtIndex(0))->restore_type()); | 2540 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2575 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( | |
2576 our_controller.GetEntryAtIndex(0))->site_instance()); | |
2577 | 2541 |
2578 // This pending navigation may have caused a different navigation to fail, | 2542 // This pending navigation may have caused a different navigation to fail, |
2579 // which causes the pending entry to be cleared. | 2543 // which causes the pending entry to be cleared. |
2580 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; | 2544 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; |
2581 fail_load_params.error_code = net::ERR_ABORTED; | 2545 fail_load_params.error_code = net::ERR_ABORTED; |
2582 fail_load_params.error_description = base::string16(); | 2546 fail_load_params.error_description = base::string16(); |
2583 fail_load_params.url = url; | 2547 fail_load_params.url = url; |
2584 fail_load_params.showing_repost_interstitial = false; | 2548 fail_load_params.showing_repost_interstitial = false; |
2585 main_test_rfh()->OnMessageReceived( | 2549 main_test_rfh()->OnMessageReceived( |
2586 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2550 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
2587 fail_load_params)); | 2551 fail_load_params)); |
2588 | 2552 |
2589 // Now the pending restored entry commits. | 2553 // Now the pending restored entry commits. |
2590 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2554 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2591 params.page_id = 0; | 2555 params.page_id = 0; |
2592 params.url = url; | 2556 params.url = url; |
2593 params.transition = ui::PAGE_TRANSITION_LINK; | 2557 params.transition = ui::PAGE_TRANSITION_LINK; |
2594 params.should_update_history = false; | 2558 params.should_update_history = false; |
2595 params.gesture = NavigationGestureUser; | 2559 params.gesture = NavigationGestureUser; |
2596 params.is_post = false; | 2560 params.is_post = false; |
2597 params.page_state = PageState::CreateFromURL(url); | 2561 params.page_state = PageState::CreateFromURL(url); |
2598 LoadCommittedDetails details; | 2562 LoadCommittedDetails details; |
2599 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2563 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2600 &details); | 2564 &details); |
2601 | 2565 |
2602 // There should be no pending entry and one committed one. | 2566 // There should be no pending entry and one committed one. |
2603 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2567 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2604 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2568 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2605 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2569 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2606 EXPECT_EQ(url, | 2570 EXPECT_EQ( |
2607 NavigationEntryImpl::FromNavigationEntry( | 2571 url, |
2608 our_controller.GetLastCommittedEntry())->site_instance()-> | 2572 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
2609 GetSiteURL()); | |
2610 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2573 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2611 NavigationEntryImpl::FromNavigationEntry( | 2574 our_controller.GetEntryAtIndex(0)->restore_type()); |
2612 our_controller.GetEntryAtIndex(0))->restore_type()); | |
2613 } | 2575 } |
2614 | 2576 |
2615 // Make sure that the page type and stuff is correct after an interstitial. | 2577 // Make sure that the page type and stuff is correct after an interstitial. |
2616 TEST_F(NavigationControllerTest, Interstitial) { | 2578 TEST_F(NavigationControllerTest, Interstitial) { |
2617 NavigationControllerImpl& controller = controller_impl(); | 2579 NavigationControllerImpl& controller = controller_impl(); |
2618 // First navigate somewhere normal. | 2580 // First navigate somewhere normal. |
2619 const GURL url1("http://foo"); | 2581 const GURL url1("http://foo"); |
2620 controller.LoadURL( | 2582 controller.LoadURL( |
2621 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2583 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2622 main_test_rfh()->PrepareForCommit(url1); | 2584 main_test_rfh()->PrepareForCommit(url1); |
2623 main_test_rfh()->SendNavigate(0, url1); | 2585 main_test_rfh()->SendNavigate(0, url1); |
2624 | 2586 |
2625 // Now navigate somewhere with an interstitial. | 2587 // Now navigate somewhere with an interstitial. |
2626 const GURL url2("http://bar"); | 2588 const GURL url2("http://bar"); |
2627 controller.LoadURL( | 2589 controller.LoadURL( |
2628 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2590 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2629 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2591 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
2630 set_page_type(PAGE_TYPE_INTERSTITIAL); | |
2631 | 2592 |
2632 // At this point the interstitial will be displayed and the load will still | 2593 // At this point the interstitial will be displayed and the load will still |
2633 // be pending. If the user continues, the load will commit. | 2594 // be pending. If the user continues, the load will commit. |
2634 main_test_rfh()->PrepareForCommit(url2); | 2595 main_test_rfh()->PrepareForCommit(url2); |
2635 main_test_rfh()->SendNavigate(1, url2); | 2596 main_test_rfh()->SendNavigate(1, url2); |
2636 | 2597 |
2637 // The page should be a normal page again. | 2598 // The page should be a normal page again. |
2638 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2599 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2639 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2600 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2640 controller.GetLastCommittedEntry()->GetPageType()); | 2601 controller.GetLastCommittedEntry()->GetPageType()); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2960 // can show them in new tabs when it is safe. | 2921 // can show them in new tabs when it is safe. |
2961 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 2922 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
2962 | 2923 |
2963 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing | 2924 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing |
2964 // the virtual URL to differ from the URL. | 2925 // the virtual URL to differ from the URL. |
2965 controller.GetPendingEntry()->SetURL(url1_fixed); | 2926 controller.GetPendingEntry()->SetURL(url1_fixed); |
2966 controller.GetPendingEntry()->SetVirtualURL(url1); | 2927 controller.GetPendingEntry()->SetVirtualURL(url1); |
2967 | 2928 |
2968 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); | 2929 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); |
2969 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); | 2930 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); |
2970 EXPECT_TRUE( | 2931 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
2971 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
2972 is_renderer_initiated()); | |
2973 | 2932 |
2974 // If the user clicks another link, we should replace the pending entry. | 2933 // If the user clicks another link, we should replace the pending entry. |
2975 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 2934 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
2976 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2935 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
2977 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 2936 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
2978 | 2937 |
2979 // Once it commits, the URL and virtual URL should reflect the actual page. | 2938 // Once it commits, the URL and virtual URL should reflect the actual page. |
2980 main_test_rfh()->SendNavigate(0, url2); | 2939 main_test_rfh()->SendNavigate(0, url2); |
2981 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2940 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2982 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 2941 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
2983 | 2942 |
2984 // We should not replace the pending entry for an error URL. | 2943 // We should not replace the pending entry for an error URL. |
2985 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 2944 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
2986 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2945 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2987 navigator->DidStartProvisionalLoad(main_test_rfh(), | 2946 navigator->DidStartProvisionalLoad(main_test_rfh(), |
2988 GURL(kUnreachableWebDataURL), false); | 2947 GURL(kUnreachableWebDataURL), false); |
2989 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2948 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2990 | 2949 |
2991 // We should remember if the pending entry will replace the current one. | 2950 // We should remember if the pending entry will replace the current one. |
2992 // http://crbug.com/308444. | 2951 // http://crbug.com/308444. |
2993 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 2952 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
2994 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2953 controller.GetPendingEntry()->set_should_replace_entry(true); |
2995 set_should_replace_entry(true); | |
2996 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 2954 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
2997 EXPECT_TRUE( | 2955 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
2998 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
2999 should_replace_entry()); | |
3000 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need | 2956 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need |
3001 // to go through the RenderViewHost. The TestRenderViewHost routes navigations | 2957 // to go through the RenderViewHost. The TestRenderViewHost routes navigations |
3002 // to the main frame. | 2958 // to the main frame. |
3003 main_test_rfh()->SendNavigate(0, url2); | 2959 main_test_rfh()->SendNavigate(0, url2); |
3004 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2960 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3005 } | 2961 } |
3006 | 2962 |
3007 // Tests that the URLs for renderer-initiated navigations are not displayed to | 2963 // Tests that the URLs for renderer-initiated navigations are not displayed to |
3008 // the user until the navigation commits, to prevent URL spoof attacks. | 2964 // the user until the navigation commits, to prevent URL spoof attacks. |
3009 // See http://crbug.com/99016. | 2965 // See http://crbug.com/99016. |
(...skipping 14 matching lines...) Expand all Loading... |
3024 main_test_rfh()->PrepareForCommit(url0); | 2980 main_test_rfh()->PrepareForCommit(url0); |
3025 main_test_rfh()->SendNavigate(0, url0); | 2981 main_test_rfh()->SendNavigate(0, url0); |
3026 | 2982 |
3027 // For link clicks (renderer-initiated navigations), the pending entry should | 2983 // For link clicks (renderer-initiated navigations), the pending entry should |
3028 // update before commit but the visible should not. | 2984 // update before commit but the visible should not. |
3029 NavigationController::LoadURLParams load_url_params(url1); | 2985 NavigationController::LoadURLParams load_url_params(url1); |
3030 load_url_params.is_renderer_initiated = true; | 2986 load_url_params.is_renderer_initiated = true; |
3031 controller.LoadURLWithParams(load_url_params); | 2987 controller.LoadURLWithParams(load_url_params); |
3032 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2988 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
3033 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2989 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3034 EXPECT_TRUE( | 2990 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3035 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
3036 is_renderer_initiated()); | |
3037 | 2991 |
3038 // After commit, both visible should be updated, there should be no pending | 2992 // After commit, both visible should be updated, there should be no pending |
3039 // entry, and we should no longer treat the entry as renderer-initiated. | 2993 // entry, and we should no longer treat the entry as renderer-initiated. |
3040 main_test_rfh()->PrepareForCommit(url1); | 2994 main_test_rfh()->PrepareForCommit(url1); |
3041 main_test_rfh()->SendNavigate(1, url1); | 2995 main_test_rfh()->SendNavigate(1, url1); |
3042 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2996 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3043 EXPECT_FALSE(controller.GetPendingEntry()); | 2997 EXPECT_FALSE(controller.GetPendingEntry()); |
3044 EXPECT_FALSE( | 2998 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
3045 NavigationEntryImpl::FromNavigationEntry( | |
3046 controller.GetLastCommittedEntry())->is_renderer_initiated()); | |
3047 | 2999 |
3048 notifications.Reset(); | 3000 notifications.Reset(); |
3049 } | 3001 } |
3050 | 3002 |
3051 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3003 // Tests that the URLs for renderer-initiated navigations in new tabs are |
3052 // displayed to the user before commit, as long as the initial about:blank | 3004 // displayed to the user before commit, as long as the initial about:blank |
3053 // page has not been modified. If so, we must revert to showing about:blank. | 3005 // page has not been modified. If so, we must revert to showing about:blank. |
3054 // See http://crbug.com/9682. | 3006 // See http://crbug.com/9682. |
3055 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { | 3007 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { |
3056 NavigationControllerImpl& controller = controller_impl(); | 3008 NavigationControllerImpl& controller = controller_impl(); |
3057 TestNotificationTracker notifications; | 3009 TestNotificationTracker notifications; |
3058 RegisterForAllNavNotifications(¬ifications, &controller); | 3010 RegisterForAllNavNotifications(¬ifications, &controller); |
3059 | 3011 |
3060 const GURL url("http://foo"); | 3012 const GURL url("http://foo"); |
3061 | 3013 |
3062 // For renderer-initiated navigations in new tabs (with no committed entries), | 3014 // For renderer-initiated navigations in new tabs (with no committed entries), |
3063 // we show the pending entry's URL as long as the about:blank page is not | 3015 // we show the pending entry's URL as long as the about:blank page is not |
3064 // modified. | 3016 // modified. |
3065 NavigationController::LoadURLParams load_url_params(url); | 3017 NavigationController::LoadURLParams load_url_params(url); |
3066 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3018 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3067 load_url_params.is_renderer_initiated = true; | 3019 load_url_params.is_renderer_initiated = true; |
3068 controller.LoadURLWithParams(load_url_params); | 3020 controller.LoadURLWithParams(load_url_params); |
3069 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 3021 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
3070 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3022 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
3071 EXPECT_TRUE( | 3023 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3072 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
3073 is_renderer_initiated()); | |
3074 EXPECT_TRUE(controller.IsInitialNavigation()); | 3024 EXPECT_TRUE(controller.IsInitialNavigation()); |
3075 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3025 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3076 | 3026 |
3077 // There should be no title yet. | 3027 // There should be no title yet. |
3078 EXPECT_TRUE(contents()->GetTitle().empty()); | 3028 EXPECT_TRUE(contents()->GetTitle().empty()); |
3079 | 3029 |
3080 // If something else modifies the contents of the about:blank page, then | 3030 // If something else modifies the contents of the about:blank page, then |
3081 // we must revert to showing about:blank to avoid a URL spoof. | 3031 // we must revert to showing about:blank to avoid a URL spoof. |
3082 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); | 3032 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
3083 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); | 3033 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
(...skipping 17 matching lines...) Expand all Loading... |
3101 // For browser-initiated navigations in new tabs (with no committed entries), | 3051 // For browser-initiated navigations in new tabs (with no committed entries), |
3102 // we show the pending entry's URL as long as the about:blank page is not | 3052 // we show the pending entry's URL as long as the about:blank page is not |
3103 // modified. This is possible in cases that the user types a URL into a popup | 3053 // modified. This is possible in cases that the user types a URL into a popup |
3104 // tab created with a slow URL. | 3054 // tab created with a slow URL. |
3105 NavigationController::LoadURLParams load_url_params(url); | 3055 NavigationController::LoadURLParams load_url_params(url); |
3106 load_url_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 3056 load_url_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
3107 load_url_params.is_renderer_initiated = false; | 3057 load_url_params.is_renderer_initiated = false; |
3108 controller.LoadURLWithParams(load_url_params); | 3058 controller.LoadURLWithParams(load_url_params); |
3109 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 3059 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
3110 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3060 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
3111 EXPECT_FALSE( | 3061 EXPECT_FALSE(controller.GetPendingEntry()->is_renderer_initiated()); |
3112 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
3113 is_renderer_initiated()); | |
3114 EXPECT_TRUE(controller.IsInitialNavigation()); | 3062 EXPECT_TRUE(controller.IsInitialNavigation()); |
3115 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3063 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3116 | 3064 |
3117 // There should be no title yet. | 3065 // There should be no title yet. |
3118 EXPECT_TRUE(contents()->GetTitle().empty()); | 3066 EXPECT_TRUE(contents()->GetTitle().empty()); |
3119 | 3067 |
3120 // Suppose it aborts before committing, if it's a 204 or download or due to a | 3068 // Suppose it aborts before committing, if it's a 204 or download or due to a |
3121 // stop or a new navigation from the user. The URL should remain visible. | 3069 // stop or a new navigation from the user. The URL should remain visible. |
3122 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; | 3070 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
3123 params.error_code = net::ERR_ABORTED; | 3071 params.error_code = net::ERR_ABORTED; |
(...skipping 28 matching lines...) Expand all Loading... |
3152 | 3100 |
3153 // For renderer-initiated navigations in new tabs (with no committed entries), | 3101 // For renderer-initiated navigations in new tabs (with no committed entries), |
3154 // we show the pending entry's URL as long as the about:blank page is not | 3102 // we show the pending entry's URL as long as the about:blank page is not |
3155 // modified. | 3103 // modified. |
3156 NavigationController::LoadURLParams load_url_params(url); | 3104 NavigationController::LoadURLParams load_url_params(url); |
3157 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3105 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3158 load_url_params.is_renderer_initiated = true; | 3106 load_url_params.is_renderer_initiated = true; |
3159 controller.LoadURLWithParams(load_url_params); | 3107 controller.LoadURLWithParams(load_url_params); |
3160 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 3108 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
3161 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3109 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
3162 EXPECT_TRUE( | 3110 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3163 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
3164 is_renderer_initiated()); | |
3165 EXPECT_TRUE(controller.IsInitialNavigation()); | 3111 EXPECT_TRUE(controller.IsInitialNavigation()); |
3166 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3112 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3167 | 3113 |
3168 // There should be no title yet. | 3114 // There should be no title yet. |
3169 EXPECT_TRUE(contents()->GetTitle().empty()); | 3115 EXPECT_TRUE(contents()->GetTitle().empty()); |
3170 | 3116 |
3171 // Suppose it aborts before committing, if it's a 204 or download or due to a | 3117 // Suppose it aborts before committing, if it's a 204 or download or due to a |
3172 // stop or a new navigation from the user. The URL should remain visible. | 3118 // stop or a new navigation from the user. The URL should remain visible. |
3173 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; | 3119 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
3174 params.error_code = net::ERR_ABORTED; | 3120 params.error_code = net::ERR_ABORTED; |
(...skipping 23 matching lines...) Expand all Loading... |
3198 const GURL url2("http://foo/bee"); | 3144 const GURL url2("http://foo/bee"); |
3199 | 3145 |
3200 // For renderer-initiated navigations in new tabs (with no committed entries), | 3146 // For renderer-initiated navigations in new tabs (with no committed entries), |
3201 // we show the pending entry's URL as long as the about:blank page is not | 3147 // we show the pending entry's URL as long as the about:blank page is not |
3202 // modified. | 3148 // modified. |
3203 NavigationController::LoadURLParams load_url_params(url1); | 3149 NavigationController::LoadURLParams load_url_params(url1); |
3204 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3150 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3205 load_url_params.is_renderer_initiated = true; | 3151 load_url_params.is_renderer_initiated = true; |
3206 controller.LoadURLWithParams(load_url_params); | 3152 controller.LoadURLWithParams(load_url_params); |
3207 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3153 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3208 EXPECT_TRUE( | 3154 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3209 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | |
3210 is_renderer_initiated()); | |
3211 EXPECT_TRUE(controller.IsInitialNavigation()); | 3155 EXPECT_TRUE(controller.IsInitialNavigation()); |
3212 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3156 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3213 | 3157 |
3214 // Simulate a commit and then starting a new pending navigation. | 3158 // Simulate a commit and then starting a new pending navigation. |
3215 main_test_rfh()->SendNavigate(0, url1); | 3159 main_test_rfh()->SendNavigate(0, url1); |
3216 NavigationController::LoadURLParams load_url2_params(url2); | 3160 NavigationController::LoadURLParams load_url2_params(url2); |
3217 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3161 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3218 load_url2_params.is_renderer_initiated = true; | 3162 load_url2_params.is_renderer_initiated = true; |
3219 controller.LoadURLWithParams(load_url2_params); | 3163 controller.LoadURLWithParams(load_url2_params); |
3220 | 3164 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3531 | 3475 |
3532 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3476 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3533 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 3477 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); |
3534 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 3478 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
3535 // This is a different site than url1, so the IDs start again at 0. | 3479 // This is a different site than url1, so the IDs start again at 0. |
3536 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); | 3480 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); |
3537 | 3481 |
3538 // The max page ID map should be copied over and updated with the max page ID | 3482 // The max page ID map should be copied over and updated with the max page ID |
3539 // from the current tab. | 3483 // from the current tab. |
3540 SiteInstance* instance1 = | 3484 SiteInstance* instance1 = |
3541 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 3485 other_controller.GetEntryAtIndex(0)->site_instance(); |
3542 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3486 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3543 | 3487 |
3544 // Ensure the SessionStorageNamespaceMaps are the same size and have | 3488 // Ensure the SessionStorageNamespaceMaps are the same size and have |
3545 // the same partitons loaded. | 3489 // the same partitons loaded. |
3546 // | 3490 // |
3547 // TODO(ajwong): We should load a url from a different partition earlier | 3491 // TODO(ajwong): We should load a url from a different partition earlier |
3548 // to make sure this map has more than one entry. | 3492 // to make sure this map has more than one entry. |
3549 const SessionStorageNamespaceMap& session_storage_namespace_map = | 3493 const SessionStorageNamespaceMap& session_storage_namespace_map = |
3550 controller.GetSessionStorageNamespaceMap(); | 3494 controller.GetSessionStorageNamespaceMap(); |
3551 const SessionStorageNamespaceMap& other_session_storage_namespace_map = | 3495 const SessionStorageNamespaceMap& other_session_storage_namespace_map = |
(...skipping 14 matching lines...) Expand all Loading... |
3566 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { | 3510 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { |
3567 NavigationControllerImpl& controller = controller_impl(); | 3511 NavigationControllerImpl& controller = controller_impl(); |
3568 const GURL url1("http://foo/1"); | 3512 const GURL url1("http://foo/1"); |
3569 const GURL url2("http://foo/2"); | 3513 const GURL url2("http://foo/2"); |
3570 const GURL url3("http://foo/3"); | 3514 const GURL url3("http://foo/3"); |
3571 | 3515 |
3572 NavigateAndCommit(url1); | 3516 NavigateAndCommit(url1); |
3573 NavigateAndCommit(url2); | 3517 NavigateAndCommit(url2); |
3574 | 3518 |
3575 // First two entries should have the same SiteInstance. | 3519 // First two entries should have the same SiteInstance. |
3576 SiteInstance* instance1 = | 3520 SiteInstance* instance1 = controller.GetEntryAtIndex(0)->site_instance(); |
3577 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)); | 3521 SiteInstance* instance2 = controller.GetEntryAtIndex(1)->site_instance(); |
3578 SiteInstance* instance2 = | |
3579 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)); | |
3580 EXPECT_EQ(instance1, instance2); | 3522 EXPECT_EQ(instance1, instance2); |
3581 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); | 3523 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); |
3582 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); | 3524 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); |
3583 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); | 3525 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); |
3584 | 3526 |
3585 scoped_ptr<TestWebContents> other_contents( | 3527 scoped_ptr<TestWebContents> other_contents( |
3586 static_cast<TestWebContents*>(CreateTestWebContents())); | 3528 static_cast<TestWebContents*>(CreateTestWebContents())); |
3587 NavigationControllerImpl& other_controller = other_contents->GetController(); | 3529 NavigationControllerImpl& other_controller = other_contents->GetController(); |
3588 other_contents->NavigateAndCommit(url3); | 3530 other_contents->NavigateAndCommit(url3); |
3589 other_contents->ExpectSetHistoryOffsetAndLength(2, 3); | 3531 other_contents->ExpectSetHistoryOffsetAndLength(2, 3); |
3590 other_controller.CopyStateFromAndPrune(&controller, false); | 3532 other_controller.CopyStateFromAndPrune(&controller, false); |
3591 | 3533 |
3592 // other_controller should now contain the 3 urls: url1, url2 and url3. | 3534 // other_controller should now contain the 3 urls: url1, url2 and url3. |
3593 | 3535 |
3594 ASSERT_EQ(3, other_controller.GetEntryCount()); | 3536 ASSERT_EQ(3, other_controller.GetEntryCount()); |
3595 | 3537 |
3596 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 3538 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
3597 | 3539 |
3598 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3540 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3599 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 3541 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
3600 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); | 3542 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
3601 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 3543 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); |
3602 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); | 3544 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); |
3603 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); | 3545 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); |
3604 | 3546 |
3605 // A new SiteInstance in a different BrowsingInstance should be used for the | 3547 // A new SiteInstance in a different BrowsingInstance should be used for the |
3606 // new tab. | 3548 // new tab. |
3607 SiteInstance* instance3 = | 3549 SiteInstance* instance3 = |
3608 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); | 3550 other_controller.GetEntryAtIndex(2)->site_instance(); |
3609 EXPECT_NE(instance3, instance1); | 3551 EXPECT_NE(instance3, instance1); |
3610 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1)); | 3552 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1)); |
3611 | 3553 |
3612 // The max page ID map should be copied over and updated with the max page ID | 3554 // The max page ID map should be copied over and updated with the max page ID |
3613 // from the current tab. | 3555 // from the current tab. |
3614 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3556 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3615 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); | 3557 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); |
3616 } | 3558 } |
3617 | 3559 |
3618 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in | 3560 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in |
(...skipping 21 matching lines...) Expand all Loading... |
3640 ASSERT_EQ(2, other_controller.GetEntryCount()); | 3582 ASSERT_EQ(2, other_controller.GetEntryCount()); |
3641 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); | 3583 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); |
3642 | 3584 |
3643 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3585 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3644 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | 3586 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
3645 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); | 3587 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); |
3646 | 3588 |
3647 // The max page ID map should be copied over and updated with the max page ID | 3589 // The max page ID map should be copied over and updated with the max page ID |
3648 // from the current tab. | 3590 // from the current tab. |
3649 SiteInstance* instance1 = | 3591 SiteInstance* instance1 = |
3650 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)); | 3592 other_controller.GetEntryAtIndex(1)->site_instance(); |
3651 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3593 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3652 } | 3594 } |
3653 | 3595 |
3654 // Test CopyStateFromAndPrune with 2 urls, the last selected and 2 entries in | 3596 // Test CopyStateFromAndPrune with 2 urls, the last selected and 2 entries in |
3655 // the target. | 3597 // the target. |
3656 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { | 3598 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { |
3657 NavigationControllerImpl& controller = controller_impl(); | 3599 NavigationControllerImpl& controller = controller_impl(); |
3658 const GURL url1("http://foo1"); | 3600 const GURL url1("http://foo1"); |
3659 const GURL url2("http://foo2"); | 3601 const GURL url2("http://foo2"); |
3660 const GURL url3("http://foo3"); | 3602 const GURL url3("http://foo3"); |
(...skipping 15 matching lines...) Expand all Loading... |
3676 ASSERT_EQ(3, other_controller.GetEntryCount()); | 3618 ASSERT_EQ(3, other_controller.GetEntryCount()); |
3677 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 3619 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
3678 | 3620 |
3679 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3621 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3680 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 3622 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
3681 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); | 3623 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); |
3682 | 3624 |
3683 // The max page ID map should be copied over and updated with the max page ID | 3625 // The max page ID map should be copied over and updated with the max page ID |
3684 // from the current tab. | 3626 // from the current tab. |
3685 SiteInstance* instance1 = | 3627 SiteInstance* instance1 = |
3686 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); | 3628 other_controller.GetEntryAtIndex(2)->site_instance(); |
3687 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3629 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3688 } | 3630 } |
3689 | 3631 |
3690 // Test CopyStateFromAndPrune with 2 urls, 2 entries in the target, with | 3632 // Test CopyStateFromAndPrune with 2 urls, 2 entries in the target, with |
3691 // not the last entry selected in the target. | 3633 // not the last entry selected in the target. |
3692 TEST_F(NavigationControllerTest, CopyStateFromAndPruneNotLast) { | 3634 TEST_F(NavigationControllerTest, CopyStateFromAndPruneNotLast) { |
3693 NavigationControllerImpl& controller = controller_impl(); | 3635 NavigationControllerImpl& controller = controller_impl(); |
3694 const GURL url1("http://foo1"); | 3636 const GURL url1("http://foo1"); |
3695 const GURL url2("http://foo2"); | 3637 const GURL url2("http://foo2"); |
3696 const GURL url3("http://foo3"); | 3638 const GURL url3("http://foo3"); |
(...skipping 17 matching lines...) Expand all Loading... |
3714 ASSERT_EQ(3, other_controller.GetEntryCount()); | 3656 ASSERT_EQ(3, other_controller.GetEntryCount()); |
3715 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 3657 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
3716 | 3658 |
3717 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3659 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3718 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 3660 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
3719 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); | 3661 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
3720 | 3662 |
3721 // The max page ID map should be copied over and updated with the max page ID | 3663 // The max page ID map should be copied over and updated with the max page ID |
3722 // from the current tab. | 3664 // from the current tab. |
3723 SiteInstance* instance1 = | 3665 SiteInstance* instance1 = |
3724 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); | 3666 other_controller.GetEntryAtIndex(2)->site_instance(); |
3725 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3667 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3726 } | 3668 } |
3727 | 3669 |
3728 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry plus | 3670 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry plus |
3729 // a pending entry in the target. | 3671 // a pending entry in the target. |
3730 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending) { | 3672 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending) { |
3731 NavigationControllerImpl& controller = controller_impl(); | 3673 NavigationControllerImpl& controller = controller_impl(); |
3732 const GURL url1("http://foo1"); | 3674 const GURL url1("http://foo1"); |
3733 const GURL url2("http://foo2"); | 3675 const GURL url2("http://foo2"); |
3734 const GURL url3("http://foo3"); | 3676 const GURL url3("http://foo3"); |
(...skipping 22 matching lines...) Expand all Loading... |
3757 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3699 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3758 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | 3700 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
3759 | 3701 |
3760 // And there should be a pending entry for url4. | 3702 // And there should be a pending entry for url4. |
3761 ASSERT_TRUE(other_controller.GetPendingEntry()); | 3703 ASSERT_TRUE(other_controller.GetPendingEntry()); |
3762 EXPECT_EQ(url4, other_controller.GetPendingEntry()->GetURL()); | 3704 EXPECT_EQ(url4, other_controller.GetPendingEntry()->GetURL()); |
3763 | 3705 |
3764 // The max page ID map should be copied over and updated with the max page ID | 3706 // The max page ID map should be copied over and updated with the max page ID |
3765 // from the current tab. | 3707 // from the current tab. |
3766 SiteInstance* instance1 = | 3708 SiteInstance* instance1 = |
3767 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 3709 other_controller.GetEntryAtIndex(0)->site_instance(); |
3768 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3710 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3769 } | 3711 } |
3770 | 3712 |
3771 // Test CopyStateFromAndPrune with 1 url in the source, 1 entry and a pending | 3713 // Test CopyStateFromAndPrune with 1 url in the source, 1 entry and a pending |
3772 // client redirect entry (with the same page ID) in the target. This used to | 3714 // client redirect entry (with the same page ID) in the target. This used to |
3773 // crash because the last committed entry would be pruned but max_page_id | 3715 // crash because the last committed entry would be pruned but max_page_id |
3774 // remembered the page ID (http://crbug.com/234809). | 3716 // remembered the page ID (http://crbug.com/234809). |
3775 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending2) { | 3717 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending2) { |
3776 NavigationControllerImpl& controller = controller_impl(); | 3718 NavigationControllerImpl& controller = controller_impl(); |
3777 const GURL url1("http://foo1"); | 3719 const GURL url1("http://foo1"); |
(...skipping 27 matching lines...) Expand all Loading... |
3805 // And there should be a pending entry for url4. | 3747 // And there should be a pending entry for url4. |
3806 ASSERT_TRUE(other_controller.GetPendingEntry()); | 3748 ASSERT_TRUE(other_controller.GetPendingEntry()); |
3807 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); | 3749 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); |
3808 | 3750 |
3809 // Let the pending entry commit. | 3751 // Let the pending entry commit. |
3810 other_contents->CommitPendingNavigation(); | 3752 other_contents->CommitPendingNavigation(); |
3811 | 3753 |
3812 // The max page ID map should be copied over and updated with the max page ID | 3754 // The max page ID map should be copied over and updated with the max page ID |
3813 // from the current tab. | 3755 // from the current tab. |
3814 SiteInstance* instance1 = | 3756 SiteInstance* instance1 = |
3815 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)); | 3757 other_controller.GetEntryAtIndex(1)->site_instance(); |
3816 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3758 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3817 } | 3759 } |
3818 | 3760 |
3819 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the | 3761 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the |
3820 // source, and 1 entry in the target. The back pending entry should be ignored. | 3762 // source, and 1 entry in the target. The back pending entry should be ignored. |
3821 TEST_F(NavigationControllerTest, CopyStateFromAndPruneSourcePending) { | 3763 TEST_F(NavigationControllerTest, CopyStateFromAndPruneSourcePending) { |
3822 NavigationControllerImpl& controller = controller_impl(); | 3764 NavigationControllerImpl& controller = controller_impl(); |
3823 const GURL url1("http://foo1"); | 3765 const GURL url1("http://foo1"); |
3824 const GURL url2("http://foo2"); | 3766 const GURL url2("http://foo2"); |
3825 const GURL url3("http://foo3"); | 3767 const GURL url3("http://foo3"); |
(...skipping 15 matching lines...) Expand all Loading... |
3841 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 3783 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
3842 | 3784 |
3843 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3785 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3844 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 3786 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
3845 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); | 3787 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
3846 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); | 3788 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); |
3847 | 3789 |
3848 // The max page ID map should be copied over and updated with the max page ID | 3790 // The max page ID map should be copied over and updated with the max page ID |
3849 // from the current tab. | 3791 // from the current tab. |
3850 SiteInstance* instance1 = | 3792 SiteInstance* instance1 = |
3851 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); | 3793 other_controller.GetEntryAtIndex(2)->site_instance(); |
3852 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3794 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3853 } | 3795 } |
3854 | 3796 |
3855 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, | 3797 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, |
3856 // when the max entry count is 3. We should prune one entry. | 3798 // when the max entry count is 3. We should prune one entry. |
3857 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { | 3799 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { |
3858 NavigationControllerImpl& controller = controller_impl(); | 3800 NavigationControllerImpl& controller = controller_impl(); |
3859 size_t original_count = NavigationControllerImpl::max_entry_count(); | 3801 size_t original_count = NavigationControllerImpl::max_entry_count(); |
3860 const int kMaxEntryCount = 3; | 3802 const int kMaxEntryCount = 3; |
3861 | 3803 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3906 TEST_F(NavigationControllerTest, CopyStateFromAndPruneReplaceEntry) { | 3848 TEST_F(NavigationControllerTest, CopyStateFromAndPruneReplaceEntry) { |
3907 NavigationControllerImpl& controller = controller_impl(); | 3849 NavigationControllerImpl& controller = controller_impl(); |
3908 const GURL url1("http://foo/1"); | 3850 const GURL url1("http://foo/1"); |
3909 const GURL url2("http://foo/2"); | 3851 const GURL url2("http://foo/2"); |
3910 const GURL url3("http://foo/3"); | 3852 const GURL url3("http://foo/3"); |
3911 | 3853 |
3912 NavigateAndCommit(url1); | 3854 NavigateAndCommit(url1); |
3913 NavigateAndCommit(url2); | 3855 NavigateAndCommit(url2); |
3914 | 3856 |
3915 // First two entries should have the same SiteInstance. | 3857 // First two entries should have the same SiteInstance. |
3916 SiteInstance* instance1 = | 3858 SiteInstance* instance1 = controller.GetEntryAtIndex(0)->site_instance(); |
3917 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)); | 3859 SiteInstance* instance2 = controller.GetEntryAtIndex(1)->site_instance(); |
3918 SiteInstance* instance2 = | |
3919 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)); | |
3920 EXPECT_EQ(instance1, instance2); | 3860 EXPECT_EQ(instance1, instance2); |
3921 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); | 3861 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); |
3922 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); | 3862 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); |
3923 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); | 3863 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); |
3924 | 3864 |
3925 scoped_ptr<TestWebContents> other_contents( | 3865 scoped_ptr<TestWebContents> other_contents( |
3926 static_cast<TestWebContents*>(CreateTestWebContents())); | 3866 static_cast<TestWebContents*>(CreateTestWebContents())); |
3927 NavigationControllerImpl& other_controller = other_contents->GetController(); | 3867 NavigationControllerImpl& other_controller = other_contents->GetController(); |
3928 other_contents->NavigateAndCommit(url3); | 3868 other_contents->NavigateAndCommit(url3); |
3929 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); | 3869 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); |
3930 other_controller.CopyStateFromAndPrune(&controller, true); | 3870 other_controller.CopyStateFromAndPrune(&controller, true); |
3931 | 3871 |
3932 // other_controller should now contain the 2 urls: url1 and url3. | 3872 // other_controller should now contain the 2 urls: url1 and url3. |
3933 | 3873 |
3934 ASSERT_EQ(2, other_controller.GetEntryCount()); | 3874 ASSERT_EQ(2, other_controller.GetEntryCount()); |
3935 | 3875 |
3936 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); | 3876 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); |
3937 | 3877 |
3938 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3878 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3939 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | 3879 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
3940 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 3880 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); |
3941 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); | 3881 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); |
3942 | 3882 |
3943 // A new SiteInstance in a different BrowsingInstance should be used for the | 3883 // A new SiteInstance in a different BrowsingInstance should be used for the |
3944 // new tab. | 3884 // new tab. |
3945 SiteInstance* instance3 = | 3885 SiteInstance* instance3 = |
3946 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)); | 3886 other_controller.GetEntryAtIndex(1)->site_instance(); |
3947 EXPECT_NE(instance3, instance1); | 3887 EXPECT_NE(instance3, instance1); |
3948 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1)); | 3888 EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1)); |
3949 | 3889 |
3950 // The max page ID map should be copied over and updated with the max page ID | 3890 // The max page ID map should be copied over and updated with the max page ID |
3951 // from the current tab. | 3891 // from the current tab. |
3952 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3892 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3953 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); | 3893 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); |
3954 } | 3894 } |
3955 | 3895 |
3956 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, when the max | 3896 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, when the max |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4338 for (int i = 0; i < 12; ++i) { | 4278 for (int i = 0; i < 12; ++i) { |
4339 const GURL url(base::StringPrintf("http://foo%d/", i)); | 4279 const GURL url(base::StringPrintf("http://foo%d/", i)); |
4340 NavigateAndCommit(url); | 4280 NavigateAndCommit(url); |
4341 EXPECT_EQ(i, controller.GetCurrentEntryIndex()); | 4281 EXPECT_EQ(i, controller.GetCurrentEntryIndex()); |
4342 } | 4282 } |
4343 | 4283 |
4344 MockScreenshotManager* screenshot_manager = | 4284 MockScreenshotManager* screenshot_manager = |
4345 new MockScreenshotManager(&controller); | 4285 new MockScreenshotManager(&controller); |
4346 controller.SetScreenshotManager(screenshot_manager); | 4286 controller.SetScreenshotManager(screenshot_manager); |
4347 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4287 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
4348 entry = NavigationEntryImpl::FromNavigationEntry( | 4288 entry = controller.GetEntryAtIndex(i); |
4349 controller.GetEntryAtIndex(i)); | |
4350 screenshot_manager->TakeScreenshotFor(entry); | 4289 screenshot_manager->TakeScreenshotFor(entry); |
4351 EXPECT_TRUE(entry->screenshot().get()); | 4290 EXPECT_TRUE(entry->screenshot().get()); |
4352 } | 4291 } |
4353 | 4292 |
4354 NavigateAndCommit(GURL("https://foo/")); | 4293 NavigateAndCommit(GURL("https://foo/")); |
4355 EXPECT_EQ(13, controller.GetEntryCount()); | 4294 EXPECT_EQ(13, controller.GetEntryCount()); |
4356 entry = NavigationEntryImpl::FromNavigationEntry( | 4295 entry = controller.GetEntryAtIndex(11); |
4357 controller.GetEntryAtIndex(11)); | |
4358 screenshot_manager->TakeScreenshotFor(entry); | 4296 screenshot_manager->TakeScreenshotFor(entry); |
4359 | 4297 |
4360 for (int i = 0; i < 2; ++i) { | 4298 for (int i = 0; i < 2; ++i) { |
4361 entry = NavigationEntryImpl::FromNavigationEntry( | 4299 entry = controller.GetEntryAtIndex(i); |
4362 controller.GetEntryAtIndex(i)); | |
4363 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4300 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4364 << " not purged"; | 4301 << " not purged"; |
4365 } | 4302 } |
4366 | 4303 |
4367 for (int i = 2; i < controller.GetEntryCount() - 1; ++i) { | 4304 for (int i = 2; i < controller.GetEntryCount() - 1; ++i) { |
4368 entry = NavigationEntryImpl::FromNavigationEntry( | 4305 entry = controller.GetEntryAtIndex(i); |
4369 controller.GetEntryAtIndex(i)); | |
4370 EXPECT_TRUE(entry->screenshot().get()) << "Screenshot not found for " << i; | 4306 EXPECT_TRUE(entry->screenshot().get()) << "Screenshot not found for " << i; |
4371 } | 4307 } |
4372 | 4308 |
4373 // Navigate to index 5 and then try to assign screenshot to all entries. | 4309 // Navigate to index 5 and then try to assign screenshot to all entries. |
4374 controller.GoToIndex(5); | 4310 controller.GoToIndex(5); |
4375 contents()->CommitPendingNavigation(); | 4311 contents()->CommitPendingNavigation(); |
4376 EXPECT_EQ(5, controller.GetCurrentEntryIndex()); | 4312 EXPECT_EQ(5, controller.GetCurrentEntryIndex()); |
4377 for (int i = 0; i < controller.GetEntryCount() - 1; ++i) { | 4313 for (int i = 0; i < controller.GetEntryCount() - 1; ++i) { |
4378 entry = NavigationEntryImpl::FromNavigationEntry( | 4314 entry = controller.GetEntryAtIndex(i); |
4379 controller.GetEntryAtIndex(i)); | |
4380 screenshot_manager->TakeScreenshotFor(entry); | 4315 screenshot_manager->TakeScreenshotFor(entry); |
4381 } | 4316 } |
4382 | 4317 |
4383 for (int i = 10; i <= 12; ++i) { | 4318 for (int i = 10; i <= 12; ++i) { |
4384 entry = NavigationEntryImpl::FromNavigationEntry( | 4319 entry = controller.GetEntryAtIndex(i); |
4385 controller.GetEntryAtIndex(i)); | |
4386 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4320 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4387 << " not purged"; | 4321 << " not purged"; |
4388 screenshot_manager->TakeScreenshotFor(entry); | 4322 screenshot_manager->TakeScreenshotFor(entry); |
4389 } | 4323 } |
4390 | 4324 |
4391 // Navigate to index 7 and assign screenshot to all entries. | 4325 // Navigate to index 7 and assign screenshot to all entries. |
4392 controller.GoToIndex(7); | 4326 controller.GoToIndex(7); |
4393 contents()->CommitPendingNavigation(); | 4327 contents()->CommitPendingNavigation(); |
4394 EXPECT_EQ(7, controller.GetCurrentEntryIndex()); | 4328 EXPECT_EQ(7, controller.GetCurrentEntryIndex()); |
4395 for (int i = 0; i < controller.GetEntryCount() - 1; ++i) { | 4329 for (int i = 0; i < controller.GetEntryCount() - 1; ++i) { |
4396 entry = NavigationEntryImpl::FromNavigationEntry( | 4330 entry = controller.GetEntryAtIndex(i); |
4397 controller.GetEntryAtIndex(i)); | |
4398 screenshot_manager->TakeScreenshotFor(entry); | 4331 screenshot_manager->TakeScreenshotFor(entry); |
4399 } | 4332 } |
4400 | 4333 |
4401 for (int i = 0; i < 2; ++i) { | 4334 for (int i = 0; i < 2; ++i) { |
4402 entry = NavigationEntryImpl::FromNavigationEntry( | 4335 entry = controller.GetEntryAtIndex(i); |
4403 controller.GetEntryAtIndex(i)); | |
4404 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4336 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4405 << " not purged"; | 4337 << " not purged"; |
4406 } | 4338 } |
4407 | 4339 |
4408 // Clear all screenshots. | 4340 // Clear all screenshots. |
4409 EXPECT_EQ(13, controller.GetEntryCount()); | 4341 EXPECT_EQ(13, controller.GetEntryCount()); |
4410 EXPECT_EQ(10, screenshot_manager->GetScreenshotCount()); | 4342 EXPECT_EQ(10, screenshot_manager->GetScreenshotCount()); |
4411 controller.ClearAllScreenshots(); | 4343 controller.ClearAllScreenshots(); |
4412 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); | 4344 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); |
4413 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4345 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
4414 entry = NavigationEntryImpl::FromNavigationEntry( | 4346 entry = controller.GetEntryAtIndex(i); |
4415 controller.GetEntryAtIndex(i)); | |
4416 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4347 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4417 << " not cleared"; | 4348 << " not cleared"; |
4418 } | 4349 } |
4419 } | 4350 } |
4420 | 4351 |
4421 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { | 4352 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { |
4422 // Navigate. | 4353 // Navigate. |
4423 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo")); | 4354 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo")); |
4424 | 4355 |
4425 // Set title and favicon. | 4356 // Set title and favicon. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4469 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 4400 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
4470 | 4401 |
4471 // Create a new pending navigation, and indicate that the session history | 4402 // Create a new pending navigation, and indicate that the session history |
4472 // should be cleared. | 4403 // should be cleared. |
4473 NavigationController::LoadURLParams params(url4); | 4404 NavigationController::LoadURLParams params(url4); |
4474 params.should_clear_history_list = true; | 4405 params.should_clear_history_list = true; |
4475 controller.LoadURLWithParams(params); | 4406 controller.LoadURLWithParams(params); |
4476 | 4407 |
4477 // Verify that the pending entry correctly indicates that the session history | 4408 // Verify that the pending entry correctly indicates that the session history |
4478 // should be cleared. | 4409 // should be cleared. |
4479 NavigationEntryImpl* entry = | 4410 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
4480 NavigationEntryImpl::FromNavigationEntry( | |
4481 controller.GetPendingEntry()); | |
4482 ASSERT_TRUE(entry); | 4411 ASSERT_TRUE(entry); |
4483 EXPECT_TRUE(entry->should_clear_history_list()); | 4412 EXPECT_TRUE(entry->should_clear_history_list()); |
4484 | 4413 |
4485 // Assume that the RF correctly cleared its history and commit the navigation. | 4414 // Assume that the RF correctly cleared its history and commit the navigation. |
4486 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 4415 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
4487 switches::kEnableBrowserSideNavigation)) { | 4416 switches::kEnableBrowserSideNavigation)) { |
4488 contents()->GetMainFrame()->PrepareForCommit(entry->GetURL()); | 4417 contents()->GetMainFrame()->PrepareForCommit(entry->GetURL()); |
4489 } | 4418 } |
4490 contents()->GetPendingMainFrame()-> | 4419 contents()->GetPendingMainFrame()-> |
4491 set_simulate_history_list_was_cleared(true); | 4420 set_simulate_history_list_was_cleared(true); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4589 { | 4518 { |
4590 LoadCommittedDetails details; | 4519 LoadCommittedDetails details; |
4591 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4520 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4592 EXPECT_EQ(PAGE_TYPE_ERROR, | 4521 EXPECT_EQ(PAGE_TYPE_ERROR, |
4593 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4522 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4594 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4523 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
4595 } | 4524 } |
4596 } | 4525 } |
4597 | 4526 |
4598 } // namespace content | 4527 } // namespace content |
OLD | NEW |