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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 972973002: Revert of Propagate audible state from player to the containing tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/frame_host/render_frame_host_impl.h"
12 #include "content/browser/media/audio_state_provider.h" 12 #include "content/browser/media/audio_stream_monitor.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/site_instance_impl.h" 14 #include "content/browser/site_instance_impl.h"
15 #include "content/browser/webui/web_ui_controller_factory_registry.h" 15 #include "content/browser/webui/web_ui_controller_factory_registry.h"
16 #include "content/common/frame_messages.h" 16 #include "content/common/frame_messages.h"
17 #include "content/common/input/synthetic_web_input_event_builders.h" 17 #include "content/common/input/synthetic_web_input_event_builders.h"
18 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "content/public/browser/global_request_id.h" 19 #include "content/public/browser/global_request_id.h"
20 #include "content/public/browser/interstitial_page_delegate.h" 20 #include "content/public/browser/interstitial_page_delegate.h"
21 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
22 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
(...skipping 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 // and positive player ids don't blow up. 2884 // and positive player ids don't blow up.
2885 const int kPlayerAudioVideoId = 15; 2885 const int kPlayerAudioVideoId = 15;
2886 const int kPlayerAudioOnlyId = -15; 2886 const int kPlayerAudioOnlyId = -15;
2887 const int kPlayerVideoOnlyId = 30; 2887 const int kPlayerVideoOnlyId = 30;
2888 const int kPlayerRemoteId = -30; 2888 const int kPlayerRemoteId = -30;
2889 2889
2890 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2890 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2891 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2891 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2892 2892
2893 TestRenderFrameHost* rfh = contents()->GetMainFrame(); 2893 TestRenderFrameHost* rfh = contents()->GetMainFrame();
2894 AudioStateProvider* audio_state = contents()->audio_state_provider(); 2894 AudioStreamMonitor* monitor = contents()->audio_stream_monitor();
2895 2895
2896 // The audio power save blocker should not be based on having a media player 2896 // The audio power save blocker should not be based on having a media player
2897 // when audio stream monitoring is available. 2897 // when audio stream monitoring is available.
2898 if (audio_state->IsAudioStateAvailable()) { 2898 if (AudioStreamMonitor::monitoring_available()) {
2899 // Send a fake audio stream monitor notification. The audio power save 2899 // Send a fake audio stream monitor notification. The audio power save
2900 // blocker should be created. 2900 // blocker should be created.
2901 audio_state->set_was_recently_audible_for_testing(true); 2901 monitor->set_was_recently_audible_for_testing(true);
2902 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 2902 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
2903 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing()); 2903 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing());
2904 2904
2905 // Send another fake notification, this time when WasRecentlyAudible() will 2905 // Send another fake notification, this time when WasRecentlyAudible() will
2906 // be false. The power save blocker should be released. 2906 // be false. The power save blocker should be released.
2907 audio_state->set_was_recently_audible_for_testing(false); 2907 monitor->set_was_recently_audible_for_testing(false);
2908 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 2908 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
2909 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2909 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2910 } 2910 }
2911 2911
2912 // Start a player with both audio and video. A video power save blocker 2912 // Start a player with both audio and video. A video power save blocker
2913 // should be created. If audio stream monitoring is available, an audio power 2913 // should be created. If audio stream monitoring is available, an audio power
2914 // save blocker should be created too. 2914 // save blocker should be created too.
2915 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 2915 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2916 0, kPlayerAudioVideoId, true, true, false)); 2916 0, kPlayerAudioVideoId, true, true, false));
2917 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2917 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2918 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2918 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2919 !audio_state->IsAudioStateAvailable()); 2919 !AudioStreamMonitor::monitoring_available());
2920 2920
2921 // Upon hiding the video power save blocker should be released. 2921 // Upon hiding the video power save blocker should be released.
2922 contents()->WasHidden(); 2922 contents()->WasHidden();
2923 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2923 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2924 2924
2925 // Start another player that only has video. There should be no change in 2925 // Start another player that only has video. There should be no change in
2926 // the power save blockers. The notification should take into account the 2926 // the power save blockers. The notification should take into account the
2927 // visibility state of the WebContents. 2927 // visibility state of the WebContents.
2928 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 2928 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2929 0, kPlayerVideoOnlyId, true, false, false)); 2929 0, kPlayerVideoOnlyId, true, false, false));
2930 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2930 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2931 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2931 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2932 !audio_state->IsAudioStateAvailable()); 2932 !AudioStreamMonitor::monitoring_available());
2933 2933
2934 // Showing the WebContents should result in the creation of the blocker. 2934 // Showing the WebContents should result in the creation of the blocker.
2935 contents()->WasShown(); 2935 contents()->WasShown();
2936 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2936 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2937 2937
2938 // Start another player that only has audio. There should be no change in 2938 // Start another player that only has audio. There should be no change in
2939 // the power save blockers. 2939 // the power save blockers.
2940 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 2940 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2941 0, kPlayerAudioOnlyId, false, true, false)); 2941 0, kPlayerAudioOnlyId, false, true, false));
2942 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2942 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2943 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2943 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2944 !audio_state->IsAudioStateAvailable()); 2944 !AudioStreamMonitor::monitoring_available());
2945 2945
2946 // Start a remote player. There should be no change in the power save 2946 // Start a remote player. There should be no change in the power save
2947 // blockers. 2947 // blockers.
2948 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 2948 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2949 0, kPlayerRemoteId, true, true, true)); 2949 0, kPlayerRemoteId, true, true, true));
2950 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2950 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2951 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2951 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2952 !audio_state->IsAudioStateAvailable()); 2952 !AudioStreamMonitor::monitoring_available());
2953 2953
2954 // Destroy the original audio video player. Both power save blockers should 2954 // Destroy the original audio video player. Both power save blockers should
2955 // remain. 2955 // remain.
2956 rfh->OnMessageReceived( 2956 rfh->OnMessageReceived(
2957 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); 2957 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId));
2958 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2958 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2959 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2959 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2960 !audio_state->IsAudioStateAvailable()); 2960 !AudioStreamMonitor::monitoring_available());
2961 2961
2962 // Destroy the audio only player. The video power save blocker should remain. 2962 // Destroy the audio only player. The video power save blocker should remain.
2963 rfh->OnMessageReceived( 2963 rfh->OnMessageReceived(
2964 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); 2964 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId));
2965 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2965 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2966 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2966 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2967 2967
2968 // Destroy the video only player. No power save blockers should remain. 2968 // Destroy the video only player. No power save blockers should remain.
2969 rfh->OnMessageReceived( 2969 rfh->OnMessageReceived(
2970 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); 2970 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId));
2971 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2971 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2972 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2972 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2973 2973
2974 // Destroy the remote player. No power save blockers should remain. 2974 // Destroy the remote player. No power save blockers should remain.
2975 rfh->OnMessageReceived( 2975 rfh->OnMessageReceived(
2976 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 2976 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId));
2977 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2977 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2978 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2978 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2979 2979
2980 // Start a player with both audio and video. A video power save blocker 2980 // Start a player with both audio and video. A video power save blocker
2981 // should be created. If audio stream monitoring is available, an audio power 2981 // should be created. If audio stream monitoring is available, an audio power
2982 // save blocker should be created too. 2982 // save blocker should be created too.
2983 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 2983 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2984 0, kPlayerAudioVideoId, true, true, false)); 2984 0, kPlayerAudioVideoId, true, true, false));
2985 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 2985 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2986 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 2986 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2987 !audio_state->IsAudioStateAvailable()); 2987 !AudioStreamMonitor::monitoring_available());
2988 2988
2989 // Crash the renderer. 2989 // Crash the renderer.
2990 contents()->GetMainFrame()->OnMessageReceived( 2990 contents()->GetMainFrame()->OnMessageReceived(
2991 FrameHostMsg_RenderProcessGone( 2991 FrameHostMsg_RenderProcessGone(
2992 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 2992 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
2993 2993
2994 // Verify that all the power save blockers have been released. 2994 // Verify that all the power save blockers have been released.
2995 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2995 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2996 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2996 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2997 } 2997 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 frame->SendBeforeUnloadHandlersPresent(false); 3036 frame->SendBeforeUnloadHandlersPresent(false);
3037 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3037 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3038 frame->SendBeforeUnloadHandlersPresent(true); 3038 frame->SendBeforeUnloadHandlersPresent(true);
3039 frame->SendUnloadHandlersPresent(false); 3039 frame->SendUnloadHandlersPresent(false);
3040 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3040 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3041 frame->SendBeforeUnloadHandlersPresent(false); 3041 frame->SendBeforeUnloadHandlersPresent(false);
3042 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3042 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3043 } 3043 }
3044 3044
3045 } // namespace content 3045 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698