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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 08f23f69226c2acd069abe0c0b3085ecabd1adb3..f9dcf5daa5d11009b61dc73c7b1a1476139c11a5 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 @@
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,
@@ -581,6 +588,13 @@
main_test_rfh()->PrepareForCommit();
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(
@@ -788,6 +802,13 @@
int pending_rvh_delete_count = 0;
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,
@@ -1031,7 +1052,6 @@
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 @@
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 @@
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,
@@ -1191,6 +1217,13 @@
EXPECT_TRUE(contents()->CrossProcessNavigationPending());
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(
@@ -1244,6 +1277,10 @@
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 @@
child_rfh->SendNavigateWithTransition(0, false,
GURL("http://google.com/frame"),
ui::PAGE_TRANSITION_AUTO_SUBFRAME);
-
- // Verify the navigation is not canceled.
+ EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack());
+
+ // 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 @@
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());
« 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