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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 761013003: PlzNavigate: add support in several navigation controller unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_request.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file_util.h" 8 #include "base/files/file_util.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "content/browser/frame_host/cross_site_transferring_request.h" 14 #include "content/browser/frame_host/cross_site_transferring_request.h"
14 #include "content/browser/frame_host/navigation_controller_impl.h" 15 #include "content/browser/frame_host/navigation_controller_impl.h"
15 #include "content/browser/frame_host/navigation_entry_impl.h" 16 #include "content/browser/frame_host/navigation_entry_impl.h"
16 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
17 #include "content/browser/frame_host/navigator.h" 18 #include "content/browser/frame_host/navigator.h"
18 #include "content/browser/site_instance_impl.h" 19 #include "content/browser/site_instance_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 20 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/common/frame_messages.h" 21 #include "content/common/frame_messages.h"
21 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
22 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/browser/web_contents_observer.h" 28 #include "content/public/browser/web_contents_observer.h"
29 #include "content/public/common/content_switches.h"
28 #include "content/public/common/page_state.h" 30 #include "content/public/common/page_state.h"
29 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
30 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
31 #include "content/public/test/test_notification_tracker.h" 33 #include "content/public/test/test_notification_tracker.h"
32 #include "content/public/test/test_utils.h" 34 #include "content/public/test/test_utils.h"
33 #include "content/test/test_render_frame_host.h" 35 #include "content/test/test_render_frame_host.h"
34 #include "content/test/test_render_view_host.h" 36 #include "content/test/test_render_view_host.h"
35 #include "content/test/test_web_contents.h" 37 #include "content/test/test_web_contents.h"
36 #include "net/base/net_util.h" 38 #include "net/base/net_util.h"
37 #include "skia/ext/platform_canvas.h" 39 #include "skia/ext/platform_canvas.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 206 }
205 207
206 const GURL& navigated_url() const { 208 const GURL& navigated_url() const {
207 return navigated_url_; 209 return navigated_url_;
208 } 210 }
209 211
210 NavigationControllerImpl& controller_impl() { 212 NavigationControllerImpl& controller_impl() {
211 return static_cast<NavigationControllerImpl&>(controller()); 213 return static_cast<NavigationControllerImpl&>(controller());
212 } 214 }
213 215
216 const IPC::Message* GetLastNavigationRequest() {
217 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
218 switches::kEnableBrowserSideNavigation)) {
219 return process()->sink().GetFirstMessageMatching(
220 FrameMsg_RequestNavigation::ID);
221 }
222 return process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
223 }
224
225 const GURL GetNavigationURLFromIPC(const IPC::Message* message) {
226 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
227 switches::kEnableBrowserSideNavigation)) {
228 Tuple2<CommonNavigationParams, RequestNavigationParams> nav_params;
229 FrameMsg_RequestNavigation::Read(message, &nav_params);
230 return nav_params.a.url;
231 }
232 Tuple1<FrameMsg_Navigate_Params> nav_params;
233 FrameMsg_Navigate::Read(message, &nav_params);
234 return nav_params.a.common_params.url;
235 }
236
214 protected: 237 protected:
215 GURL navigated_url_; 238 GURL navigated_url_;
216 size_t navigation_entry_committed_counter_; 239 size_t navigation_entry_committed_counter_;
217 }; 240 };
218 241
219 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, 242 void RegisterForAllNavNotifications(TestNotificationTracker* tracker,
220 NavigationController* controller) { 243 NavigationController* controller) {
221 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, 244 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED,
222 Source<NavigationController>(controller)); 245 Source<NavigationController>(controller));
223 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, 246 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_FALSE(controller.CanGoForward()); 390 EXPECT_FALSE(controller.CanGoForward());
368 EXPECT_EQ(contents()->GetMaxPageID(), -1); 391 EXPECT_EQ(contents()->GetMaxPageID(), -1);
369 392
370 // Neither the timestamp nor the status code should have been set yet. 393 // Neither the timestamp nor the status code should have been set yet.
371 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 394 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
372 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); 395 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode());
373 396
374 // We should have gotten no notifications from the preceeding checks. 397 // We should have gotten no notifications from the preceeding checks.
375 EXPECT_EQ(0U, notifications.size()); 398 EXPECT_EQ(0U, notifications.size());
376 399
400 main_test_rfh()->PrepareForCommit(url1);
377 main_test_rfh()->SendNavigate(0, url1); 401 main_test_rfh()->SendNavigate(0, url1);
378 EXPECT_EQ(1U, navigation_entry_committed_counter_); 402 EXPECT_EQ(1U, navigation_entry_committed_counter_);
379 navigation_entry_committed_counter_ = 0; 403 navigation_entry_committed_counter_ = 0;
380 404
381 // The load should now be committed. 405 // The load should now be committed.
382 EXPECT_EQ(controller.GetEntryCount(), 1); 406 EXPECT_EQ(controller.GetEntryCount(), 1);
383 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 407 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
384 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 408 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
385 EXPECT_TRUE(controller.GetLastCommittedEntry()); 409 EXPECT_TRUE(controller.GetLastCommittedEntry());
386 EXPECT_FALSE(controller.GetPendingEntry()); 410 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 20 matching lines...) Expand all
407 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); 431 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
408 // TODO(darin): maybe this should really be true? 432 // TODO(darin): maybe this should really be true?
409 EXPECT_FALSE(controller.CanGoBack()); 433 EXPECT_FALSE(controller.CanGoBack());
410 EXPECT_FALSE(controller.CanGoForward()); 434 EXPECT_FALSE(controller.CanGoForward());
411 EXPECT_EQ(contents()->GetMaxPageID(), 0); 435 EXPECT_EQ(contents()->GetMaxPageID(), 0);
412 436
413 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 437 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
414 438
415 // Simulate the beforeunload ack for the cross-site transition, and then the 439 // Simulate the beforeunload ack for the cross-site transition, and then the
416 // commit. 440 // commit.
417 main_test_rfh()->SendBeforeUnloadACK(true); 441 main_test_rfh()->PrepareForCommit(url2);
418 contents()->GetPendingMainFrame()->SendNavigate(1, url2); 442 contents()->GetPendingMainFrame()->SendNavigate(1, url2);
419 EXPECT_EQ(1U, navigation_entry_committed_counter_); 443 EXPECT_EQ(1U, navigation_entry_committed_counter_);
420 navigation_entry_committed_counter_ = 0; 444 navigation_entry_committed_counter_ = 0;
421 445
422 // The load should now be committed. 446 // The load should now be committed.
423 EXPECT_EQ(controller.GetEntryCount(), 2); 447 EXPECT_EQ(controller.GetEntryCount(), 2);
424 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 448 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
425 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 449 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
426 EXPECT_TRUE(controller.GetLastCommittedEntry()); 450 EXPECT_TRUE(controller.GetLastCommittedEntry());
427 EXPECT_FALSE(controller.GetPendingEntry()); 451 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 EXPECT_EQ(1U, navigation_entry_committed_counter_); 769 EXPECT_EQ(1U, navigation_entry_committed_counter_);
746 navigation_entry_committed_counter_ = 0; 770 navigation_entry_committed_counter_ = 0;
747 771
748 // Make a pending entry to somewhere new. 772 // Make a pending entry to somewhere new.
749 const GURL kExistingURL2("http://bee"); 773 const GURL kExistingURL2("http://bee");
750 controller.LoadURL( 774 controller.LoadURL(
751 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 775 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
752 EXPECT_EQ(0U, notifications.size()); 776 EXPECT_EQ(0U, notifications.size());
753 777
754 // After the beforeunload but before it commits, do a new navigation. 778 // After the beforeunload but before it commits, do a new navigation.
755 main_test_rfh()->SendBeforeUnloadACK(true); 779 main_test_rfh()->PrepareForCommit(kExistingURL2);
756 const GURL kNewURL("http://see"); 780 const GURL kNewURL("http://see");
757 contents()->GetPendingMainFrame()->SendNavigate(3, kNewURL); 781 contents()->GetMainFrame()->SendNavigate(3, kNewURL);
758 782
759 // There should no longer be any pending entry, and the third navigation we 783 // There should no longer be any pending entry, and the third navigation we
760 // just made should be committed. 784 // just made should be committed.
761 EXPECT_EQ(1U, navigation_entry_committed_counter_); 785 EXPECT_EQ(1U, navigation_entry_committed_counter_);
762 navigation_entry_committed_counter_ = 0; 786 navigation_entry_committed_counter_ = 0;
763 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 787 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
764 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 788 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
765 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 789 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
766 } 790 }
767 791
(...skipping 22 matching lines...) Expand all
790 814
791 // Now make a pending back/forward navigation. The zeroth entry should be 815 // Now make a pending back/forward navigation. The zeroth entry should be
792 // pending. 816 // pending.
793 controller.GoBack(); 817 controller.GoBack();
794 EXPECT_EQ(0U, notifications.size()); 818 EXPECT_EQ(0U, notifications.size());
795 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 819 EXPECT_EQ(0, controller.GetPendingEntryIndex());
796 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 820 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
797 821
798 // Before that commits, do a new navigation. 822 // Before that commits, do a new navigation.
799 const GURL kNewURL("http://foo/see"); 823 const GURL kNewURL("http://foo/see");
800 LoadCommittedDetails details;
801 main_test_rfh()->SendNavigate(3, kNewURL); 824 main_test_rfh()->SendNavigate(3, kNewURL);
802 825
803 // There should no longer be any pending entry, and the third navigation we 826 // There should no longer be any pending entry, and the third navigation we
804 // just made should be committed. 827 // just made should be committed.
805 EXPECT_EQ(1U, navigation_entry_committed_counter_); 828 EXPECT_EQ(1U, navigation_entry_committed_counter_);
806 navigation_entry_committed_counter_ = 0; 829 navigation_entry_committed_counter_ = 0;
807 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 830 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
808 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 831 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
809 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 832 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
810 } 833 }
811 834
812 // Tests navigating to a new URL when there is a pending back/forward 835 // Tests navigating to a new URL when there is a pending back/forward
813 // navigation to a cross-process, privileged URL. This will happen if the user 836 // navigation to a cross-process, privileged URL. This will happen if the user
814 // hits back, but before that commits, they navigate somewhere new. 837 // hits back, but before that commits, they navigate somewhere new.
815 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { 838 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
816 NavigationControllerImpl& controller = controller_impl(); 839 NavigationControllerImpl& controller = controller_impl();
817 TestNotificationTracker notifications; 840 TestNotificationTracker notifications;
818 RegisterForAllNavNotifications(&notifications, &controller); 841 RegisterForAllNavNotifications(&notifications, &controller);
819 842
820 // First make some history, starting with a privileged URL. 843 // First make some history, starting with a privileged URL.
821 const GURL kExistingURL1("http://privileged"); 844 const GURL kExistingURL1("http://privileged");
822 controller.LoadURL( 845 controller.LoadURL(
823 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 846 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
824 // Pretend it has bindings so we can tell if we incorrectly copy it. 847 // Pretend it has bindings so we can tell if we incorrectly copy it.
825 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); 848 main_test_rfh()->GetRenderViewHost()->AllowBindings(2);
849 main_test_rfh()->PrepareForCommit(kExistingURL1);
826 main_test_rfh()->SendNavigate(0, kExistingURL1); 850 main_test_rfh()->SendNavigate(0, kExistingURL1);
827 EXPECT_EQ(1U, navigation_entry_committed_counter_); 851 EXPECT_EQ(1U, navigation_entry_committed_counter_);
828 navigation_entry_committed_counter_ = 0; 852 navigation_entry_committed_counter_ = 0;
829 853
830 // Navigate cross-process to a second URL. 854 // Navigate cross-process to a second URL.
831 const GURL kExistingURL2("http://foo/eh"); 855 const GURL kExistingURL2("http://foo/eh");
832 controller.LoadURL( 856 controller.LoadURL(
833 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 857 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
834 main_test_rfh()->SendBeforeUnloadACK(true); 858 main_test_rfh()->PrepareForCommit(kExistingURL2);
835 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); 859 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame();
836 foo_rfh->SendNavigate(1, kExistingURL2); 860 foo_rfh->SendNavigate(1, kExistingURL2);
837 EXPECT_EQ(1U, navigation_entry_committed_counter_); 861 EXPECT_EQ(1U, navigation_entry_committed_counter_);
838 navigation_entry_committed_counter_ = 0; 862 navigation_entry_committed_counter_ = 0;
839 863
840 // Now make a pending back/forward navigation to a privileged entry. 864 // Now make a pending back/forward navigation to a privileged entry.
841 // The zeroth entry should be pending. 865 // The zeroth entry should be pending.
842 controller.GoBack(); 866 controller.GoBack();
843 foo_rfh->SendBeforeUnloadACK(true); 867 foo_rfh->SendBeforeUnloadACK(true);
844 EXPECT_EQ(0U, notifications.size()); 868 EXPECT_EQ(0U, notifications.size());
845 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 869 EXPECT_EQ(0, controller.GetPendingEntryIndex());
846 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 870 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
847 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( 871 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry(
848 controller.GetPendingEntry())->bindings()); 872 controller.GetPendingEntry())->bindings());
849 873
850 // Before that commits, do a new navigation. 874 // Before that commits, do a new navigation.
851 const GURL kNewURL("http://foo/bee"); 875 const GURL kNewURL("http://foo/bee");
852 LoadCommittedDetails details;
853 foo_rfh->SendNavigate(3, kNewURL); 876 foo_rfh->SendNavigate(3, kNewURL);
854 877
855 // There should no longer be any pending entry, and the third navigation we 878 // There should no longer be any pending entry, and the third navigation we
856 // just made should be committed. 879 // just made should be committed.
857 EXPECT_EQ(1U, navigation_entry_committed_counter_); 880 EXPECT_EQ(1U, navigation_entry_committed_counter_);
858 navigation_entry_committed_counter_ = 0; 881 navigation_entry_committed_counter_ = 0;
859 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 882 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
860 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 883 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
861 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 884 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
862 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 885 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1101
1079 // Navigate to a first, unprivileged URL. 1102 // Navigate to a first, unprivileged URL.
1080 controller.LoadURL( 1103 controller.LoadURL(
1081 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1104 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1082 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, 1105 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings,
1083 NavigationEntryImpl::FromNavigationEntry( 1106 NavigationEntryImpl::FromNavigationEntry(
1084 controller.GetPendingEntry())->bindings()); 1107 controller.GetPendingEntry())->bindings());
1085 1108
1086 // Commit. 1109 // Commit.
1087 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1110 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1111 orig_rfh->PrepareForCommit(url1);
1088 orig_rfh->SendNavigate(0, url1); 1112 orig_rfh->SendNavigate(0, url1);
1089 EXPECT_EQ(controller.GetEntryCount(), 1); 1113 EXPECT_EQ(controller.GetEntryCount(), 1);
1090 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1114 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1091 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 1115 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
1092 controller.GetLastCommittedEntry())->bindings()); 1116 controller.GetLastCommittedEntry())->bindings());
1093 1117
1094 // Manually increase the number of active frames in the SiteInstance 1118 // Manually increase the number of active frames in the SiteInstance
1095 // that orig_rfh belongs to, to prevent it from being destroyed when 1119 // that orig_rfh belongs to, to prevent it from being destroyed when
1096 // it gets swapped out, so that we can reuse orig_rfh when the 1120 // it gets swapped out, so that we can reuse orig_rfh when the
1097 // controller goes back. 1121 // controller goes back.
1098 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 1122 orig_rfh->GetSiteInstance()->increment_active_frame_count();
1099 1123
1100 // Navigate to a second URL, simulate the beforeunload ack for the cross-site 1124 // Navigate to a second URL, simulate the beforeunload ack for the cross-site
1101 // transition, and set bindings on the pending RenderViewHost to simulate a 1125 // transition, and set bindings on the pending RenderViewHost to simulate a
1102 // privileged url. 1126 // privileged url.
1103 controller.LoadURL( 1127 controller.LoadURL(
1104 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1128 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1105 orig_rfh->SendBeforeUnloadACK(true); 1129 orig_rfh->PrepareForCommit(url2);
1106 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); 1130 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame();
1107 new_rfh->GetRenderViewHost()->AllowBindings(1); 1131 new_rfh->GetRenderViewHost()->AllowBindings(1);
1108 new_rfh->SendNavigate(1, url2); 1132 new_rfh->SendNavigate(1, url2);
1109 1133
1110 // The second load should be committed, and bindings should be remembered. 1134 // The second load should be committed, and bindings should be remembered.
1111 EXPECT_EQ(controller.GetEntryCount(), 2); 1135 EXPECT_EQ(controller.GetEntryCount(), 2);
1112 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1136 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1113 EXPECT_TRUE(controller.CanGoBack()); 1137 EXPECT_TRUE(controller.CanGoBack());
1114 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( 1138 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry(
1115 controller.GetLastCommittedEntry())->bindings()); 1139 controller.GetLastCommittedEntry())->bindings());
(...skipping 2772 matching lines...) Expand 10 before | Expand all | Expand 10 after
3888 NavigationControllerImpl& controller = controller_impl(); 3912 NavigationControllerImpl& controller = controller_impl();
3889 const GURL url1("http://foo/1"); 3913 const GURL url1("http://foo/1");
3890 const GURL url2("http://foo/2"); 3914 const GURL url2("http://foo/2");
3891 const GURL url3("http://foo/3"); 3915 const GURL url3("http://foo/3");
3892 3916
3893 NavigateAndCommit(url1); 3917 NavigateAndCommit(url1);
3894 NavigateAndCommit(url2); 3918 NavigateAndCommit(url2);
3895 NavigateAndCommit(url3); 3919 NavigateAndCommit(url3);
3896 controller.GoBack(); 3920 controller.GoBack();
3897 contents()->CommitPendingNavigation(); 3921 contents()->CommitPendingNavigation();
3922 process()->sink().ClearMessages();
3898 3923
3899 // Simulate the page calling history.back(). It should create a pending entry. 3924 // Simulate the page calling history.back(). It should create a pending entry.
3900 contents()->OnGoToEntryAtOffset(-1); 3925 contents()->OnGoToEntryAtOffset(-1);
3901 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 3926 EXPECT_EQ(0, controller.GetPendingEntryIndex());
3902 // The actual cross-navigation is suspended until the current RVH tells us 3927 // The actual cross-navigation is suspended until the current RVH tells us
3903 // it unloaded, simulate that. 3928 // it unloaded, simulate that.
3904 contents()->ProceedWithCrossSiteNavigation(); 3929 contents()->ProceedWithCrossSiteNavigation();
3905 // Also make sure we told the page to navigate. 3930 // Also make sure we told the page to navigate.
3906 const IPC::Message* message = 3931 const IPC::Message* message = GetLastNavigationRequest();
3907 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
3908 ASSERT_TRUE(message != NULL); 3932 ASSERT_TRUE(message != NULL);
3909 Tuple1<FrameMsg_Navigate_Params> nav_params; 3933 GURL nav_url = GetNavigationURLFromIPC(message);
3910 FrameMsg_Navigate::Read(message, &nav_params); 3934 EXPECT_EQ(url1, nav_url);
3911 EXPECT_EQ(url1, nav_params.a.common_params.url);
3912 process()->sink().ClearMessages(); 3935 process()->sink().ClearMessages();
3913 3936
3914 // Now test history.forward() 3937 // Now test history.forward()
3915 contents()->OnGoToEntryAtOffset(2); 3938 contents()->OnGoToEntryAtOffset(2);
3916 EXPECT_EQ(2, controller.GetPendingEntryIndex()); 3939 EXPECT_EQ(2, controller.GetPendingEntryIndex());
3917 // The actual cross-navigation is suspended until the current RVH tells us 3940 // The actual cross-navigation is suspended until the current RVH tells us
3918 // it unloaded, simulate that. 3941 // it unloaded, simulate that.
3919 contents()->ProceedWithCrossSiteNavigation(); 3942 contents()->ProceedWithCrossSiteNavigation();
3920 message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 3943 message = GetLastNavigationRequest();
3921 ASSERT_TRUE(message != NULL); 3944 ASSERT_TRUE(message != NULL);
3922 FrameMsg_Navigate::Read(message, &nav_params); 3945 nav_url = GetNavigationURLFromIPC(message);
3923 EXPECT_EQ(url3, nav_params.a.common_params.url); 3946 EXPECT_EQ(url3, nav_url);
3924 process()->sink().ClearMessages(); 3947 process()->sink().ClearMessages();
3925 3948
3926 controller.DiscardNonCommittedEntries(); 3949 controller.DiscardNonCommittedEntries();
3927 3950
3928 // Make sure an extravagant history.go() doesn't break. 3951 // Make sure an extravagant history.go() doesn't break.
3929 contents()->OnGoToEntryAtOffset(120); // Out of bounds. 3952 contents()->OnGoToEntryAtOffset(120); // Out of bounds.
3930 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3953 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3931 message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 3954 message = GetLastNavigationRequest();
3932 EXPECT_TRUE(message == NULL); 3955 EXPECT_TRUE(message == NULL);
3933 } 3956 }
3934 3957
3935 // Test call to PruneAllButLastCommitted for the only entry. 3958 // Test call to PruneAllButLastCommitted for the only entry.
3936 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { 3959 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) {
3937 NavigationControllerImpl& controller = controller_impl(); 3960 NavigationControllerImpl& controller = controller_impl();
3938 const GURL url1("http://foo1"); 3961 const GURL url1("http://foo1");
3939 NavigateAndCommit(url1); 3962 NavigateAndCommit(url1);
3940 3963
3941 contents()->ExpectSetHistoryOffsetAndLength(0, 1); 3964 contents()->ExpectSetHistoryOffsetAndLength(0, 1);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 4331
4309 // Verify that the pending entry correctly indicates that the session history 4332 // Verify that the pending entry correctly indicates that the session history
4310 // should be cleared. 4333 // should be cleared.
4311 NavigationEntryImpl* entry = 4334 NavigationEntryImpl* entry =
4312 NavigationEntryImpl::FromNavigationEntry( 4335 NavigationEntryImpl::FromNavigationEntry(
4313 controller.GetPendingEntry()); 4336 controller.GetPendingEntry());
4314 ASSERT_TRUE(entry); 4337 ASSERT_TRUE(entry);
4315 EXPECT_TRUE(entry->should_clear_history_list()); 4338 EXPECT_TRUE(entry->should_clear_history_list());
4316 4339
4317 // Assume that the RF correctly cleared its history and commit the navigation. 4340 // Assume that the RF correctly cleared its history and commit the navigation.
4341 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
4342 switches::kEnableBrowserSideNavigation)) {
4343 contents()->GetMainFrame()->PrepareForCommit(entry->GetURL());
4344 }
4318 contents()->GetPendingMainFrame()-> 4345 contents()->GetPendingMainFrame()->
4319 set_simulate_history_list_was_cleared(true); 4346 set_simulate_history_list_was_cleared(true);
4320 contents()->CommitPendingNavigation(); 4347 contents()->CommitPendingNavigation();
4321 4348
4322 // Verify that the NavigationController's session history was correctly 4349 // Verify that the NavigationController's session history was correctly
4323 // cleared. 4350 // cleared.
4324 EXPECT_EQ(1, controller.GetEntryCount()); 4351 EXPECT_EQ(1, controller.GetEntryCount());
4325 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4352 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4326 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4353 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4327 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4354 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4360 params.post_id = -1; 4387 params.post_id = -1;
4361 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4388 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4362 4389
4363 // Now reload. replaceState overrides the POST, so we should not show a 4390 // Now reload. replaceState overrides the POST, so we should not show a
4364 // repost warning dialog. 4391 // repost warning dialog.
4365 controller_impl().Reload(true); 4392 controller_impl().Reload(true);
4366 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4393 EXPECT_EQ(0, delegate->repost_form_warning_count());
4367 } 4394 }
4368 4395
4369 } // namespace content 4396 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698