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

Unified Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 857213003: Refactor sudden termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.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 ded5a4be207d4f581cabbe833f670c4554cfbc5c..e0102d2c7f7f1977f62f17415643f2361daf5ff7 100644
--- a/content/browser/web_contents/web_contents_impl_unittest.cc
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc
@@ -8,6 +8,7 @@
#include "content/browser/frame_host/cross_site_transferring_request.h"
#include "content/browser/frame_host/interstitial_page_impl.h"
#include "content/browser/frame_host/navigation_entry_impl.h"
+#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/media/audio_stream_monitor.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/site_instance_impl.h"
@@ -3029,4 +3030,50 @@ TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
}
#endif
+// Test that sudden termination status is properly tracked for a frame.
+TEST_F(WebContentsImplTest, SuddenTerminationForFrame) {
+ const GURL url("http://www.chromium.org");
+ contents()->NavigateAndCommit(url);
+
+ TestRenderFrameHost* frame = contents()->GetMainFrame();
+ EXPECT_TRUE(frame->SuddenTerminationAllowed());
+
+ // Register a BeforeUnload handler.
+ frame->SendBeforeUnloadHandlersPresent(true);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+
+ // Unregister the BeforeUnload handler.
+ frame->SendBeforeUnloadHandlersPresent(false);
+ EXPECT_TRUE(frame->SuddenTerminationAllowed());
+
+ // Register an Unload handler.
+ frame->SendUnloadHandlersPresent(true);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+
+ // Unregister the Unload handler.
+ frame->SendUnloadHandlersPresent(false);
+ EXPECT_TRUE(frame->SuddenTerminationAllowed());
+
+ // Register a BeforeUnload handler and an Unload handler.
+ frame->SendBeforeUnloadHandlersPresent(true);
+ frame->SendUnloadHandlersPresent(true);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+
+ // Override the sudden termination status.
+ frame->set_override_sudden_termination_status(true);
+ EXPECT_TRUE(frame->SuddenTerminationAllowed());
+ frame->set_override_sudden_termination_status(false);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+
+ // Sudden termination should not be allowed unless there are no BeforeUnload
+ // handlers and no Unload handlers in the RenderFrame.
+ frame->SendBeforeUnloadHandlersPresent(false);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+ frame->SendBeforeUnloadHandlersPresent(true);
+ frame->SendUnloadHandlersPresent(false);
+ EXPECT_FALSE(frame->SuddenTerminationAllowed());
+ frame->SendBeforeUnloadHandlersPresent(false);
+ EXPECT_TRUE(frame->SuddenTerminationAllowed());
+}
+
} // namespace content
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698