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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 903043002: Skip BeforeUnload on cross-site navigations when there are no handlers Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // Navigate to URL. First URL should use first RenderViewHost. 482 // Navigate to URL. First URL should use first RenderViewHost.
483 const GURL url("http://www.google.com"); 483 const GURL url("http://www.google.com");
484 controller().LoadURL( 484 controller().LoadURL(
485 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 485 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
486 orig_rfh->PrepareForCommit(url); 486 orig_rfh->PrepareForCommit(url);
487 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 487 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
488 488
489 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 489 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
490 // that orig_rfh doesn't get deleted when it gets swapped out. 490 // that orig_rfh doesn't get deleted when it gets swapped out.
491 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 491 orig_rfh->GetSiteInstance()->increment_active_frame_count();
492 orig_rfh->SendBeforeUnloadHandlersPresent(true);
492 493
493 EXPECT_FALSE(contents()->cross_navigation_pending()); 494 EXPECT_FALSE(contents()->cross_navigation_pending());
494 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 495 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
495 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 496 EXPECT_EQ(url, contents()->GetLastCommittedURL());
496 EXPECT_EQ(url, contents()->GetVisibleURL()); 497 EXPECT_EQ(url, contents()->GetVisibleURL());
497 498
498 // Navigate to new site 499 // Navigate to new site
499 const GURL url2("http://www.yahoo.com"); 500 const GURL url2("http://www.yahoo.com");
500 controller().LoadURL( 501 controller().LoadURL(
501 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 502 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
(...skipping 19 matching lines...) Expand all
521 522
522 // DidNavigate from the pending page 523 // DidNavigate from the pending page
523 contents()->TestDidNavigate( 524 contents()->TestDidNavigate(
524 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 525 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
525 SiteInstance* instance2 = contents()->GetSiteInstance(); 526 SiteInstance* instance2 = contents()->GetSiteInstance();
526 527
527 // Keep the number of active frames in pending_rfh's SiteInstance 528 // Keep the number of active frames in pending_rfh's SiteInstance
528 // non-zero so that orig_rfh doesn't get deleted when it gets 529 // non-zero so that orig_rfh doesn't get deleted when it gets
529 // swapped out. 530 // swapped out.
530 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 531 pending_rfh->GetSiteInstance()->increment_active_frame_count();
532 pending_rfh->SendBeforeUnloadHandlersPresent(true);
531 533
532 EXPECT_FALSE(contents()->cross_navigation_pending()); 534 EXPECT_FALSE(contents()->cross_navigation_pending());
533 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 535 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
534 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 536 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
535 EXPECT_EQ(url2, contents()->GetVisibleURL()); 537 EXPECT_EQ(url2, contents()->GetVisibleURL());
536 EXPECT_NE(instance1, instance2); 538 EXPECT_NE(instance1, instance2);
537 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 539 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
538 // We keep the original RFH around, swapped out. 540 // We keep the original RFH around, swapped out.
539 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 541 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
540 orig_rfh)); 542 orig_rfh));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 EXPECT_FALSE(contents()->cross_navigation_pending()); 726 EXPECT_FALSE(contents()->cross_navigation_pending());
725 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 727 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
726 EXPECT_EQ(url, contents()->GetVisibleURL()); 728 EXPECT_EQ(url, contents()->GetVisibleURL());
727 EXPECT_FALSE(contents()->GetPendingMainFrame()); 729 EXPECT_FALSE(contents()->GetPendingMainFrame());
728 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 730 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
729 731
730 // Keep the number of active frames in orig_rfh's SiteInstance 732 // Keep the number of active frames in orig_rfh's SiteInstance
731 // non-zero so that orig_rfh doesn't get deleted when it gets 733 // non-zero so that orig_rfh doesn't get deleted when it gets
732 // swapped out. 734 // swapped out.
733 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 735 orig_rfh->GetSiteInstance()->increment_active_frame_count();
736 orig_rfh->SendBeforeUnloadHandlersPresent(true);
734 737
735 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 738 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
736 EXPECT_TRUE( 739 EXPECT_TRUE(
737 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 740 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
738 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 741 EXPECT_EQ(url, contents()->GetLastCommittedURL());
739 742
740 // Navigate to another new site (should create a new site instance). 743 // Navigate to another new site (should create a new site instance).
741 const GURL url2("http://www.yahoo.com"); 744 const GURL url2("http://www.yahoo.com");
742 controller().LoadURL( 745 controller().LoadURL(
743 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 746 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 951 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
949 EXPECT_FALSE(contents()->cross_navigation_pending()); 952 EXPECT_FALSE(contents()->cross_navigation_pending());
950 contents()->GetMainFrame()->PrepareForCommit(url3); 953 contents()->GetMainFrame()->PrepareForCommit(url3);
951 contents()->TestDidNavigate( 954 contents()->TestDidNavigate(
952 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); 955 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED);
953 SiteInstance* instance4 = contents()->GetSiteInstance(); 956 SiteInstance* instance4 = contents()->GetSiteInstance();
954 EXPECT_EQ(instance1, instance4); 957 EXPECT_EQ(instance1, instance4);
955 } 958 }
956 959
957 // Test that the onbeforeunload and onunload handlers run when navigating 960 // Test that the onbeforeunload and onunload handlers run when navigating
958 // across site boundaries. 961 // across site boundaries if needed.
959 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 962 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
960 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 963 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
961 SiteInstance* instance1 = contents()->GetSiteInstance(); 964 SiteInstance* instance1 = contents()->GetSiteInstance();
962 965
963 // Navigate to URL. First URL should use first RenderViewHost. 966 // Navigate to URL. First URL should use first RenderViewHost.
964 const GURL url("http://www.google.com"); 967 const GURL url("http://www.google.com");
965 controller().LoadURL( 968 controller().LoadURL(
966 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 969 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
967 contents()->GetMainFrame()->PrepareForCommit(url); 970 contents()->GetMainFrame()->PrepareForCommit(url);
968 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 971 contents()->TestDidNavigate(rfh1, 1, url, ui::PAGE_TRANSITION_TYPED);
969 EXPECT_FALSE(contents()->cross_navigation_pending()); 972 EXPECT_FALSE(contents()->cross_navigation_pending());
970 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 973 EXPECT_EQ(rfh1, contents()->GetMainFrame());
974 rfh1->SendBeforeUnloadHandlersPresent(true);
971 975
972 // Navigate to new site, but simulate an onbeforeunload denial. 976 // Navigate to new site, but simulate an onbeforeunload denial.
973 const GURL url2("http://www.yahoo.com"); 977 const GURL url2("http://www.yahoo.com");
974 controller().LoadURL( 978 controller().LoadURL(
975 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 979 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
976 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 980 EXPECT_TRUE(rfh1->IsWaitingForBeforeUnloadACK());
977 base::TimeTicks now = base::TimeTicks::Now(); 981 base::TimeTicks now = base::TimeTicks::Now();
978 orig_rfh->OnMessageReceived( 982 rfh1->OnMessageReceived(
979 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 983 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
980 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 984 EXPECT_FALSE(rfh1->IsWaitingForBeforeUnloadACK());
981 EXPECT_FALSE(contents()->cross_navigation_pending()); 985 EXPECT_FALSE(contents()->cross_navigation_pending());
982 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 986 EXPECT_EQ(rfh1, contents()->GetMainFrame());
983 987
984 // Navigate again, but simulate an onbeforeunload approval. 988 // Navigate again, but simulate an onbeforeunload approval.
985 controller().LoadURL( 989 controller().LoadURL(
986 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 990 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
987 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 991 EXPECT_TRUE(rfh1->IsWaitingForBeforeUnloadACK());
988 now = base::TimeTicks::Now(); 992 now = base::TimeTicks::Now();
989 orig_rfh->PrepareForCommit(url2); 993 rfh1->PrepareForCommit(url2);
990 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 994 EXPECT_FALSE(rfh1->IsWaitingForBeforeUnloadACK());
991 EXPECT_TRUE(contents()->cross_navigation_pending()); 995 EXPECT_TRUE(contents()->cross_navigation_pending());
992 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 996 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
993
994 // We won't hear DidNavigate until the onunload handler has finished running.
995 997
996 // DidNavigate from the pending page. 998 // DidNavigate from the pending page.
997 contents()->TestDidNavigate( 999 contents()->TestDidNavigate(
998 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1000 rfh2, 1, url2, ui::PAGE_TRANSITION_TYPED);
999 SiteInstance* instance2 = contents()->GetSiteInstance(); 1001 SiteInstance* instance2 = contents()->GetSiteInstance();
1000 EXPECT_FALSE(contents()->cross_navigation_pending()); 1002 EXPECT_FALSE(contents()->cross_navigation_pending());
1001 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1003 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1002 EXPECT_NE(instance1, instance2); 1004 EXPECT_NE(instance1, instance2);
1003 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1005 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1006
carlosk 2015/02/17 12:52:09 Suggestion: split it here into a new test.
clamy 2015/02/18 13:27:23 I think it makes sense for it to be in this test,
1007 // Now navigate to a new site. There is no beforeUnload handlers, so we should
Charlie Reis 2015/02/17 23:04:31 nit: There are
clamy 2015/02/18 13:27:23 Done.
1008 // not be waiting for a BeforeUnloadACK.
1009 const GURL url3("http://www.chromium.org");
1010 rfh2->GetSiteInstance()->increment_active_frame_count();
1011 controller().LoadURL(
1012 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1013 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK());
1014 rfh2->PrepareForCommit(url3);
1015 EXPECT_TRUE(contents()->cross_navigation_pending());
1016 TestRenderFrameHost* rfh3 = contents()->GetPendingMainFrame();
1017
1018 // DidNavigate from the pending page.
1019 contents()->TestDidNavigate(
1020 rfh3, 1, url3, ui::PAGE_TRANSITION_TYPED);
1021 SiteInstance* instance3 = contents()->GetSiteInstance();
1022 EXPECT_FALSE(contents()->cross_navigation_pending());
1023 EXPECT_EQ(rfh3, contents()->GetMainFrame());
1024 EXPECT_NE(instance2, instance3);
1025 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1004 } 1026 }
1005 1027
1006 // Test that during a slow cross-site navigation, the original renderer can 1028 // Test that during a slow cross-site navigation, the original renderer can
1007 // navigate to a different URL and have it displayed, canceling the slow 1029 // navigate to a different URL and have it displayed, canceling the slow
1008 // navigation. 1030 // navigation.
1009 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { 1031 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) {
1010 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1032 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1011 SiteInstance* instance1 = contents()->GetSiteInstance(); 1033 SiteInstance* instance1 = contents()->GetSiteInstance();
1012 1034
1013 // Navigate to URL. First URL should use first RenderFrameHost. 1035 // Navigate to URL. First URL should use first RenderFrameHost.
1014 const GURL url("http://www.google.com"); 1036 const GURL url("http://www.google.com");
1015 controller().LoadURL( 1037 controller().LoadURL(
1016 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1038 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1017 contents()->GetMainFrame()->PrepareForCommit(url); 1039 contents()->GetMainFrame()->PrepareForCommit(url);
1018 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1040 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1019 EXPECT_FALSE(contents()->cross_navigation_pending()); 1041 EXPECT_FALSE(contents()->cross_navigation_pending());
1020 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1042 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1043 orig_rfh->SendBeforeUnloadHandlersPresent(true);
1021 1044
1022 // Navigate to new site, simulating an onbeforeunload approval. 1045 // Navigate to new site, simulating an onbeforeunload approval.
1023 const GURL url2("http://www.yahoo.com"); 1046 const GURL url2("http://www.yahoo.com");
1024 controller().LoadURL( 1047 controller().LoadURL(
1025 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1048 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1026 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1049 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1027 orig_rfh->PrepareForCommit(url2); 1050 orig_rfh->PrepareForCommit(url2);
1028 EXPECT_TRUE(contents()->cross_navigation_pending()); 1051 EXPECT_TRUE(contents()->cross_navigation_pending());
1029 1052
1030 // Suppose the original renderer navigates before the new one is ready. 1053 // Suppose the original renderer navigates before the new one is ready.
(...skipping 19 matching lines...) Expand all
1050 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1073 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1051 SiteInstance* instance1 = contents()->GetSiteInstance(); 1074 SiteInstance* instance1 = contents()->GetSiteInstance();
1052 1075
1053 EXPECT_FALSE(contents()->cross_navigation_pending()); 1076 EXPECT_FALSE(contents()->cross_navigation_pending());
1054 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1077 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
1055 EXPECT_EQ(url1, entry1->GetURL()); 1078 EXPECT_EQ(url1, entry1->GetURL());
1056 EXPECT_EQ(instance1, 1079 EXPECT_EQ(instance1,
1057 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1080 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1058 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & 1081 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() &
1059 BINDINGS_POLICY_WEB_UI); 1082 BINDINGS_POLICY_WEB_UI);
1083 ntp_rfh->SendBeforeUnloadHandlersPresent(true);
1060 1084
1061 // Navigate to new site. 1085 // Navigate to new site.
1062 const GURL url2("http://www.google.com"); 1086 const GURL url2("http://www.google.com");
1063 controller().LoadURL( 1087 controller().LoadURL(
1064 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1088 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1065 EXPECT_TRUE(contents()->cross_navigation_pending()); 1089 EXPECT_TRUE(contents()->cross_navigation_pending());
1066 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1090 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1067 1091
1068 // Simulate beforeunload approval. 1092 // Simulate beforeunload approval.
1069 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK()); 1093 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK());
(...skipping 27 matching lines...) Expand all
1097 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1121 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1098 SiteInstance* instance3 = contents()->GetSiteInstance(); 1122 SiteInstance* instance3 = contents()->GetSiteInstance();
1099 1123
1100 EXPECT_FALSE(contents()->cross_navigation_pending()); 1124 EXPECT_FALSE(contents()->cross_navigation_pending());
1101 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1125 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1102 EXPECT_EQ(instance2, instance3); 1126 EXPECT_EQ(instance2, instance3);
1103 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1127 EXPECT_FALSE(contents()->GetPendingMainFrame());
1104 EXPECT_EQ(url3, entry3->GetURL()); 1128 EXPECT_EQ(url3, entry3->GetURL());
1105 EXPECT_EQ(instance3, 1129 EXPECT_EQ(instance3,
1106 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1130 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1131 google_rfh->SendBeforeUnloadHandlersPresent(true);
1107 1132
1108 // Go back within the site. 1133 // Go back within the site.
1109 controller().GoBack(); 1134 controller().GoBack();
1110 EXPECT_FALSE(contents()->cross_navigation_pending()); 1135 EXPECT_FALSE(contents()->cross_navigation_pending());
1111 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1136 EXPECT_EQ(entry2, controller().GetPendingEntry());
1112 1137
1113 // Before that commits, go back again. 1138 // Before that commits, go back again.
1114 controller().GoBack(); 1139 controller().GoBack();
1115 EXPECT_TRUE(contents()->cross_navigation_pending()); 1140 EXPECT_TRUE(contents()->cross_navigation_pending());
1116 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1141 EXPECT_TRUE(contents()->GetPendingMainFrame());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1173 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1149 1174
1150 // Navigate to URL. First URL should use the original RenderFrameHost. 1175 // Navigate to URL. First URL should use the original RenderFrameHost.
1151 const GURL url("http://www.google.com"); 1176 const GURL url("http://www.google.com");
1152 controller().LoadURL( 1177 controller().LoadURL(
1153 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1178 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1154 contents()->GetMainFrame()->PrepareForCommit(url); 1179 contents()->GetMainFrame()->PrepareForCommit(url);
1155 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1180 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1156 EXPECT_FALSE(contents()->cross_navigation_pending()); 1181 EXPECT_FALSE(contents()->cross_navigation_pending());
1157 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1182 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1183 orig_rfh->SendBeforeUnloadHandlersPresent(true);
1158 1184
1159 // Start navigating to new site. 1185 // Start navigating to new site.
1160 const GURL url2("http://www.yahoo.com"); 1186 const GURL url2("http://www.yahoo.com");
1161 controller().LoadURL( 1187 controller().LoadURL(
1162 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1188 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1163 1189
1164 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1190 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1165 // waiting for a before unload response. 1191 // waiting for a before unload response.
1166 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1192 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1167 child_rfh->SendNavigateWithTransition( 1193 child_rfh->SendNavigateWithTransition(
(...skipping 10 matching lines...) Expand all
1178 // Test that a cross-site navigation is not preempted if the previous 1204 // Test that a cross-site navigation is not preempted if the previous
1179 // renderer sends a FrameNavigate message just before being told to stop. 1205 // renderer sends a FrameNavigate message just before being told to stop.
1180 // We should only preempt the cross-site navigation if the previous renderer 1206 // We should only preempt the cross-site navigation if the previous renderer
1181 // has started a new navigation. See http://crbug.com/79176. 1207 // has started a new navigation. See http://crbug.com/79176.
1182 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1208 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1183 // Navigate to NTP URL. 1209 // Navigate to NTP URL.
1184 const GURL url("chrome://blah"); 1210 const GURL url("chrome://blah");
1185 controller().LoadURL( 1211 controller().LoadURL(
1186 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1212 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1187 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1213 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1214 orig_rfh->SendBeforeUnloadHandlersPresent(true);
1188 EXPECT_FALSE(contents()->cross_navigation_pending()); 1215 EXPECT_FALSE(contents()->cross_navigation_pending());
1189 1216
1190 // Navigate to new site, with the beforeunload request in flight. 1217 // Navigate to new site, with the beforeunload request in flight.
1191 const GURL url2("http://www.yahoo.com"); 1218 const GURL url2("http://www.yahoo.com");
1192 controller().LoadURL( 1219 controller().LoadURL(
1193 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1220 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1194 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1221 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1195 EXPECT_TRUE(contents()->cross_navigation_pending()); 1222 EXPECT_TRUE(contents()->cross_navigation_pending());
1196 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1223 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1197 1224
(...skipping 18 matching lines...) Expand all
1216 SiteInstance* instance1 = contents()->GetSiteInstance(); 1243 SiteInstance* instance1 = contents()->GetSiteInstance();
1217 1244
1218 // Navigate to URL. First URL should use original RenderFrameHost. 1245 // Navigate to URL. First URL should use original RenderFrameHost.
1219 const GURL url("http://www.google.com"); 1246 const GURL url("http://www.google.com");
1220 controller().LoadURL( 1247 controller().LoadURL(
1221 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1248 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1222 contents()->GetMainFrame()->PrepareForCommit(url); 1249 contents()->GetMainFrame()->PrepareForCommit(url);
1223 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1250 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1224 EXPECT_FALSE(contents()->cross_navigation_pending()); 1251 EXPECT_FALSE(contents()->cross_navigation_pending());
1225 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1252 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1253 orig_rfh->SendBeforeUnloadHandlersPresent(true);
1226 1254
1227 // Navigate to new site, simulating an onbeforeunload approval. 1255 // Navigate to new site, simulating an onbeforeunload approval.
1228 const GURL url2("http://www.yahoo.com"); 1256 const GURL url2("http://www.yahoo.com");
1229 controller().LoadURL( 1257 controller().LoadURL(
1230 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1258 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1231 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1259 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1232 contents()->GetMainFrame()->PrepareForCommit(url2); 1260 contents()->GetMainFrame()->PrepareForCommit(url2);
1233 EXPECT_TRUE(contents()->cross_navigation_pending()); 1261 EXPECT_TRUE(contents()->cross_navigation_pending());
1234 1262
1235 // Simulate swap out message when the response arrives. 1263 // Simulate swap out message when the response arrives.
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 frame->SendBeforeUnloadHandlersPresent(false); 3066 frame->SendBeforeUnloadHandlersPresent(false);
3039 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3067 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3040 frame->SendBeforeUnloadHandlersPresent(true); 3068 frame->SendBeforeUnloadHandlersPresent(true);
3041 frame->SendUnloadHandlersPresent(false); 3069 frame->SendUnloadHandlersPresent(false);
3042 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3070 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3043 frame->SendBeforeUnloadHandlersPresent(false); 3071 frame->SendBeforeUnloadHandlersPresent(false);
3044 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3072 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3045 } 3073 }
3046 3074
3047 } // namespace content 3075 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698