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

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

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

Powered by Google App Engine
This is Rietveld 408576698