| 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/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 411 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 412 // TODO(darin): maybe this should really be true? | 412 // TODO(darin): maybe this should really be true? |
| 413 EXPECT_FALSE(controller.CanGoBack()); | 413 EXPECT_FALSE(controller.CanGoBack()); |
| 414 EXPECT_FALSE(controller.CanGoForward()); | 414 EXPECT_FALSE(controller.CanGoForward()); |
| 415 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 415 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 416 | 416 |
| 417 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 417 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 418 | 418 |
| 419 // Simulate the beforeunload ack for the cross-site transition, and then the | 419 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 420 // commit. | 420 // commit. |
| 421 test_rvh()->SendBeforeUnloadACK(true); | 421 main_test_rfh()->SendBeforeUnloadACK(true); |
| 422 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 422 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
| 423 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 423 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 424 navigation_entry_committed_counter_ = 0; | 424 navigation_entry_committed_counter_ = 0; |
| 425 | 425 |
| 426 // The load should now be committed. | 426 // The load should now be committed. |
| 427 EXPECT_EQ(controller.GetEntryCount(), 2); | 427 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 428 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 428 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 429 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 429 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 430 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 430 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 431 EXPECT_FALSE(controller.GetPendingEntry()); | 431 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 main_test_rfh()->SendNavigate(0, url1); | 463 main_test_rfh()->SendNavigate(0, url1); |
| 464 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 464 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 465 navigation_entry_committed_counter_ = 0; | 465 navigation_entry_committed_counter_ = 0; |
| 466 | 466 |
| 467 // Load another... | 467 // Load another... |
| 468 controller.LoadURL( | 468 controller.LoadURL( |
| 469 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 469 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 470 | 470 |
| 471 // Simulate the beforeunload ack for the cross-site transition, and then the | 471 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 472 // commit. | 472 // commit. |
| 473 test_rvh()->SendBeforeUnloadACK(true); | 473 main_test_rfh()->SendBeforeUnloadACK(true); |
| 474 main_test_rfh()->SendNavigate(1, url2); | 474 main_test_rfh()->SendNavigate(1, url2); |
| 475 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 475 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 476 navigation_entry_committed_counter_ = 0; | 476 navigation_entry_committed_counter_ = 0; |
| 477 | 477 |
| 478 // The two loads should now be committed. | 478 // The two loads should now be committed. |
| 479 ASSERT_EQ(controller.GetEntryCount(), 2); | 479 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 480 | 480 |
| 481 // Timestamps should be distinct despite the clock returning the | 481 // Timestamps should be distinct despite the clock returning the |
| 482 // same value. | 482 // same value. |
| 483 EXPECT_EQ(1u, | 483 EXPECT_EQ(1u, |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 749 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 750 navigation_entry_committed_counter_ = 0; | 750 navigation_entry_committed_counter_ = 0; |
| 751 | 751 |
| 752 // Make a pending entry to somewhere new. | 752 // Make a pending entry to somewhere new. |
| 753 const GURL kExistingURL2("http://bee"); | 753 const GURL kExistingURL2("http://bee"); |
| 754 controller.LoadURL( | 754 controller.LoadURL( |
| 755 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 755 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 756 EXPECT_EQ(0U, notifications.size()); | 756 EXPECT_EQ(0U, notifications.size()); |
| 757 | 757 |
| 758 // After the beforeunload but before it commits, do a new navigation. | 758 // After the beforeunload but before it commits, do a new navigation. |
| 759 test_rvh()->SendBeforeUnloadACK(true); | 759 main_test_rfh()->SendBeforeUnloadACK(true); |
| 760 const GURL kNewURL("http://see"); | 760 const GURL kNewURL("http://see"); |
| 761 contents()->GetPendingMainFrame()->SendNavigate(3, kNewURL); | 761 contents()->GetPendingMainFrame()->SendNavigate(3, kNewURL); |
| 762 | 762 |
| 763 // There should no longer be any pending entry, and the third navigation we | 763 // There should no longer be any pending entry, and the third navigation we |
| 764 // just made should be committed. | 764 // just made should be committed. |
| 765 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 765 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 766 navigation_entry_committed_counter_ = 0; | 766 navigation_entry_committed_counter_ = 0; |
| 767 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 767 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 768 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 768 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 769 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 769 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // Pretend it has bindings so we can tell if we incorrectly copy it. | 828 // Pretend it has bindings so we can tell if we incorrectly copy it. |
| 829 test_rvh()->AllowBindings(2); | 829 test_rvh()->AllowBindings(2); |
| 830 main_test_rfh()->SendNavigate(0, kExistingURL1); | 830 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 831 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 831 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 832 navigation_entry_committed_counter_ = 0; | 832 navigation_entry_committed_counter_ = 0; |
| 833 | 833 |
| 834 // Navigate cross-process to a second URL. | 834 // Navigate cross-process to a second URL. |
| 835 const GURL kExistingURL2("http://foo/eh"); | 835 const GURL kExistingURL2("http://foo/eh"); |
| 836 controller.LoadURL( | 836 controller.LoadURL( |
| 837 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 837 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 838 test_rvh()->SendBeforeUnloadACK(true); | 838 main_test_rfh()->SendBeforeUnloadACK(true); |
| 839 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); | 839 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); |
| 840 foo_rfh->SendNavigate(1, kExistingURL2); | 840 foo_rfh->SendNavigate(1, kExistingURL2); |
| 841 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 841 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 842 navigation_entry_committed_counter_ = 0; | 842 navigation_entry_committed_counter_ = 0; |
| 843 | 843 |
| 844 // Now make a pending back/forward navigation to a privileged entry. | 844 // Now make a pending back/forward navigation to a privileged entry. |
| 845 // The zeroth entry should be pending. | 845 // The zeroth entry should be pending. |
| 846 controller.GoBack(); | 846 controller.GoBack(); |
| 847 foo_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 847 foo_rfh->SendBeforeUnloadACK(true); |
| 848 EXPECT_EQ(0U, notifications.size()); | 848 EXPECT_EQ(0U, notifications.size()); |
| 849 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 849 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 850 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 850 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 851 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( | 851 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( |
| 852 controller.GetPendingEntry())->bindings()); | 852 controller.GetPendingEntry())->bindings()); |
| 853 | 853 |
| 854 // Before that commits, do a new navigation. | 854 // Before that commits, do a new navigation. |
| 855 const GURL kNewURL("http://foo/bee"); | 855 const GURL kNewURL("http://foo/bee"); |
| 856 LoadCommittedDetails details; | 856 LoadCommittedDetails details; |
| 857 foo_rfh->SendNavigate(3, kNewURL); | 857 foo_rfh->SendNavigate(3, kNewURL); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 controller.GetPendingEntry())->bindings()); | 1088 controller.GetPendingEntry())->bindings()); |
| 1089 | 1089 |
| 1090 // Commit. | 1090 // Commit. |
| 1091 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1091 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
| 1092 orig_rfh->SendNavigate(0, url1); | 1092 orig_rfh->SendNavigate(0, url1); |
| 1093 EXPECT_EQ(controller.GetEntryCount(), 1); | 1093 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1094 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1094 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1095 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1095 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 1096 controller.GetLastCommittedEntry())->bindings()); | 1096 controller.GetLastCommittedEntry())->bindings()); |
| 1097 | 1097 |
| 1098 // Manually increase the number of active views in the SiteInstance | 1098 // Manually increase the number of active frames in the SiteInstance |
| 1099 // that orig_rfh belongs to, to prevent it from being destroyed when | 1099 // that orig_rfh belongs to, to prevent it from being destroyed when |
| 1100 // it gets swapped out, so that we can reuse orig_rfh when the | 1100 // it gets swapped out, so that we can reuse orig_rfh when the |
| 1101 // controller goes back. | 1101 // controller goes back. |
| 1102 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> | 1102 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1103 increment_active_view_count(); | |
| 1104 | 1103 |
| 1105 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1104 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
| 1106 // transition, and set bindings on the pending RenderViewHost to simulate a | 1105 // transition, and set bindings on the pending RenderViewHost to simulate a |
| 1107 // privileged url. | 1106 // privileged url. |
| 1108 controller.LoadURL( | 1107 controller.LoadURL( |
| 1109 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1108 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1110 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 1109 orig_rfh->SendBeforeUnloadACK(true); |
| 1111 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1110 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
| 1112 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1111 new_rfh->GetRenderViewHost()->AllowBindings(1); |
| 1113 new_rfh->SendNavigate(1, url2); | 1112 new_rfh->SendNavigate(1, url2); |
| 1114 | 1113 |
| 1115 // The second load should be committed, and bindings should be remembered. | 1114 // The second load should be committed, and bindings should be remembered. |
| 1116 EXPECT_EQ(controller.GetEntryCount(), 2); | 1115 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1117 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1116 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1118 EXPECT_TRUE(controller.CanGoBack()); | 1117 EXPECT_TRUE(controller.CanGoBack()); |
| 1119 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( | 1118 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( |
| 1120 controller.GetLastCommittedEntry())->bindings()); | 1119 controller.GetLastCommittedEntry())->bindings()); |
| 1121 | 1120 |
| 1122 // Going back, the first entry should still appear unprivileged. | 1121 // Going back, the first entry should still appear unprivileged. |
| 1123 controller.GoBack(); | 1122 controller.GoBack(); |
| 1124 new_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 1123 new_rfh->SendBeforeUnloadACK(true); |
| 1125 orig_rfh->SendNavigate(0, url1); | 1124 orig_rfh->SendNavigate(0, url1); |
| 1126 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1125 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1127 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( | 1126 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( |
| 1128 controller.GetLastCommittedEntry())->bindings()); | 1127 controller.GetLastCommittedEntry())->bindings()); |
| 1129 } | 1128 } |
| 1130 | 1129 |
| 1131 TEST_F(NavigationControllerTest, Reload) { | 1130 TEST_F(NavigationControllerTest, Reload) { |
| 1132 NavigationControllerImpl& controller = controller_impl(); | 1131 NavigationControllerImpl& controller = controller_impl(); |
| 1133 TestNotificationTracker notifications; | 1132 TestNotificationTracker notifications; |
| 1134 RegisterForAllNavNotifications(¬ifications, &controller); | 1133 RegisterForAllNavNotifications(¬ifications, &controller); |
| (...skipping 3220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4355 params.post_id = -1; | 4354 params.post_id = -1; |
| 4356 test_rvh()->SendNavigateWithParams(¶ms); | 4355 test_rvh()->SendNavigateWithParams(¶ms); |
| 4357 | 4356 |
| 4358 // Now reload. replaceState overrides the POST, so we should not show a | 4357 // Now reload. replaceState overrides the POST, so we should not show a |
| 4359 // repost warning dialog. | 4358 // repost warning dialog. |
| 4360 controller_impl().Reload(true); | 4359 controller_impl().Reload(true); |
| 4361 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4360 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
| 4362 } | 4361 } |
| 4363 | 4362 |
| 4364 } // namespace content | 4363 } // namespace content |
| OLD | NEW |