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

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

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

Powered by Google App Engine
This is Rietveld 408576698