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 <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" |
(...skipping 3181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3192 | 3192 |
3193 EXPECT_FALSE(has_audio_power_save_blocker()); | 3193 EXPECT_FALSE(has_audio_power_save_blocker()); |
3194 EXPECT_FALSE(has_video_power_save_blocker()); | 3194 EXPECT_FALSE(has_video_power_save_blocker()); |
3195 | 3195 |
3196 TestRenderFrameHost* rfh = main_test_rfh(); | 3196 TestRenderFrameHost* rfh = main_test_rfh(); |
3197 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); | 3197 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); |
3198 | 3198 |
3199 // Ensure RenderFrame is initialized before simulating events coming from it. | 3199 // Ensure RenderFrame is initialized before simulating events coming from it. |
3200 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 3200 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
3201 | 3201 |
3202 // The audio power save blocker should not be based on having a media player | 3202 // Send a fake audio stream monitor notification. The audio power save |
3203 // when audio stream monitoring is available. | 3203 // blocker should be created. |
3204 if (AudioStreamMonitor::monitoring_available()) { | 3204 monitor->set_was_recently_audible_for_testing(true); |
3205 // Send a fake audio stream monitor notification. The audio power save | 3205 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
3206 // blocker should be created. | 3206 EXPECT_TRUE(has_audio_power_save_blocker()); |
3207 monitor->set_was_recently_audible_for_testing(true); | |
3208 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | |
3209 EXPECT_TRUE(has_audio_power_save_blocker()); | |
3210 | 3207 |
3211 // Send another fake notification, this time when WasRecentlyAudible() will | 3208 // Send another fake notification, this time when WasRecentlyAudible() will |
3212 // be false. The power save blocker should be released. | 3209 // be false. The power save blocker should be released. |
3213 monitor->set_was_recently_audible_for_testing(false); | 3210 monitor->set_was_recently_audible_for_testing(false); |
3214 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 3211 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
3215 EXPECT_FALSE(has_audio_power_save_blocker()); | 3212 EXPECT_FALSE(has_audio_power_save_blocker()); |
3216 } | |
3217 | 3213 |
3218 // Start a player with both audio and video. A video power save blocker | 3214 // Start a player with both audio and video. A video power save blocker |
3219 // should be created. If audio stream monitoring is available, an audio power | 3215 // should be created. If audio stream monitoring is available, an audio power |
3220 // save blocker should be created too. | 3216 // save blocker should be created too. |
3221 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3217 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3222 0, kPlayerAudioVideoId, true, true, false, | 3218 0, kPlayerAudioVideoId, true, true, false, |
3223 media::MediaContentType::Persistent)); | 3219 media::MediaContentType::Persistent)); |
3224 EXPECT_TRUE(has_video_power_save_blocker()); | 3220 EXPECT_TRUE(has_video_power_save_blocker()); |
3225 EXPECT_EQ(has_audio_power_save_blocker(), | 3221 EXPECT_FALSE(has_audio_power_save_blocker()); |
3226 !AudioStreamMonitor::monitoring_available()); | |
3227 | 3222 |
3228 // Upon hiding the video power save blocker should be released. | 3223 // Upon hiding the video power save blocker should be released. |
3229 contents()->WasHidden(); | 3224 contents()->WasHidden(); |
3230 EXPECT_FALSE(has_video_power_save_blocker()); | 3225 EXPECT_FALSE(has_video_power_save_blocker()); |
3231 | 3226 |
3232 // Start another player that only has video. There should be no change in | 3227 // Start another player that only has video. There should be no change in |
3233 // the power save blockers. The notification should take into account the | 3228 // the power save blockers. The notification should take into account the |
3234 // visibility state of the WebContents. | 3229 // visibility state of the WebContents. |
3235 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3230 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3236 0, kPlayerVideoOnlyId, true, false, false, | 3231 0, kPlayerVideoOnlyId, true, false, false, |
3237 media::MediaContentType::Persistent)); | 3232 media::MediaContentType::Persistent)); |
3238 EXPECT_FALSE(has_video_power_save_blocker()); | 3233 EXPECT_FALSE(has_video_power_save_blocker()); |
3239 EXPECT_EQ(has_audio_power_save_blocker(), | 3234 EXPECT_FALSE(has_audio_power_save_blocker()); |
3240 !AudioStreamMonitor::monitoring_available()); | |
3241 | 3235 |
3242 // Showing the WebContents should result in the creation of the blocker. | 3236 // Showing the WebContents should result in the creation of the blocker. |
3243 contents()->WasShown(); | 3237 contents()->WasShown(); |
3244 EXPECT_TRUE(has_video_power_save_blocker()); | 3238 EXPECT_TRUE(has_video_power_save_blocker()); |
3245 | 3239 |
3246 // Start another player that only has audio. There should be no change in | 3240 // Start another player that only has audio. There should be no change in |
3247 // the power save blockers. | 3241 // the power save blockers. |
3248 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3242 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3249 0, kPlayerAudioOnlyId, false, true, false, | 3243 0, kPlayerAudioOnlyId, false, true, false, |
3250 media::MediaContentType::Persistent)); | 3244 media::MediaContentType::Persistent)); |
3251 EXPECT_TRUE(has_video_power_save_blocker()); | 3245 EXPECT_TRUE(has_video_power_save_blocker()); |
3252 EXPECT_EQ(has_audio_power_save_blocker(), | 3246 EXPECT_FALSE(has_audio_power_save_blocker()); |
3253 !AudioStreamMonitor::monitoring_available()); | |
3254 | 3247 |
3255 // Start a remote player. There should be no change in the power save | 3248 // Start a remote player. There should be no change in the power save |
3256 // blockers. | 3249 // blockers. |
3257 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3250 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3258 0, kPlayerRemoteId, true, true, true, | 3251 0, kPlayerRemoteId, true, true, true, |
3259 media::MediaContentType::Persistent)); | 3252 media::MediaContentType::Persistent)); |
3260 EXPECT_TRUE(has_video_power_save_blocker()); | 3253 EXPECT_TRUE(has_video_power_save_blocker()); |
3261 EXPECT_EQ(has_audio_power_save_blocker(), | 3254 EXPECT_FALSE(has_audio_power_save_blocker()); |
3262 !AudioStreamMonitor::monitoring_available()); | |
3263 | 3255 |
3264 // Destroy the original audio video player. Both power save blockers should | 3256 // Destroy the original audio video player. Both power save blockers should |
3265 // remain. | 3257 // remain. |
3266 rfh->OnMessageReceived( | 3258 rfh->OnMessageReceived( |
3267 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioVideoId, false)); | 3259 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioVideoId, false)); |
3268 EXPECT_TRUE(has_video_power_save_blocker()); | 3260 EXPECT_TRUE(has_video_power_save_blocker()); |
3269 EXPECT_EQ(has_audio_power_save_blocker(), | 3261 EXPECT_FALSE(has_audio_power_save_blocker()); |
3270 !AudioStreamMonitor::monitoring_available()); | |
3271 | 3262 |
3272 // Destroy the audio only player. The video power save blocker should remain. | 3263 // Destroy the audio only player. The video power save blocker should remain. |
3273 rfh->OnMessageReceived( | 3264 rfh->OnMessageReceived( |
3274 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioOnlyId, false)); | 3265 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioOnlyId, false)); |
3275 EXPECT_TRUE(has_video_power_save_blocker()); | 3266 EXPECT_TRUE(has_video_power_save_blocker()); |
3276 EXPECT_FALSE(has_audio_power_save_blocker()); | 3267 EXPECT_FALSE(has_audio_power_save_blocker()); |
3277 | 3268 |
3278 // Destroy the video only player. No power save blockers should remain. | 3269 // Destroy the video only player. No power save blockers should remain. |
3279 rfh->OnMessageReceived( | 3270 rfh->OnMessageReceived( |
3280 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerVideoOnlyId, false)); | 3271 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerVideoOnlyId, false)); |
3281 EXPECT_FALSE(has_video_power_save_blocker()); | 3272 EXPECT_FALSE(has_video_power_save_blocker()); |
3282 EXPECT_FALSE(has_audio_power_save_blocker()); | 3273 EXPECT_FALSE(has_audio_power_save_blocker()); |
3283 | 3274 |
3284 // Destroy the remote player. No power save blockers should remain. | 3275 // Destroy the remote player. No power save blockers should remain. |
3285 rfh->OnMessageReceived( | 3276 rfh->OnMessageReceived( |
3286 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerRemoteId, false)); | 3277 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerRemoteId, false)); |
3287 EXPECT_FALSE(has_video_power_save_blocker()); | 3278 EXPECT_FALSE(has_video_power_save_blocker()); |
3288 EXPECT_FALSE(has_audio_power_save_blocker()); | 3279 EXPECT_FALSE(has_audio_power_save_blocker()); |
3289 | 3280 |
3290 // Start a player with both audio and video. A video power save blocker | 3281 // Start a player with both audio and video. A video power save blocker |
3291 // should be created. If audio stream monitoring is available, an audio power | 3282 // should be created. If audio stream monitoring is available, an audio power |
3292 // save blocker should be created too. | 3283 // save blocker should be created too. |
3293 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3284 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3294 0, kPlayerAudioVideoId, true, true, false, | 3285 0, kPlayerAudioVideoId, true, true, false, |
3295 media::MediaContentType::Persistent)); | 3286 media::MediaContentType::Persistent)); |
3296 EXPECT_TRUE(has_video_power_save_blocker()); | 3287 EXPECT_TRUE(has_video_power_save_blocker()); |
3297 EXPECT_EQ(has_audio_power_save_blocker(), | 3288 EXPECT_FALSE(has_audio_power_save_blocker()); |
3298 !AudioStreamMonitor::monitoring_available()); | |
3299 | 3289 |
3300 // Crash the renderer. | 3290 // Crash the renderer. |
3301 main_test_rfh()->GetProcess()->SimulateCrash(); | 3291 main_test_rfh()->GetProcess()->SimulateCrash(); |
3302 | 3292 |
3303 // Verify that all the power save blockers have been released. | 3293 // Verify that all the power save blockers have been released. |
3304 EXPECT_FALSE(has_video_power_save_blocker()); | 3294 EXPECT_FALSE(has_video_power_save_blocker()); |
3305 EXPECT_FALSE(has_audio_power_save_blocker()); | 3295 EXPECT_FALSE(has_audio_power_save_blocker()); |
3306 } | 3296 } |
3307 | 3297 |
3308 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { | 3298 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3425 // An automatic navigation. | 3415 // An automatic navigation. |
3426 main_test_rfh()->SendNavigateWithModificationCallback( | 3416 main_test_rfh()->SendNavigateWithModificationCallback( |
3427 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3417 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
3428 | 3418 |
3429 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3419 EXPECT_EQ(1u, dialog_manager.reset_count()); |
3430 | 3420 |
3431 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3421 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
3432 } | 3422 } |
3433 | 3423 |
3434 } // namespace content | 3424 } // namespace content |
OLD | NEW |