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

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

Issue 1570043002: Implement MediaSession on top of the WebMediaPlayerDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session
Patch Set: Reorder. Created 4 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 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/browser/frame_host/cross_site_transferring_request.h" 13 #include "content/browser/frame_host/cross_site_transferring_request.h"
14 #include "content/browser/frame_host/interstitial_page_impl.h" 14 #include "content/browser/frame_host/interstitial_page_impl.h"
15 #include "content/browser/frame_host/navigation_entry_impl.h" 15 #include "content/browser/frame_host/navigation_entry_impl.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h" 16 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/frame_host/render_frame_proxy_host.h" 17 #include "content/browser/frame_host/render_frame_proxy_host.h"
18 #include "content/browser/media/audio_stream_monitor.h" 18 #include "content/browser/media/audio_stream_monitor.h"
19 #include "content/browser/media/media_web_contents_observer.h" 19 #include "content/browser/media/media_web_contents_observer.h"
20 #include "content/browser/renderer_host/render_view_host_impl.h" 20 #include "content/browser/renderer_host/render_view_host_impl.h"
21 #include "content/browser/site_instance_impl.h" 21 #include "content/browser/site_instance_impl.h"
22 #include "content/browser/webui/content_web_ui_controller_factory.h" 22 #include "content/browser/webui/content_web_ui_controller_factory.h"
23 #include "content/browser/webui/web_ui_controller_factory_registry.h" 23 #include "content/browser/webui/web_ui_controller_factory_registry.h"
24 #include "content/common/frame_messages.h" 24 #include "content/common/frame_messages.h"
25 #include "content/common/input/synthetic_web_input_event_builders.h" 25 #include "content/common/input/synthetic_web_input_event_builders.h"
26 #include "content/common/media/media_player_delegate_messages.h"
26 #include "content/common/site_isolation_policy.h" 27 #include "content/common/site_isolation_policy.h"
27 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
28 #include "content/public/browser/global_request_id.h" 29 #include "content/public/browser/global_request_id.h"
29 #include "content/public/browser/interstitial_page_delegate.h" 30 #include "content/public/browser/interstitial_page_delegate.h"
30 #include "content/public/browser/navigation_details.h" 31 #include "content/public/browser/navigation_details.h"
31 #include "content/public/browser/notification_details.h" 32 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
33 #include "content/public/browser/render_widget_host_view.h" 34 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/web_contents_delegate.h" 35 #include "content/public/browser/web_contents_delegate.h"
35 #include "content/public/browser/web_contents_observer.h" 36 #include "content/public/browser/web_contents_observer.h"
(...skipping 3156 matching lines...) Expand 10 before | Expand all | Expand 10 after
3192 3193
3193 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents 3194 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents
3194 // should now have stopped loading. 3195 // should now have stopped loading.
3195 new_current_rfh->OnMessageReceived( 3196 new_current_rfh->OnMessageReceived(
3196 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID())); 3197 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID()));
3197 EXPECT_EQ(contents()->GetMainFrame(), new_current_rfh); 3198 EXPECT_EQ(contents()->GetMainFrame(), new_current_rfh);
3198 EXPECT_FALSE(contents()->IsLoading()); 3199 EXPECT_FALSE(contents()->IsLoading());
3199 } 3200 }
3200 3201
3201 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { 3202 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
3202 // PlayerIDs are actually pointers cast to int64_t, so verify that both 3203 // Verify that both negative and positive player ids don't blow up.
3203 // negative
3204 // and positive player ids don't blow up.
3205 const int kPlayerAudioVideoId = 15; 3204 const int kPlayerAudioVideoId = 15;
3206 const int kPlayerAudioOnlyId = -15; 3205 const int kPlayerAudioOnlyId = -15;
3207 const int kPlayerVideoOnlyId = 30; 3206 const int kPlayerVideoOnlyId = 30;
3208 const int kPlayerRemoteId = -30; 3207 const int kPlayerRemoteId = -30;
3209 3208
3210 EXPECT_FALSE(has_audio_power_save_blocker()); 3209 EXPECT_FALSE(has_audio_power_save_blocker());
3211 EXPECT_FALSE(has_video_power_save_blocker()); 3210 EXPECT_FALSE(has_video_power_save_blocker());
3212 3211
3213 TestRenderFrameHost* rfh = contents()->GetMainFrame(); 3212 TestRenderFrameHost* rfh = contents()->GetMainFrame();
3214 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); 3213 AudioStreamMonitor* monitor = contents()->audio_stream_monitor();
(...skipping 13 matching lines...) Expand all
3228 // Send another fake notification, this time when WasRecentlyAudible() will 3227 // Send another fake notification, this time when WasRecentlyAudible() will
3229 // be false. The power save blocker should be released. 3228 // be false. The power save blocker should be released.
3230 monitor->set_was_recently_audible_for_testing(false); 3229 monitor->set_was_recently_audible_for_testing(false);
3231 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 3230 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
3232 EXPECT_FALSE(has_audio_power_save_blocker()); 3231 EXPECT_FALSE(has_audio_power_save_blocker());
3233 } 3232 }
3234 3233
3235 // Start a player with both audio and video. A video power save blocker 3234 // Start a player with both audio and video. A video power save blocker
3236 // should be created. If audio stream monitoring is available, an audio power 3235 // should be created. If audio stream monitoring is available, an audio power
3237 // save blocker should be created too. 3236 // save blocker should be created too.
3238 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3237 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying(
3239 0, kPlayerAudioVideoId, true, true, false)); 3238 0, kPlayerAudioVideoId, true, true, false, base::TimeDelta()));
3240 EXPECT_TRUE(has_video_power_save_blocker()); 3239 EXPECT_TRUE(has_video_power_save_blocker());
3241 EXPECT_EQ(has_audio_power_save_blocker(), 3240 EXPECT_EQ(has_audio_power_save_blocker(),
3242 !AudioStreamMonitor::monitoring_available()); 3241 !AudioStreamMonitor::monitoring_available());
3243 3242
3244 // Upon hiding the video power save blocker should be released. 3243 // Upon hiding the video power save blocker should be released.
3245 contents()->WasHidden(); 3244 contents()->WasHidden();
3246 EXPECT_FALSE(has_video_power_save_blocker()); 3245 EXPECT_FALSE(has_video_power_save_blocker());
3247 3246
3248 // Start another player that only has video. There should be no change in 3247 // Start another player that only has video. There should be no change in
3249 // the power save blockers. The notification should take into account the 3248 // the power save blockers. The notification should take into account the
3250 // visibility state of the WebContents. 3249 // visibility state of the WebContents.
3251 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3250 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying(
3252 0, kPlayerVideoOnlyId, true, false, false)); 3251 0, kPlayerVideoOnlyId, true, false, false, base::TimeDelta()));
3253 EXPECT_FALSE(has_video_power_save_blocker()); 3252 EXPECT_FALSE(has_video_power_save_blocker());
3254 EXPECT_EQ(has_audio_power_save_blocker(), 3253 EXPECT_EQ(has_audio_power_save_blocker(),
3255 !AudioStreamMonitor::monitoring_available()); 3254 !AudioStreamMonitor::monitoring_available());
3256 3255
3257 // Showing the WebContents should result in the creation of the blocker. 3256 // Showing the WebContents should result in the creation of the blocker.
3258 contents()->WasShown(); 3257 contents()->WasShown();
3259 EXPECT_TRUE(has_video_power_save_blocker()); 3258 EXPECT_TRUE(has_video_power_save_blocker());
3260 3259
3261 // Start another player that only has audio. There should be no change in 3260 // Start another player that only has audio. There should be no change in
3262 // the power save blockers. 3261 // the power save blockers.
3263 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3262 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying(
3264 0, kPlayerAudioOnlyId, false, true, false)); 3263 0, kPlayerAudioOnlyId, false, true, false, base::TimeDelta()));
3265 EXPECT_TRUE(has_video_power_save_blocker()); 3264 EXPECT_TRUE(has_video_power_save_blocker());
3266 EXPECT_EQ(has_audio_power_save_blocker(), 3265 EXPECT_EQ(has_audio_power_save_blocker(),
3267 !AudioStreamMonitor::monitoring_available()); 3266 !AudioStreamMonitor::monitoring_available());
3268 3267
3269 // Start a remote player. There should be no change in the power save 3268 // Start a remote player. There should be no change in the power save
3270 // blockers. 3269 // blockers.
3271 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3270 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying(
3272 0, kPlayerRemoteId, true, true, true)); 3271 0, kPlayerRemoteId, true, true, true, base::TimeDelta()));
3273 EXPECT_TRUE(has_video_power_save_blocker()); 3272 EXPECT_TRUE(has_video_power_save_blocker());
3274 EXPECT_EQ(has_audio_power_save_blocker(), 3273 EXPECT_EQ(has_audio_power_save_blocker(),
3275 !AudioStreamMonitor::monitoring_available()); 3274 !AudioStreamMonitor::monitoring_available());
3276 3275
3277 // Destroy the original audio video player. Both power save blockers should 3276 // Destroy the original audio video player. Both power save blockers should
3278 // remain. 3277 // remain.
3279 rfh->OnMessageReceived( 3278 rfh->OnMessageReceived(
3280 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); 3279 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioVideoId, false));
3281 EXPECT_TRUE(has_video_power_save_blocker()); 3280 EXPECT_TRUE(has_video_power_save_blocker());
3282 EXPECT_EQ(has_audio_power_save_blocker(), 3281 EXPECT_EQ(has_audio_power_save_blocker(),
3283 !AudioStreamMonitor::monitoring_available()); 3282 !AudioStreamMonitor::monitoring_available());
3284 3283
3285 // Destroy the audio only player. The video power save blocker should remain. 3284 // Destroy the audio only player. The video power save blocker should remain.
3286 rfh->OnMessageReceived( 3285 rfh->OnMessageReceived(
3287 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); 3286 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioOnlyId, false));
3288 EXPECT_TRUE(has_video_power_save_blocker()); 3287 EXPECT_TRUE(has_video_power_save_blocker());
3289 EXPECT_FALSE(has_audio_power_save_blocker()); 3288 EXPECT_FALSE(has_audio_power_save_blocker());
3290 3289
3291 // Destroy the video only player. No power save blockers should remain. 3290 // Destroy the video only player. No power save blockers should remain.
3292 rfh->OnMessageReceived( 3291 rfh->OnMessageReceived(
3293 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); 3292 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerVideoOnlyId, false));
3294 EXPECT_FALSE(has_video_power_save_blocker()); 3293 EXPECT_FALSE(has_video_power_save_blocker());
3295 EXPECT_FALSE(has_audio_power_save_blocker()); 3294 EXPECT_FALSE(has_audio_power_save_blocker());
3296 3295
3297 // Destroy the remote player. No power save blockers should remain. 3296 // Destroy the remote player. No power save blockers should remain.
3298 rfh->OnMessageReceived( 3297 rfh->OnMessageReceived(
3299 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 3298 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerRemoteId, false));
3300 EXPECT_FALSE(has_video_power_save_blocker()); 3299 EXPECT_FALSE(has_video_power_save_blocker());
3301 EXPECT_FALSE(has_audio_power_save_blocker()); 3300 EXPECT_FALSE(has_audio_power_save_blocker());
3302 3301
3303 // Start a player with both audio and video. A video power save blocker 3302 // Start a player with both audio and video. A video power save blocker
3304 // should be created. If audio stream monitoring is available, an audio power 3303 // should be created. If audio stream monitoring is available, an audio power
3305 // save blocker should be created too. 3304 // save blocker should be created too.
3306 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3305 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying(
3307 0, kPlayerAudioVideoId, true, true, false)); 3306 0, kPlayerAudioVideoId, true, true, false, base::TimeDelta()));
3308 EXPECT_TRUE(has_video_power_save_blocker()); 3307 EXPECT_TRUE(has_video_power_save_blocker());
3309 EXPECT_EQ(has_audio_power_save_blocker(), 3308 EXPECT_EQ(has_audio_power_save_blocker(),
3310 !AudioStreamMonitor::monitoring_available()); 3309 !AudioStreamMonitor::monitoring_available());
3311 3310
3312 // Crash the renderer. 3311 // Crash the renderer.
3313 contents()->GetMainFrame()->GetProcess()->SimulateCrash(); 3312 contents()->GetMainFrame()->GetProcess()->SimulateCrash();
3314 3313
3315 // Verify that all the power save blockers have been released. 3314 // Verify that all the power save blockers have been released.
3316 EXPECT_FALSE(has_video_power_save_blocker()); 3315 EXPECT_FALSE(has_video_power_save_blocker());
3317 EXPECT_FALSE(has_audio_power_save_blocker()); 3316 EXPECT_FALSE(has_audio_power_save_blocker());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 backend->AllowCertForHost(*cert, test_url.host(), 1); 3377 backend->AllowCertForHost(*cert, test_url.host(), 1);
3379 EXPECT_TRUE(backend->HasAllowException(test_url.host())); 3378 EXPECT_TRUE(backend->HasAllowException(test_url.host()));
3380 3379
3381 contents()->OnDidLoadResourceFromMemoryCache(test_url, "", "GET", "mime type", 3380 contents()->OnDidLoadResourceFromMemoryCache(test_url, "", "GET", "mime type",
3382 RESOURCE_TYPE_MAIN_FRAME); 3381 RESOURCE_TYPE_MAIN_FRAME);
3383 3382
3384 EXPECT_TRUE(backend->HasAllowException(test_url.host())); 3383 EXPECT_TRUE(backend->HasAllowException(test_url.host()));
3385 } 3384 }
3386 3385
3387 } // namespace content 3386 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_web_contents_observer.cc ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698