OLD | NEW |
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 3001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3022 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3023 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
3023 | 3024 |
3024 // Destroy the remote player. No power save blockers should remain. | 3025 // Destroy the remote player. No power save blockers should remain. |
3025 rfh->OnMessageReceived( | 3026 rfh->OnMessageReceived( |
3026 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); | 3027 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); |
3027 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3028 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
3028 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3029 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
3029 } | 3030 } |
3030 #endif | 3031 #endif |
3031 | 3032 |
| 3033 // Test that sudden termination status is properly tracked for a frame. |
| 3034 TEST_F(WebContentsImplTest, SuddenTerminationForFrame) { |
| 3035 const GURL url("http://www.chromium.org"); |
| 3036 contents()->NavigateAndCommit(url); |
| 3037 |
| 3038 TestRenderFrameHost* frame = contents()->GetMainFrame(); |
| 3039 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3040 |
| 3041 // Register a BeforeUnload handler. |
| 3042 frame->SendBeforeUnloadHandlersPresent(true); |
| 3043 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3044 |
| 3045 // Unregister the BeforeUnload handler. |
| 3046 frame->SendBeforeUnloadHandlersPresent(false); |
| 3047 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3048 |
| 3049 // Register an Unload handler. |
| 3050 frame->SendUnloadHandlersPresent(true); |
| 3051 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3052 |
| 3053 // Unregister the Unload handler. |
| 3054 frame->SendUnloadHandlersPresent(false); |
| 3055 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3056 |
| 3057 // Register a BeforeUnload handler and an Unload handler. |
| 3058 frame->SendBeforeUnloadHandlersPresent(true); |
| 3059 frame->SendUnloadHandlersPresent(true); |
| 3060 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3061 |
| 3062 // Override the sudden termination status. |
| 3063 frame->set_override_sudden_termination_status(true); |
| 3064 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3065 frame->set_override_sudden_termination_status(false); |
| 3066 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3067 |
| 3068 // Sudden termination should not be allowed unless there are no BeforeUnload |
| 3069 // handlers and no Unload handlers in the RenderFrame. |
| 3070 frame->SendBeforeUnloadHandlersPresent(false); |
| 3071 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3072 frame->SendBeforeUnloadHandlersPresent(true); |
| 3073 frame->SendUnloadHandlersPresent(false); |
| 3074 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3075 frame->SendBeforeUnloadHandlersPresent(false); |
| 3076 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3077 } |
| 3078 |
3032 } // namespace content | 3079 } // namespace content |
OLD | NEW |