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

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

Issue 2783723002: Keep track in the browser of which frames have onunload and onbeforeunload handlers. (Closed)
Patch Set: fix content_browsertests with plznavigate and also remove now unnecessary unloadcontroller change Created 3 years, 8 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 orig_rfh->PrepareForCommit(); 543 orig_rfh->PrepareForCommit();
544 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 544 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
545 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 545 EXPECT_EQ(url, contents()->GetLastCommittedURL());
546 EXPECT_EQ(url2, contents()->GetVisibleURL()); 546 EXPECT_EQ(url2, contents()->GetVisibleURL());
547 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 547 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
548 EXPECT_TRUE(pending_rfh->GetLastCommittedURL().is_empty()); 548 EXPECT_TRUE(pending_rfh->GetLastCommittedURL().is_empty());
549 int pending_rvh_delete_count = 0; 549 int pending_rvh_delete_count = 0;
550 pending_rfh->GetRenderViewHost()->set_delete_counter( 550 pending_rfh->GetRenderViewHost()->set_delete_counter(
551 &pending_rvh_delete_count); 551 &pending_rvh_delete_count);
552 552
553 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
554 if (!IsBrowserSideNavigationEnabled()) {
555 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
556 orig_rfh->SendBeforeUnloadACK(true);
557 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
558 }
559
560 // DidNavigate from the pending page 553 // DidNavigate from the pending page
561 contents()->TestDidNavigateWithSequenceNumber( 554 contents()->TestDidNavigateWithSequenceNumber(
562 pending_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, 555 pending_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
563 false, 1, 1); 556 false, 1, 1);
564 SiteInstance* instance2 = contents()->GetSiteInstance(); 557 SiteInstance* instance2 = contents()->GetSiteInstance();
565 558
566 // Keep the number of active frames in pending_rfh's SiteInstance 559 // Keep the number of active frames in pending_rfh's SiteInstance
567 // non-zero so that orig_rfh doesn't get deleted when it gets 560 // non-zero so that orig_rfh doesn't get deleted when it gets
568 // swapped out. 561 // swapped out.
569 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount(); 562 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount();
(...skipping 12 matching lines...) Expand all
582 // Going back should switch SiteInstances again. The first SiteInstance is 575 // Going back should switch SiteInstances again. The first SiteInstance is
583 // stored in the NavigationEntry, so it should be the same as at the start. 576 // stored in the NavigationEntry, so it should be the same as at the start.
584 // We should use the same RFH as before, swapping it back in. 577 // We should use the same RFH as before, swapping it back in.
585 controller().GoBack(); 578 controller().GoBack();
586 entry_id = controller().GetPendingEntry()->GetUniqueID(); 579 entry_id = controller().GetPendingEntry()->GetUniqueID();
587 if (IsBrowserSideNavigationEnabled()) 580 if (IsBrowserSideNavigationEnabled())
588 main_test_rfh()->PrepareForCommit(); 581 main_test_rfh()->PrepareForCommit();
589 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 582 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
590 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 583 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
591 584
592 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
593 if (!IsBrowserSideNavigationEnabled()) {
594 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
595 pending_rfh->SendBeforeUnloadACK(true);
596 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
597 }
598
599 // DidNavigate from the back action 585 // DidNavigate from the back action
600 contents()->TestDidNavigateWithSequenceNumber( 586 contents()->TestDidNavigateWithSequenceNumber(
601 goback_rfh, entry_id, false, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, 587 goback_rfh, entry_id, false, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
602 false, 2, 0); 588 false, 2, 0);
603 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 589 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
604 EXPECT_EQ(goback_rfh, main_test_rfh()); 590 EXPECT_EQ(goback_rfh, main_test_rfh());
605 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 591 EXPECT_EQ(instance1, contents()->GetSiteInstance());
606 // There should be a proxy for the pending RFH SiteInstance. 592 // There should be a proxy for the pending RFH SiteInstance.
607 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 593 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
608 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance())); 594 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance()));
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 if (IsBrowserSideNavigationEnabled()) 782 if (IsBrowserSideNavigationEnabled())
797 orig_rfh->PrepareForCommit(); 783 orig_rfh->PrepareForCommit();
798 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 784 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
799 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 785 EXPECT_EQ(url, contents()->GetLastCommittedURL());
800 EXPECT_EQ(url2, contents()->GetVisibleURL()); 786 EXPECT_EQ(url2, contents()->GetVisibleURL());
801 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 787 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
802 int pending_rvh_delete_count = 0; 788 int pending_rvh_delete_count = 0;
803 pending_rfh->GetRenderViewHost()->set_delete_counter( 789 pending_rfh->GetRenderViewHost()->set_delete_counter(
804 &pending_rvh_delete_count); 790 &pending_rvh_delete_count);
805 791
806 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
807 if (!IsBrowserSideNavigationEnabled()) {
808 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
809 orig_rfh->SendBeforeUnloadACK(true);
810 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
811 }
812
813 // DidNavigate from the pending page. 792 // DidNavigate from the pending page.
814 contents()->TestDidNavigate(pending_rfh, entry_id, true, url2, 793 contents()->TestDidNavigate(pending_rfh, entry_id, true, url2,
815 ui::PAGE_TRANSITION_TYPED); 794 ui::PAGE_TRANSITION_TYPED);
816 SiteInstance* new_instance = contents()->GetSiteInstance(); 795 SiteInstance* new_instance = contents()->GetSiteInstance();
817 796
818 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 797 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
819 EXPECT_EQ(pending_rfh, main_test_rfh()); 798 EXPECT_EQ(pending_rfh, main_test_rfh());
820 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 799 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
821 EXPECT_EQ(url2, contents()->GetVisibleURL()); 800 EXPECT_EQ(url2, contents()->GetVisibleURL());
822 EXPECT_NE(new_instance, orig_instance); 801 EXPECT_NE(new_instance, orig_instance);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 // across site boundaries. 1024 // across site boundaries.
1046 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 1025 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
1047 TestRenderFrameHost* orig_rfh = main_test_rfh(); 1026 TestRenderFrameHost* orig_rfh = main_test_rfh();
1048 SiteInstance* instance1 = contents()->GetSiteInstance(); 1027 SiteInstance* instance1 = contents()->GetSiteInstance();
1049 1028
1050 // Navigate to URL. First URL should use first RenderViewHost. 1029 // Navigate to URL. First URL should use first RenderViewHost.
1051 const GURL url("http://www.google.com"); 1030 const GURL url("http://www.google.com");
1052 controller().LoadURL( 1031 controller().LoadURL(
1053 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1032 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1054 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 1033 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1034 main_test_rfh()->set_has_beforeunload_handlers();
1055 main_test_rfh()->PrepareForCommit(); 1035 main_test_rfh()->PrepareForCommit();
1056 contents()->TestDidNavigate(orig_rfh, entry_id, true, url, 1036 contents()->TestDidNavigate(orig_rfh, entry_id, true, url,
1057 ui::PAGE_TRANSITION_TYPED); 1037 ui::PAGE_TRANSITION_TYPED);
1058 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1038 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1059 EXPECT_EQ(orig_rfh, main_test_rfh()); 1039 EXPECT_EQ(orig_rfh, main_test_rfh());
1060 1040
1061 // Navigate to new site, but simulate an onbeforeunload denial. 1041 // Navigate to new site, but simulate an onbeforeunload denial.
1062 const GURL url2("http://www.yahoo.com"); 1042 const GURL url2("http://www.yahoo.com");
1063 controller().LoadURL( 1043 controller().LoadURL(
1064 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1044 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 main_test_rfh()->PrepareForCommit(); 1088 main_test_rfh()->PrepareForCommit();
1109 contents()->TestDidNavigate(orig_rfh, entry_id, true, url, 1089 contents()->TestDidNavigate(orig_rfh, entry_id, true, url,
1110 ui::PAGE_TRANSITION_TYPED); 1090 ui::PAGE_TRANSITION_TYPED);
1111 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1091 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1112 EXPECT_EQ(orig_rfh, main_test_rfh()); 1092 EXPECT_EQ(orig_rfh, main_test_rfh());
1113 1093
1114 // Navigate to new site, simulating an onbeforeunload approval. 1094 // Navigate to new site, simulating an onbeforeunload approval.
1115 const GURL url2("http://www.yahoo.com"); 1095 const GURL url2("http://www.yahoo.com");
1116 controller().LoadURL( 1096 controller().LoadURL(
1117 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1097 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1118 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
1119 orig_rfh->PrepareForCommit();
1120 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1098 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1121 1099
1122 // Suppose the original renderer navigates before the new one is ready. 1100 // Suppose the original renderer navigates before the new one is ready.
1123 orig_rfh->SendNavigate(0, true, GURL("http://www.google.com/foo")); 1101 orig_rfh->SendNavigate(0, true, GURL("http://www.google.com/foo"));
1124 1102
1125 // Verify that the pending navigation is cancelled. 1103 // Verify that the pending navigation is cancelled.
1126 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1104 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1127 SiteInstance* instance2 = contents()->GetSiteInstance(); 1105 SiteInstance* instance2 = contents()->GetSiteInstance();
1128 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1106 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1129 EXPECT_EQ(orig_rfh, main_test_rfh()); 1107 EXPECT_EQ(orig_rfh, main_test_rfh());
(...skipping 28 matching lines...) Expand all
1158 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1136 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1159 1137
1160 // Navigate to new site. 1138 // Navigate to new site.
1161 const GURL url2("http://www.google.com"); 1139 const GURL url2("http://www.google.com");
1162 controller().LoadURL( 1140 controller().LoadURL(
1163 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1141 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1164 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1142 entry_id = controller().GetPendingEntry()->GetUniqueID();
1165 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1143 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1166 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1144 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1167 1145
1168 // Simulate beforeunload approval.
1169 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack());
1170 webui_rfh->PrepareForCommit();
1171
1172 // DidNavigate from the pending page. 1146 // DidNavigate from the pending page.
1173 contents()->TestDidNavigateWithSequenceNumber( 1147 contents()->TestDidNavigateWithSequenceNumber(
1174 google_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, 1148 google_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
1175 false, 1, 1); 1149 false, 1, 1);
1176 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1150 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1177 SiteInstance* instance2 = contents()->GetSiteInstance(); 1151 SiteInstance* instance2 = contents()->GetSiteInstance();
1178 1152
1179 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1153 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1180 EXPECT_EQ(google_rfh, main_test_rfh()); 1154 EXPECT_EQ(google_rfh, main_test_rfh());
1181 EXPECT_NE(instance1, instance2); 1155 EXPECT_NE(instance1, instance2);
(...skipping 29 matching lines...) Expand all
1211 NavigationEntry* goback_entry = controller().GetPendingEntry(); 1185 NavigationEntry* goback_entry = controller().GetPendingEntry();
1212 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1186 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1213 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1187 EXPECT_EQ(entry2, controller().GetPendingEntry());
1214 1188
1215 // Before that commits, go back again. 1189 // Before that commits, go back again.
1216 controller().GoBack(); 1190 controller().GoBack();
1217 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1191 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1218 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1192 EXPECT_TRUE(contents()->GetPendingMainFrame());
1219 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1193 EXPECT_EQ(entry1, controller().GetPendingEntry());
1220 1194
1221 // Simulate beforeunload approval.
1222 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack());
1223 base::TimeTicks now = base::TimeTicks::Now();
1224 google_rfh->PrepareForCommit();
1225 google_rfh->OnMessageReceived(
1226 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1227
1228 // DidNavigate from the first back. This aborts the second back's pending RFH. 1195 // DidNavigate from the first back. This aborts the second back's pending RFH.
1229 contents()->TestDidNavigateWithSequenceNumber( 1196 contents()->TestDidNavigateWithSequenceNumber(
1230 google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(), 1197 google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(),
1231 ui::PAGE_TRANSITION_TYPED, false, 1, 1); 1198 ui::PAGE_TRANSITION_TYPED, false, 1, 1);
1232 1199
1233 // We should commit this page and forget about the second back. 1200 // We should commit this page and forget about the second back.
1234 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1201 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1235 EXPECT_FALSE(controller().GetPendingEntry()); 1202 EXPECT_FALSE(controller().GetPendingEntry());
1236 EXPECT_EQ(google_rfh, main_test_rfh()); 1203 EXPECT_EQ(google_rfh, main_test_rfh());
1237 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); 1204 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1237 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1271 1238
1272 // Navigate to new site. 1239 // Navigate to new site.
1273 const GURL url2("http://www.google.com"); 1240 const GURL url2("http://www.google.com");
1274 controller().LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, 1241 controller().LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
1275 std::string()); 1242 std::string());
1276 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1243 entry_id = controller().GetPendingEntry()->GetUniqueID();
1277 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1244 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1278 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1245 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1279 1246
1280 // Simulate beforeunload approval.
1281 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack());
1282 webui_rfh->PrepareForCommit();
1283
1284 // DidNavigate from the pending page. 1247 // DidNavigate from the pending page.
1285 contents()->TestDidNavigate(google_rfh, entry_id, true, url2, 1248 contents()->TestDidNavigate(google_rfh, entry_id, true, url2,
1286 ui::PAGE_TRANSITION_TYPED); 1249 ui::PAGE_TRANSITION_TYPED);
1287 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1250 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1288 SiteInstance* instance2 = contents()->GetSiteInstance(); 1251 SiteInstance* instance2 = contents()->GetSiteInstance();
1289 1252
1290 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1253 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1291 EXPECT_EQ(google_rfh, main_test_rfh()); 1254 EXPECT_EQ(google_rfh, main_test_rfh());
1292 EXPECT_NE(instance1, instance2); 1255 EXPECT_NE(instance1, instance2);
1293 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1256 EXPECT_FALSE(contents()->GetPendingMainFrame());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 const GURL url2("http://www.yahoo.com"); 1324 const GURL url2("http://www.yahoo.com");
1362 controller().LoadURL( 1325 controller().LoadURL(
1363 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1326 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1364 1327
1365 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1328 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1366 // waiting for a before unload response. 1329 // waiting for a before unload response.
1367 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1330 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1368 child_rfh->SendNavigateWithTransition(0, false, 1331 child_rfh->SendNavigateWithTransition(0, false,
1369 GURL("http://google.com/frame"), 1332 GURL("http://google.com/frame"),
1370 ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1333 ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1371 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
1372 1334
1373 // Now simulate the onbeforeunload approval and verify the navigation is 1335 // Verify the navigation is not canceled.
1374 // not canceled.
1375 orig_rfh->PrepareForCommit();
1376 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1377 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1336 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1378 } 1337 }
1379 1338
1380 namespace { 1339 namespace {
1381 void SetAsNonUserGesture(FrameHostMsg_DidCommitProvisionalLoad_Params* params) { 1340 void SetAsNonUserGesture(FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
1382 params->gesture = NavigationGestureAuto; 1341 params->gesture = NavigationGestureAuto;
1383 } 1342 }
1384 } 1343 }
1385 1344
1386 // Test that a cross-site navigation is not preempted if the previous 1345 // Test that a cross-site navigation is not preempted if the previous
1387 // renderer sends a FrameNavigate message just before being told to stop. 1346 // renderer sends a FrameNavigate message just before being told to stop.
1388 // We should only preempt the cross-site navigation if the previous renderer 1347 // We should only preempt the cross-site navigation if the previous renderer
1389 // has started a new navigation. See http://crbug.com/79176. 1348 // has started a new navigation. See http://crbug.com/79176.
1390 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1349 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1391 // Navigate to WebUI URL. 1350 // Navigate to WebUI URL.
1392 const GURL url("chrome://gpu"); 1351 const GURL url("chrome://gpu");
1393 controller().LoadURL( 1352 controller().LoadURL(
1394 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1353 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1395 int entry1_id = controller().GetPendingEntry()->GetUniqueID(); 1354 int entry1_id = controller().GetPendingEntry()->GetUniqueID();
1396 TestRenderFrameHost* orig_rfh = main_test_rfh(); 1355 TestRenderFrameHost* orig_rfh = main_test_rfh();
1356 orig_rfh->set_has_beforeunload_handlers();
1397 orig_rfh->PrepareForCommit(); 1357 orig_rfh->PrepareForCommit();
1398 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1358 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1399 1359
1400 // Navigate to new site, with the beforeunload request in flight. 1360 // Navigate to new site, with the beforeunload request in flight.
1401 const GURL url2("http://www.yahoo.com"); 1361 const GURL url2("http://www.yahoo.com");
1402 controller().LoadURL( 1362 controller().LoadURL(
1403 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1363 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1404 int entry2_id = controller().GetPendingEntry()->GetUniqueID(); 1364 int entry2_id = controller().GetPendingEntry()->GetUniqueID();
1405 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1365 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1406 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1366 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after
3443 // An automatic navigation. 3403 // An automatic navigation.
3444 main_test_rfh()->SendNavigateWithModificationCallback( 3404 main_test_rfh()->SendNavigateWithModificationCallback(
3445 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); 3405 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture));
3446 3406
3447 EXPECT_EQ(1u, dialog_manager.reset_count()); 3407 EXPECT_EQ(1u, dialog_manager.reset_count());
3448 3408
3449 contents()->SetJavaScriptDialogManagerForTesting(nullptr); 3409 contents()->SetJavaScriptDialogManagerForTesting(nullptr);
3450 } 3410 }
3451 3411
3452 } // namespace content 3412 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698