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

Side by Side 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: Created 5 years, 11 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h"
11 #include "content/browser/media/audio_stream_monitor.h" 12 #include "content/browser/media/audio_stream_monitor.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/site_instance_impl.h" 14 #include "content/browser/site_instance_impl.h"
14 #include "content/browser/webui/web_ui_controller_factory_registry.h" 15 #include "content/browser/webui/web_ui_controller_factory_registry.h"
15 #include "content/common/frame_messages.h" 16 #include "content/common/frame_messages.h"
16 #include "content/common/input/synthetic_web_input_event_builders.h" 17 #include "content/common/input/synthetic_web_input_event_builders.h"
17 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
18 #include "content/public/browser/global_request_id.h" 19 #include "content/public/browser/global_request_id.h"
19 #include "content/public/browser/interstitial_page_delegate.h" 20 #include "content/public/browser/interstitial_page_delegate.h"
20 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
(...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2980 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2980 2981
2981 // Destroy the remote player. No power save blockers should remain. 2982 // Destroy the remote player. No power save blockers should remain.
2982 rfh->OnMessageReceived( 2983 rfh->OnMessageReceived(
2983 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 2984 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId));
2984 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2985 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2985 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2986 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2986 } 2987 }
2987 #endif 2988 #endif
2988 2989
2990 // Test that sudden termination status is properly tracked for a frame.
2991 TEST_F(WebContentsImplTest, SuddenTerminationForFrame) {
2992 const GURL url("http://www.chromium.org");
2993 contents()->NavigateAndCommit(url);
2994
2995 TestRenderFrameHost* frame = contents()->GetMainFrame();
2996 EXPECT_TRUE(frame->SuddenTerminationAllowed());
2997
2998 // Register a BeforeUnload handler.
2999 frame->SendBeforeUnloadHandlersPresenceChanged(true);
3000 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3001
3002 // Unregister the BeforeUnload handler.
3003 frame->SendBeforeUnloadHandlersPresenceChanged(false);
3004 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3005
3006 // Register an Unload handler.
3007 frame->SendUnloadHandlersPresenceChanged(true);
3008 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3009
3010 // Unregister the Unload handler.
3011 frame->SendUnloadHandlersPresenceChanged(false);
3012 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3013
3014 // Register a BeforeUnload handler and an Unload handler.
3015 frame->SendBeforeUnloadHandlersPresenceChanged(true);
3016 frame->SendUnloadHandlersPresenceChanged(true);
3017 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3018
3019 // Override the sudden termination status.
3020 frame->set_override_sudden_termination_status(true);
3021 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3022 frame->set_override_sudden_termination_status(false);
3023 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3024
3025 // Sudden termination should not be allowed unless there are no BeforeUnload
3026 // handlers and no Unload handlers in the RenderFrame.
3027 frame->SendBeforeUnloadHandlersPresenceChanged(false);
3028 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3029 frame->SendBeforeUnloadHandlersPresenceChanged(true);
3030 frame->SendUnloadHandlersPresenceChanged(false);
3031 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3032 frame->SendBeforeUnloadHandlersPresenceChanged(false);
3033 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3034 }
3035
2989 } // namespace content 3036 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698