Index: content/browser/web_contents/web_contents_impl_unittest.cc |
diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc |
index e7fba9b301a2aab8883492837dfe42919de519b9..36ce1924d1dbcfd1388a83d87c375011be32f515 100644 |
--- a/content/browser/web_contents/web_contents_impl_unittest.cc |
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc |
@@ -550,6 +550,13 @@ TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
pending_rfh->GetRenderViewHost()->set_delete_counter( |
&pending_rvh_delete_count); |
+ // Navigations should be suspended in pending_rfh until BeforeUnloadACK. |
+ if (!IsBrowserSideNavigationEnabled()) { |
+ EXPECT_TRUE(pending_rfh->are_navigations_suspended()); |
+ orig_rfh->SendBeforeUnloadACK(true); |
+ EXPECT_FALSE(pending_rfh->are_navigations_suspended()); |
+ } |
+ |
// DidNavigate from the pending page |
contents()->TestDidNavigateWithSequenceNumber( |
pending_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
@@ -582,6 +589,13 @@ TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); |
EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
+ // Navigations should be suspended in goback_rfh until BeforeUnloadACK. |
+ if (!IsBrowserSideNavigationEnabled()) { |
+ EXPECT_TRUE(goback_rfh->are_navigations_suspended()); |
+ pending_rfh->SendBeforeUnloadACK(true); |
+ EXPECT_FALSE(goback_rfh->are_navigations_suspended()); |
+ } |
+ |
// DidNavigate from the back action |
contents()->TestDidNavigateWithSequenceNumber( |
goback_rfh, entry_id, false, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
@@ -789,6 +803,13 @@ TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { |
pending_rfh->GetRenderViewHost()->set_delete_counter( |
&pending_rvh_delete_count); |
+ // Navigations should be suspended in pending_rvh until BeforeUnloadACK. |
+ if (!IsBrowserSideNavigationEnabled()) { |
+ EXPECT_TRUE(pending_rfh->are_navigations_suspended()); |
+ orig_rfh->SendBeforeUnloadACK(true); |
+ EXPECT_FALSE(pending_rfh->are_navigations_suspended()); |
+ } |
+ |
// DidNavigate from the pending page. |
contents()->TestDidNavigate(pending_rfh, entry_id, true, url2, |
ui::PAGE_TRANSITION_TYPED); |
@@ -1031,7 +1052,6 @@ TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { |
controller().LoadURL( |
url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
- main_test_rfh()->set_has_beforeunload_handlers(); |
main_test_rfh()->PrepareForCommit(); |
contents()->TestDidNavigate(orig_rfh, entry_id, true, url, |
ui::PAGE_TRANSITION_TYPED); |
@@ -1095,6 +1115,8 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { |
const GURL url2("http://www.yahoo.com"); |
controller().LoadURL( |
url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
+ EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); |
+ orig_rfh->PrepareForCommit(); |
EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
// Suppose the original renderer navigates before the new one is ready. |
@@ -1143,6 +1165,10 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); |
+ // Simulate beforeunload approval. |
+ EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack()); |
+ webui_rfh->PrepareForCommit(); |
+ |
// DidNavigate from the pending page. |
contents()->TestDidNavigateWithSequenceNumber( |
google_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
@@ -1192,6 +1218,13 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
EXPECT_TRUE(contents()->GetPendingMainFrame()); |
EXPECT_EQ(entry1, controller().GetPendingEntry()); |
+ // Simulate beforeunload approval. |
+ EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); |
+ base::TimeTicks now = base::TimeTicks::Now(); |
+ google_rfh->PrepareForCommit(); |
+ google_rfh->OnMessageReceived( |
+ FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
+ |
// DidNavigate from the first back. This aborts the second back's pending RFH. |
contents()->TestDidNavigateWithSequenceNumber( |
google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(), |
@@ -1244,6 +1277,10 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationBackOldNavigationIgnored) { |
EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); |
+ // Simulate beforeunload approval. |
+ EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack()); |
+ webui_rfh->PrepareForCommit(); |
+ |
// DidNavigate from the pending page. |
contents()->TestDidNavigate(google_rfh, entry_id, true, url2, |
ui::PAGE_TRANSITION_TYPED); |
@@ -1331,8 +1368,12 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { |
child_rfh->SendNavigateWithTransition(0, false, |
GURL("http://google.com/frame"), |
ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
+ EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); |
- // Verify the navigation is not canceled. |
+ // Now simulate the onbeforeunload approval and verify the navigation is |
+ // not canceled. |
+ orig_rfh->PrepareForCommit(); |
+ EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); |
EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
} |
@@ -1353,7 +1394,6 @@ TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
int entry1_id = controller().GetPendingEntry()->GetUniqueID(); |
TestRenderFrameHost* orig_rfh = main_test_rfh(); |
- orig_rfh->set_has_beforeunload_handlers(); |
orig_rfh->PrepareForCommit(); |
EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |