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

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: 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/test/test_web_contents.h » ('j') | content/test/test_web_contents.cc » ('J')
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_FALSE(controller.CanGoForward()); 369 EXPECT_FALSE(controller.CanGoForward());
368 EXPECT_EQ(contents()->GetMaxPageID(), -1); 370 EXPECT_EQ(contents()->GetMaxPageID(), -1);
369 371
370 // Neither the timestamp nor the status code should have been set yet. 372 // Neither the timestamp nor the status code should have been set yet.
371 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 373 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
372 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); 374 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode());
373 375
374 // We should have gotten no notifications from the preceeding checks. 376 // We should have gotten no notifications from the preceeding checks.
375 EXPECT_EQ(0U, notifications.size()); 377 EXPECT_EQ(0U, notifications.size());
376 378
377 main_test_rfh()->SendNavigate(0, url1); 379 contents()->CommitNavigationWithPageID(0, url1, false);
nasko 2014/12/11 00:51:45 Why do we have false in this case?
378 EXPECT_EQ(1U, navigation_entry_committed_counter_); 380 EXPECT_EQ(1U, navigation_entry_committed_counter_);
379 navigation_entry_committed_counter_ = 0; 381 navigation_entry_committed_counter_ = 0;
380 382
381 // The load should now be committed. 383 // The load should now be committed.
382 EXPECT_EQ(controller.GetEntryCount(), 1); 384 EXPECT_EQ(controller.GetEntryCount(), 1);
383 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 385 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
384 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 386 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
385 EXPECT_TRUE(controller.GetLastCommittedEntry()); 387 EXPECT_TRUE(controller.GetLastCommittedEntry());
386 EXPECT_FALSE(controller.GetPendingEntry()); 388 EXPECT_FALSE(controller.GetPendingEntry());
387 ASSERT_TRUE(controller.GetVisibleEntry()); 389 ASSERT_TRUE(controller.GetVisibleEntry());
(...skipping 19 matching lines...) Expand all
407 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); 409 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
408 // TODO(darin): maybe this should really be true? 410 // TODO(darin): maybe this should really be true?
409 EXPECT_FALSE(controller.CanGoBack()); 411 EXPECT_FALSE(controller.CanGoBack());
410 EXPECT_FALSE(controller.CanGoForward()); 412 EXPECT_FALSE(controller.CanGoForward());
411 EXPECT_EQ(contents()->GetMaxPageID(), 0); 413 EXPECT_EQ(contents()->GetMaxPageID(), 0);
412 414
413 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 415 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
414 416
415 // Simulate the beforeunload ack for the cross-site transition, and then the 417 // Simulate the beforeunload ack for the cross-site transition, and then the
416 // commit. 418 // commit.
417 main_test_rfh()->SendBeforeUnloadACK(true); 419 contents()->CommitNavigationWithPageID(1, url2, true);
418 contents()->GetPendingMainFrame()->SendNavigate(1, url2);
419 EXPECT_EQ(1U, navigation_entry_committed_counter_); 420 EXPECT_EQ(1U, navigation_entry_committed_counter_);
420 navigation_entry_committed_counter_ = 0; 421 navigation_entry_committed_counter_ = 0;
421 422
422 // The load should now be committed. 423 // The load should now be committed.
423 EXPECT_EQ(controller.GetEntryCount(), 2); 424 EXPECT_EQ(controller.GetEntryCount(), 2);
424 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 425 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
425 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 426 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
426 EXPECT_TRUE(controller.GetLastCommittedEntry()); 427 EXPECT_TRUE(controller.GetLastCommittedEntry());
427 EXPECT_FALSE(controller.GetPendingEntry()); 428 EXPECT_FALSE(controller.GetPendingEntry());
428 ASSERT_TRUE(controller.GetVisibleEntry()); 429 ASSERT_TRUE(controller.GetVisibleEntry());
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 // commits. 735 // commits.
735 TEST_F(NavigationControllerTest, LoadURL_NewPending) { 736 TEST_F(NavigationControllerTest, LoadURL_NewPending) {
736 NavigationControllerImpl& controller = controller_impl(); 737 NavigationControllerImpl& controller = controller_impl();
737 TestNotificationTracker notifications; 738 TestNotificationTracker notifications;
738 RegisterForAllNavNotifications(&notifications, &controller); 739 RegisterForAllNavNotifications(&notifications, &controller);
739 740
740 // First make an existing committed entry. 741 // First make an existing committed entry.
741 const GURL kExistingURL1("http://eh"); 742 const GURL kExistingURL1("http://eh");
742 controller.LoadURL( 743 controller.LoadURL(
743 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 744 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
744 main_test_rfh()->SendNavigate(0, kExistingURL1); 745 contents()->CommitPendingNavigation();
745 EXPECT_EQ(1U, navigation_entry_committed_counter_); 746 EXPECT_EQ(1U, navigation_entry_committed_counter_);
746 navigation_entry_committed_counter_ = 0; 747 navigation_entry_committed_counter_ = 0;
747 748
748 // Make a pending entry to somewhere new. 749 // Make a pending entry to somewhere new.
749 const GURL kExistingURL2("http://bee"); 750 const GURL kExistingURL2("http://bee");
750 controller.LoadURL( 751 controller.LoadURL(
751 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 752 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
752 EXPECT_EQ(0U, notifications.size()); 753 EXPECT_EQ(0U, notifications.size());
753 754
754 // After the beforeunload but before it commits, do a new navigation. 755 // After the beforeunload but before it commits, do a new navigation.
755 main_test_rfh()->SendBeforeUnloadACK(true); 756 contents()->ProceedNavigationWithRendererResponse(kExistingURL2);
756 const GURL kNewURL("http://see"); 757 const GURL kNewURL("http://see");
757 contents()->GetPendingMainFrame()->SendNavigate(3, kNewURL); 758 contents()->SimulateRendererInitiatedNavigation(3, kNewURL);
758 759
759 // There should no longer be any pending entry, and the third navigation we 760 // There should no longer be any pending entry, and the third navigation we
760 // just made should be committed. 761 // just made should be committed.
761 EXPECT_EQ(1U, navigation_entry_committed_counter_); 762 EXPECT_EQ(1U, navigation_entry_committed_counter_);
762 navigation_entry_committed_counter_ = 0; 763 navigation_entry_committed_counter_ = 0;
763 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 764 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
764 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 765 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
765 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 766 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
766 } 767 }
767 768
(...skipping 22 matching lines...) Expand all
790 791
791 // Now make a pending back/forward navigation. The zeroth entry should be 792 // Now make a pending back/forward navigation. The zeroth entry should be
792 // pending. 793 // pending.
793 controller.GoBack(); 794 controller.GoBack();
794 EXPECT_EQ(0U, notifications.size()); 795 EXPECT_EQ(0U, notifications.size());
795 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 796 EXPECT_EQ(0, controller.GetPendingEntryIndex());
796 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 797 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
797 798
798 // Before that commits, do a new navigation. 799 // Before that commits, do a new navigation.
799 const GURL kNewURL("http://foo/see"); 800 const GURL kNewURL("http://foo/see");
800 LoadCommittedDetails details; 801 LoadCommittedDetails details;
nasko 2014/12/11 00:51:45 drive-by nit: It looks like details isn't used any
clamy 2014/12/15 17:01:38 Done.
801 main_test_rfh()->SendNavigate(3, kNewURL); 802 main_test_rfh()->SendNavigate(3, kNewURL);
802 803
803 // There should no longer be any pending entry, and the third navigation we 804 // There should no longer be any pending entry, and the third navigation we
804 // just made should be committed. 805 // just made should be committed.
805 EXPECT_EQ(1U, navigation_entry_committed_counter_); 806 EXPECT_EQ(1U, navigation_entry_committed_counter_);
806 navigation_entry_committed_counter_ = 0; 807 navigation_entry_committed_counter_ = 0;
807 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 808 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
808 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 809 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
809 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 810 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
810 } 811 }
811 812
812 // Tests navigating to a new URL when there is a pending back/forward 813 // 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 814 // navigation to a cross-process, privileged URL. This will happen if the user
814 // hits back, but before that commits, they navigate somewhere new. 815 // hits back, but before that commits, they navigate somewhere new.
815 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { 816 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
816 NavigationControllerImpl& controller = controller_impl(); 817 NavigationControllerImpl& controller = controller_impl();
817 TestNotificationTracker notifications; 818 TestNotificationTracker notifications;
818 RegisterForAllNavNotifications(&notifications, &controller); 819 RegisterForAllNavNotifications(&notifications, &controller);
819 820
820 // First make some history, starting with a privileged URL. 821 // First make some history, starting with a privileged URL.
821 const GURL kExistingURL1("http://privileged"); 822 const GURL kExistingURL1("http://privileged");
822 controller.LoadURL( 823 controller.LoadURL(
823 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 824 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
824 // Pretend it has bindings so we can tell if we incorrectly copy it. 825 // Pretend it has bindings so we can tell if we incorrectly copy it.
825 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); 826 contents()->CommitPendingNavigationWithBindings(2, false);
nasko 2014/12/11 00:51:45 As I'm reading through these changes, it seems lik
clamy 2014/12/15 17:01:39 Done.
826 main_test_rfh()->SendNavigate(0, kExistingURL1);
827 EXPECT_EQ(1U, navigation_entry_committed_counter_); 827 EXPECT_EQ(1U, navigation_entry_committed_counter_);
828 navigation_entry_committed_counter_ = 0; 828 navigation_entry_committed_counter_ = 0;
829 829
830 // Navigate cross-process to a second URL. 830 // Navigate cross-process to a second URL.
831 const GURL kExistingURL2("http://foo/eh"); 831 const GURL kExistingURL2("http://foo/eh");
832 controller.LoadURL( 832 controller.LoadURL(
833 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 833 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
834 main_test_rfh()->SendBeforeUnloadACK(true); 834 contents()->CommitPendingNavigation();
835 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame();
836 foo_rfh->SendNavigate(1, kExistingURL2);
837 EXPECT_EQ(1U, navigation_entry_committed_counter_); 835 EXPECT_EQ(1U, navigation_entry_committed_counter_);
838 navigation_entry_committed_counter_ = 0; 836 navigation_entry_committed_counter_ = 0;
839 837
840 // Now make a pending back/forward navigation to a privileged entry. 838 // Now make a pending back/forward navigation to a privileged entry.
841 // The zeroth entry should be pending. 839 // The zeroth entry should be pending.
842 controller.GoBack(); 840 controller.GoBack();
843 foo_rfh->SendBeforeUnloadACK(true); 841 contents()->ProceedNavigationWithRendererResponse(kExistingURL1);
844 EXPECT_EQ(0U, notifications.size()); 842 EXPECT_EQ(0U, notifications.size());
845 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 843 EXPECT_EQ(0, controller.GetPendingEntryIndex());
846 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 844 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
847 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry( 845 EXPECT_EQ(2, NavigationEntryImpl::FromNavigationEntry(
848 controller.GetPendingEntry())->bindings()); 846 controller.GetPendingEntry())->bindings());
849 847
850 // Before that commits, do a new navigation. 848 // Before that commits, do a new navigation.
851 const GURL kNewURL("http://foo/bee"); 849 const GURL kNewURL("http://foo/bee");
852 LoadCommittedDetails details; 850 LoadCommittedDetails details;
853 foo_rfh->SendNavigate(3, kNewURL); 851 contents()->SimulateRendererInitiatedNavigation(3, kNewURL);
854 852
855 // There should no longer be any pending entry, and the third navigation we 853 // There should no longer be any pending entry, and the third navigation we
856 // just made should be committed. 854 // just made should be committed.
857 EXPECT_EQ(1U, navigation_entry_committed_counter_); 855 EXPECT_EQ(1U, navigation_entry_committed_counter_);
858 navigation_entry_committed_counter_ = 0; 856 navigation_entry_committed_counter_ = 0;
859 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 857 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
860 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 858 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
861 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 859 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
862 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 860 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
863 controller.GetLastCommittedEntry())->bindings()); 861 controller.GetLastCommittedEntry())->bindings());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1076
1079 // Navigate to a first, unprivileged URL. 1077 // Navigate to a first, unprivileged URL.
1080 controller.LoadURL( 1078 controller.LoadURL(
1081 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1079 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1082 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, 1080 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings,
1083 NavigationEntryImpl::FromNavigationEntry( 1081 NavigationEntryImpl::FromNavigationEntry(
1084 controller.GetPendingEntry())->bindings()); 1082 controller.GetPendingEntry())->bindings());
1085 1083
1086 // Commit. 1084 // Commit.
1087 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1085 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1088 orig_rfh->SendNavigate(0, url1); 1086 contents()->CommitPendingNavigationNoLiveRenderer();
1089 EXPECT_EQ(controller.GetEntryCount(), 1); 1087 EXPECT_EQ(controller.GetEntryCount(), 1);
1090 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1088 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1091 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 1089 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
1092 controller.GetLastCommittedEntry())->bindings()); 1090 controller.GetLastCommittedEntry())->bindings());
1093 1091
1094 // Manually increase the number of active frames in the SiteInstance 1092 // Manually increase the number of active frames in the SiteInstance
1095 // that orig_rfh belongs to, to prevent it from being destroyed when 1093 // 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 1094 // it gets swapped out, so that we can reuse orig_rfh when the
1097 // controller goes back. 1095 // controller goes back.
1098 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 1096 orig_rfh->GetSiteInstance()->increment_active_frame_count();
1099 1097
1100 // Navigate to a second URL, simulate the beforeunload ack for the cross-site 1098 // 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 1099 // transition, and set bindings on the pending RenderViewHost to simulate a
1102 // privileged url. 1100 // privileged url.
1103 controller.LoadURL( 1101 controller.LoadURL(
1104 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1102 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1105 orig_rfh->SendBeforeUnloadACK(true); 1103 contents()->CommitPendingNavigationWithBindings(1, true);
1106 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame();
1107 new_rfh->GetRenderViewHost()->AllowBindings(1);
1108 new_rfh->SendNavigate(1, url2);
1109 1104
1110 // The second load should be committed, and bindings should be remembered. 1105 // The second load should be committed, and bindings should be remembered.
1111 EXPECT_EQ(controller.GetEntryCount(), 2); 1106 EXPECT_EQ(controller.GetEntryCount(), 2);
1112 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1107 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1113 EXPECT_TRUE(controller.CanGoBack()); 1108 EXPECT_TRUE(controller.CanGoBack());
1114 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry( 1109 EXPECT_EQ(1, NavigationEntryImpl::FromNavigationEntry(
1115 controller.GetLastCommittedEntry())->bindings()); 1110 controller.GetLastCommittedEntry())->bindings());
1116 1111
1117 // Going back, the first entry should still appear unprivileged. 1112 // Going back, the first entry should still appear unprivileged.
1118 controller.GoBack(); 1113 controller.GoBack();
1119 new_rfh->SendBeforeUnloadACK(true); 1114 contents()->CommitPendingNavigation();
1120 orig_rfh->SendNavigate(0, url1);
1121 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1115 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1122 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 1116 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
1123 controller.GetLastCommittedEntry())->bindings()); 1117 controller.GetLastCommittedEntry())->bindings());
1124 } 1118 }
1125 1119
1126 TEST_F(NavigationControllerTest, Reload) { 1120 TEST_F(NavigationControllerTest, Reload) {
1127 NavigationControllerImpl& controller = controller_impl(); 1121 NavigationControllerImpl& controller = controller_impl();
1128 TestNotificationTracker notifications; 1122 TestNotificationTracker notifications;
1129 RegisterForAllNavNotifications(&notifications, &controller); 1123 RegisterForAllNavNotifications(&notifications, &controller);
1130 1124
(...skipping 2740 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 scoped_ptr<TestWebContents> source_contents( 3865 scoped_ptr<TestWebContents> source_contents(
3872 static_cast<TestWebContents*>(CreateTestWebContents())); 3866 static_cast<TestWebContents*>(CreateTestWebContents()));
3873 NavigationControllerImpl& source_controller = 3867 NavigationControllerImpl& source_controller =
3874 source_contents->GetController(); 3868 source_contents->GetController();
3875 source_controller.Restore( 3869 source_controller.Restore(
3876 entries.size() - 1, 3870 entries.size() - 1,
3877 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 3871 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
3878 &entries); 3872 &entries);
3879 ASSERT_EQ(0u, entries.size()); 3873 ASSERT_EQ(0u, entries.size());
3880 source_controller.LoadIfNecessary(); 3874 source_controller.LoadIfNecessary();
3881 source_contents->CommitPendingNavigation(); 3875 source_contents->CommitPendingNavigationNoLiveRenderer();
3882 3876
3883 // Load a page, then copy state from |source_contents|. 3877 // Load a page, then copy state from |source_contents|.
3884 NavigateAndCommit(kInitialUrl); 3878 NavigateAndCommit(kInitialUrl);
3885 contents()->ExpectSetHistoryLengthAndPrune( 3879 contents()->ExpectSetHistoryLengthAndPrune(
3886 GetSiteInstanceFromEntry(controller_impl().GetEntryAtIndex(0)), 2, 3880 GetSiteInstanceFromEntry(controller_impl().GetEntryAtIndex(0)), 2,
3887 controller_impl().GetEntryAtIndex(0)->GetPageID()); 3881 controller_impl().GetEntryAtIndex(0)->GetPageID());
3888 controller_impl().CopyStateFromAndPrune(&source_controller, false); 3882 controller_impl().CopyStateFromAndPrune(&source_controller, false);
3889 ASSERT_EQ(3, controller_impl().GetEntryCount()); 3883 ASSERT_EQ(3, controller_impl().GetEntryCount());
3890 3884
3891 // Go back to the first entry one at a time and 3885 // Go back to the first entry one at a time and
(...skipping 18 matching lines...) Expand all
3910 NavigationControllerImpl& controller = controller_impl(); 3904 NavigationControllerImpl& controller = controller_impl();
3911 const GURL url1("http://foo/1"); 3905 const GURL url1("http://foo/1");
3912 const GURL url2("http://foo/2"); 3906 const GURL url2("http://foo/2");
3913 const GURL url3("http://foo/3"); 3907 const GURL url3("http://foo/3");
3914 3908
3915 NavigateAndCommit(url1); 3909 NavigateAndCommit(url1);
3916 NavigateAndCommit(url2); 3910 NavigateAndCommit(url2);
3917 NavigateAndCommit(url3); 3911 NavigateAndCommit(url3);
3918 controller.GoBack(); 3912 controller.GoBack();
3919 contents()->CommitPendingNavigation(); 3913 contents()->CommitPendingNavigation();
3914 process()->sink().ClearMessages();
3920 3915
3921 // Simulate the page calling history.back(). It should create a pending entry. 3916 // Simulate the page calling history.back(). It should create a pending entry.
3922 contents()->OnGoToEntryAtOffset(-1); 3917 contents()->OnGoToEntryAtOffset(-1);
3923 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 3918 EXPECT_EQ(0, controller.GetPendingEntryIndex());
3924 // The actual cross-navigation is suspended until the current RVH tells us 3919 // The actual cross-navigation is suspended until the current RVH tells us
3925 // it unloaded, simulate that. 3920 // it unloaded, simulate that.
3926 contents()->ProceedWithCrossSiteNavigation(); 3921 contents()->ProceedNavigationWithRendererResponse(url1);
3927 // Also make sure we told the page to navigate. 3922 // Also make sure we told the page to navigate.
3928 const IPC::Message* message = 3923 GURL nav_url;
3929 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 3924 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3930 ASSERT_TRUE(message != NULL); 3925 switches::kEnableBrowserSideNavigation)) {
3931 Tuple1<FrameMsg_Navigate_Params> nav_params; 3926 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
3932 FrameMsg_Navigate::Read(message, &nav_params); 3927 FrameMsg_RequestNavigation::ID);
3933 EXPECT_EQ(url1, nav_params.a.common_params.url); 3928 ASSERT_TRUE(message != NULL);
3929 Tuple2<CommonNavigationParams, RequestNavigationParams> nav_params;
3930 FrameMsg_RequestNavigation::Read(message, &nav_params);
3931 nav_url = nav_params.a.url;
3932 } else {
3933 const IPC::Message* message =
3934 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
3935 ASSERT_TRUE(message != NULL);
3936 Tuple1<FrameMsg_Navigate_Params> nav_params;
3937 FrameMsg_Navigate::Read(message, &nav_params);
3938 nav_url = nav_params.a.common_params.url;
3939 }
3940 EXPECT_EQ(url1, nav_url);
3934 process()->sink().ClearMessages(); 3941 process()->sink().ClearMessages();
3935 3942
3936 // Now test history.forward() 3943 // Now test history.forward()
3937 contents()->OnGoToEntryAtOffset(2); 3944 contents()->OnGoToEntryAtOffset(2);
3938 EXPECT_EQ(2, controller.GetPendingEntryIndex()); 3945 EXPECT_EQ(2, controller.GetPendingEntryIndex());
3939 // The actual cross-navigation is suspended until the current RVH tells us 3946 // The actual cross-navigation is suspended until the current RVH tells us
3940 // it unloaded, simulate that. 3947 // it unloaded, simulate that.
3941 contents()->ProceedWithCrossSiteNavigation(); 3948 contents()->ProceedNavigationWithRendererResponse(url3);
3942 message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 3949 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3943 ASSERT_TRUE(message != NULL); 3950 switches::kEnableBrowserSideNavigation)) {
3944 FrameMsg_Navigate::Read(message, &nav_params); 3951 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
3945 EXPECT_EQ(url3, nav_params.a.common_params.url); 3952 FrameMsg_RequestNavigation::ID);
3953 ASSERT_TRUE(message != NULL);
3954 Tuple2<CommonNavigationParams, RequestNavigationParams> nav_params;
3955 FrameMsg_RequestNavigation::Read(message, &nav_params);
3956 nav_url = nav_params.a.url;
3957 } else {
3958 const IPC::Message* message =
3959 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
3960 ASSERT_TRUE(message != NULL);
3961 Tuple1<FrameMsg_Navigate_Params> nav_params;
3962 FrameMsg_Navigate::Read(message, &nav_params);
3963 nav_url = nav_params.a.common_params.url;
3964 }
3965 EXPECT_EQ(url3, nav_url);
3946 process()->sink().ClearMessages(); 3966 process()->sink().ClearMessages();
3947 3967
3948 controller.DiscardNonCommittedEntries(); 3968 controller.DiscardNonCommittedEntries();
3949 3969
3950 // Make sure an extravagant history.go() doesn't break. 3970 // Make sure an extravagant history.go() doesn't break.
3951 contents()->OnGoToEntryAtOffset(120); // Out of bounds. 3971 contents()->OnGoToEntryAtOffset(120); // Out of bounds.
3952 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3972 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3953 message = process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); 3973 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3954 EXPECT_TRUE(message == NULL); 3974 switches::kEnableBrowserSideNavigation)) {
3975 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
3976 FrameMsg_RequestNavigation::ID);
3977 EXPECT_TRUE(message == NULL);
3978 } else {
3979 const IPC::Message* message =
3980 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID);
3981 EXPECT_TRUE(message == NULL);
3982 }
3955 } 3983 }
3956 3984
3957 // Test call to PruneAllButLastCommitted for the only entry. 3985 // Test call to PruneAllButLastCommitted for the only entry.
3958 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { 3986 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) {
3959 NavigationControllerImpl& controller = controller_impl(); 3987 NavigationControllerImpl& controller = controller_impl();
3960 const GURL url1("http://foo1"); 3988 const GURL url1("http://foo1");
3961 NavigateAndCommit(url1); 3989 NavigateAndCommit(url1);
3962 3990
3963 contents()->ExpectSetHistoryLengthAndPrune( 3991 contents()->ExpectSetHistoryLengthAndPrune(
3964 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, 3992 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0,
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
4337 4365
4338 // Verify that the pending entry correctly indicates that the session history 4366 // Verify that the pending entry correctly indicates that the session history
4339 // should be cleared. 4367 // should be cleared.
4340 NavigationEntryImpl* entry = 4368 NavigationEntryImpl* entry =
4341 NavigationEntryImpl::FromNavigationEntry( 4369 NavigationEntryImpl::FromNavigationEntry(
4342 controller.GetPendingEntry()); 4370 controller.GetPendingEntry());
4343 ASSERT_TRUE(entry); 4371 ASSERT_TRUE(entry);
4344 EXPECT_TRUE(entry->should_clear_history_list()); 4372 EXPECT_TRUE(entry->should_clear_history_list());
4345 4373
4346 // Assume that the RF correctly cleared its history and commit the navigation. 4374 // Assume that the RF correctly cleared its history and commit the navigation.
4347 contents()->GetPendingMainFrame()-> 4375 contents()->CommitPendingNavigationWithHistoryCleared(true, true);
4348 set_simulate_history_list_was_cleared(true);
4349 contents()->CommitPendingNavigation();
4350 4376
4351 // Verify that the NavigationController's session history was correctly 4377 // Verify that the NavigationController's session history was correctly
4352 // cleared. 4378 // cleared.
4353 EXPECT_EQ(1, controller.GetEntryCount()); 4379 EXPECT_EQ(1, controller.GetEntryCount());
4354 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4380 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4355 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4381 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4356 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4382 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4357 EXPECT_FALSE(controller.CanGoBack()); 4383 EXPECT_FALSE(controller.CanGoBack());
4358 EXPECT_FALSE(controller.CanGoForward()); 4384 EXPECT_FALSE(controller.CanGoForward());
4359 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4385 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
(...skipping 29 matching lines...) Expand all
4389 params.post_id = -1; 4415 params.post_id = -1;
4390 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4416 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4391 4417
4392 // Now reload. replaceState overrides the POST, so we should not show a 4418 // Now reload. replaceState overrides the POST, so we should not show a
4393 // repost warning dialog. 4419 // repost warning dialog.
4394 controller_impl().Reload(true); 4420 controller_impl().Reload(true);
4395 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4421 EXPECT_EQ(0, delegate->repost_form_warning_count());
4396 } 4422 }
4397 4423
4398 } // namespace content 4424 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/test_web_contents.h » ('j') | content/test/test_web_contents.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698