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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 WebUIControllerFactory::RegisterFactory( | 250 WebUIControllerFactory::RegisterFactory( |
251 ContentWebUIControllerFactory::GetInstance()); | 251 ContentWebUIControllerFactory::GetInstance()); |
252 } | 252 } |
253 | 253 |
254 void TearDown() override { | 254 void TearDown() override { |
255 WebUIControllerFactory::UnregisterFactoryForTesting( | 255 WebUIControllerFactory::UnregisterFactoryForTesting( |
256 ContentWebUIControllerFactory::GetInstance()); | 256 ContentWebUIControllerFactory::GetInstance()); |
257 RenderViewHostImplTestHarness::TearDown(); | 257 RenderViewHostImplTestHarness::TearDown(); |
258 } | 258 } |
259 | 259 |
260 bool has_audio_power_save_blocker() { | 260 bool has_audio_wake_lock() { |
261 return contents() | 261 return contents() |
262 ->media_web_contents_observer() | 262 ->media_web_contents_observer() |
263 ->has_audio_power_save_blocker_for_testing(); | 263 ->has_audio_wake_lock_for_testing(); |
264 } | 264 } |
265 | 265 |
266 bool has_video_power_save_blocker() { | 266 bool has_video_wake_lock() { |
267 return contents() | 267 return contents() |
268 ->media_web_contents_observer() | 268 ->media_web_contents_observer() |
269 ->has_video_power_save_blocker_for_testing(); | 269 ->has_video_wake_lock_for_testing(); |
270 } | 270 } |
271 }; | 271 }; |
272 | 272 |
273 class TestWebContentsObserver : public WebContentsObserver { | 273 class TestWebContentsObserver : public WebContentsObserver { |
274 public: | 274 public: |
275 explicit TestWebContentsObserver(WebContents* contents) | 275 explicit TestWebContentsObserver(WebContents* contents) |
276 : WebContentsObserver(contents), | 276 : WebContentsObserver(contents), |
277 last_theme_color_(SK_ColorTRANSPARENT) { | 277 last_theme_color_(SK_ColorTRANSPARENT) { |
278 } | 278 } |
279 ~TestWebContentsObserver() override {} | 279 ~TestWebContentsObserver() override {} |
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3207 EXPECT_EQ(3, controller().GetEntryCount()); | 3207 EXPECT_EQ(3, controller().GetEntryCount()); |
3208 | 3208 |
3209 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents | 3209 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents |
3210 // should now have stopped loading. | 3210 // should now have stopped loading. |
3211 new_current_rfh->OnMessageReceived( | 3211 new_current_rfh->OnMessageReceived( |
3212 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID())); | 3212 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID())); |
3213 EXPECT_EQ(main_test_rfh(), new_current_rfh); | 3213 EXPECT_EQ(main_test_rfh(), new_current_rfh); |
3214 EXPECT_FALSE(contents()->IsLoading()); | 3214 EXPECT_FALSE(contents()->IsLoading()); |
3215 } | 3215 } |
3216 | 3216 |
3217 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { | 3217 TEST_F(WebContentsImplTest, MediaWakeLock) { |
3218 // Verify that both negative and positive player ids don't blow up. | 3218 // Verify that both negative and positive player ids don't blow up. |
3219 const int kPlayerAudioVideoId = 15; | 3219 const int kPlayerAudioVideoId = 15; |
3220 const int kPlayerAudioOnlyId = -15; | 3220 const int kPlayerAudioOnlyId = -15; |
3221 const int kPlayerVideoOnlyId = 30; | 3221 const int kPlayerVideoOnlyId = 30; |
3222 const int kPlayerRemoteId = -30; | 3222 const int kPlayerRemoteId = -30; |
3223 | 3223 |
3224 EXPECT_FALSE(has_audio_power_save_blocker()); | 3224 EXPECT_FALSE(has_audio_wake_lock()); |
3225 EXPECT_FALSE(has_video_power_save_blocker()); | 3225 EXPECT_FALSE(has_video_wake_lock()); |
3226 | 3226 |
3227 TestRenderFrameHost* rfh = main_test_rfh(); | 3227 TestRenderFrameHost* rfh = main_test_rfh(); |
3228 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); | 3228 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); |
3229 | 3229 |
3230 // Ensure RenderFrame is initialized before simulating events coming from it. | 3230 // Ensure RenderFrame is initialized before simulating events coming from it. |
3231 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 3231 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
3232 | 3232 |
3233 // Send a fake audio stream monitor notification. The audio power save | 3233 // Send a fake audio stream monitor notification. The audio wake lock |
3234 // blocker should be created. | 3234 // should be created. |
3235 monitor->set_was_recently_audible_for_testing(true); | 3235 monitor->set_was_recently_audible_for_testing(true); |
3236 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 3236 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
3237 EXPECT_TRUE(has_audio_power_save_blocker()); | 3237 EXPECT_TRUE(has_audio_wake_lock()); |
3238 | 3238 |
3239 // Send another fake notification, this time when WasRecentlyAudible() will | 3239 // Send another fake notification, this time when WasRecentlyAudible() will |
3240 // be false. The power save blocker should be released. | 3240 // be false. The wake lock should be released. |
3241 monitor->set_was_recently_audible_for_testing(false); | 3241 monitor->set_was_recently_audible_for_testing(false); |
3242 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 3242 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
3243 EXPECT_FALSE(has_audio_power_save_blocker()); | 3243 EXPECT_FALSE(has_audio_wake_lock()); |
3244 | 3244 |
3245 // Start a player with both audio and video. A video power save blocker | 3245 // Start a player with both audio and video. A video wake lock |
3246 // should be created. If audio stream monitoring is available, an audio power | 3246 // should be created. If audio stream monitoring is available, an audio power |
3247 // save blocker should be created too. | 3247 // save blocker should be created too. |
3248 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3248 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3249 0, kPlayerAudioVideoId, true, true, false, | 3249 0, kPlayerAudioVideoId, true, true, false, |
3250 media::MediaContentType::Persistent)); | 3250 media::MediaContentType::Persistent)); |
3251 EXPECT_TRUE(has_video_power_save_blocker()); | 3251 EXPECT_TRUE(has_video_wake_lock()); |
3252 EXPECT_FALSE(has_audio_power_save_blocker()); | 3252 EXPECT_FALSE(has_audio_wake_lock()); |
3253 | 3253 |
3254 // Upon hiding the video power save blocker should be released. | 3254 // Upon hiding the video wake lock should be released. |
3255 contents()->WasHidden(); | 3255 contents()->WasHidden(); |
3256 EXPECT_FALSE(has_video_power_save_blocker()); | 3256 EXPECT_FALSE(has_video_wake_lock()); |
3257 | 3257 |
3258 // Start another player that only has video. There should be no change in | 3258 // Start another player that only has video. There should be no change in |
3259 // the power save blockers. The notification should take into account the | 3259 // the wake locks. The notification should take into account the |
3260 // visibility state of the WebContents. | 3260 // visibility state of the WebContents. |
3261 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3261 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3262 0, kPlayerVideoOnlyId, true, false, false, | 3262 0, kPlayerVideoOnlyId, true, false, false, |
3263 media::MediaContentType::Persistent)); | 3263 media::MediaContentType::Persistent)); |
3264 EXPECT_FALSE(has_video_power_save_blocker()); | 3264 EXPECT_FALSE(has_video_wake_lock()); |
3265 EXPECT_FALSE(has_audio_power_save_blocker()); | 3265 EXPECT_FALSE(has_audio_wake_lock()); |
3266 | 3266 |
3267 // Showing the WebContents should result in the creation of the blocker. | 3267 // Showing the WebContents should result in the creation of the blocker. |
3268 contents()->WasShown(); | 3268 contents()->WasShown(); |
3269 EXPECT_TRUE(has_video_power_save_blocker()); | 3269 EXPECT_TRUE(has_video_wake_lock()); |
3270 | 3270 |
3271 // Start another player that only has audio. There should be no change in | 3271 // Start another player that only has audio. There should be no change in |
3272 // the power save blockers. | 3272 // the wake locks. |
3273 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3273 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3274 0, kPlayerAudioOnlyId, false, true, false, | 3274 0, kPlayerAudioOnlyId, false, true, false, |
3275 media::MediaContentType::Persistent)); | 3275 media::MediaContentType::Persistent)); |
3276 EXPECT_TRUE(has_video_power_save_blocker()); | 3276 EXPECT_TRUE(has_video_wake_lock()); |
3277 EXPECT_FALSE(has_audio_power_save_blocker()); | 3277 EXPECT_FALSE(has_audio_wake_lock()); |
3278 | 3278 |
3279 // Start a remote player. There should be no change in the power save | 3279 // Start a remote player. There should be no change in the power save |
3280 // blockers. | 3280 // blockers. |
3281 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3281 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3282 0, kPlayerRemoteId, true, true, true, | 3282 0, kPlayerRemoteId, true, true, true, |
3283 media::MediaContentType::Persistent)); | 3283 media::MediaContentType::Persistent)); |
3284 EXPECT_TRUE(has_video_power_save_blocker()); | 3284 EXPECT_TRUE(has_video_wake_lock()); |
3285 EXPECT_FALSE(has_audio_power_save_blocker()); | 3285 EXPECT_FALSE(has_audio_wake_lock()); |
3286 | 3286 |
3287 // Destroy the original audio video player. Both power save blockers should | 3287 // Destroy the original audio video player. Both wake locks should |
3288 // remain. | 3288 // remain. |
3289 rfh->OnMessageReceived( | 3289 rfh->OnMessageReceived( |
3290 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioVideoId, false)); | 3290 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioVideoId, false)); |
3291 EXPECT_TRUE(has_video_power_save_blocker()); | 3291 EXPECT_TRUE(has_video_wake_lock()); |
3292 EXPECT_FALSE(has_audio_power_save_blocker()); | 3292 EXPECT_FALSE(has_audio_wake_lock()); |
3293 | 3293 |
3294 // Destroy the audio only player. The video power save blocker should remain. | 3294 // Destroy the audio only player. The video wake lock should remain. |
3295 rfh->OnMessageReceived( | 3295 rfh->OnMessageReceived( |
3296 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioOnlyId, false)); | 3296 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerAudioOnlyId, false)); |
3297 EXPECT_TRUE(has_video_power_save_blocker()); | 3297 EXPECT_TRUE(has_video_wake_lock()); |
3298 EXPECT_FALSE(has_audio_power_save_blocker()); | 3298 EXPECT_FALSE(has_audio_wake_lock()); |
3299 | 3299 |
3300 // Destroy the video only player. No power save blockers should remain. | 3300 // Destroy the video only player. No wake locks should remain. |
3301 rfh->OnMessageReceived( | 3301 rfh->OnMessageReceived( |
3302 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerVideoOnlyId, false)); | 3302 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerVideoOnlyId, false)); |
3303 EXPECT_FALSE(has_video_power_save_blocker()); | 3303 EXPECT_FALSE(has_video_wake_lock()); |
3304 EXPECT_FALSE(has_audio_power_save_blocker()); | 3304 EXPECT_FALSE(has_audio_wake_lock()); |
3305 | 3305 |
3306 // Destroy the remote player. No power save blockers should remain. | 3306 // Destroy the remote player. No wake locks should remain. |
3307 rfh->OnMessageReceived( | 3307 rfh->OnMessageReceived( |
3308 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerRemoteId, false)); | 3308 MediaPlayerDelegateHostMsg_OnMediaPaused(0, kPlayerRemoteId, false)); |
3309 EXPECT_FALSE(has_video_power_save_blocker()); | 3309 EXPECT_FALSE(has_video_wake_lock()); |
3310 EXPECT_FALSE(has_audio_power_save_blocker()); | 3310 EXPECT_FALSE(has_audio_wake_lock()); |
3311 | 3311 |
3312 // Start a player with both audio and video. A video power save blocker | 3312 // Start a player with both audio and video. A video wake lock |
3313 // should be created. If audio stream monitoring is available, an audio power | 3313 // should be created. If audio stream monitoring is available, an audio power |
3314 // save blocker should be created too. | 3314 // save blocker should be created too. |
3315 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( | 3315 rfh->OnMessageReceived(MediaPlayerDelegateHostMsg_OnMediaPlaying( |
3316 0, kPlayerAudioVideoId, true, true, false, | 3316 0, kPlayerAudioVideoId, true, true, false, |
3317 media::MediaContentType::Persistent)); | 3317 media::MediaContentType::Persistent)); |
3318 EXPECT_TRUE(has_video_power_save_blocker()); | 3318 EXPECT_TRUE(has_video_wake_lock()); |
3319 EXPECT_FALSE(has_audio_power_save_blocker()); | 3319 EXPECT_FALSE(has_audio_wake_lock()); |
3320 | 3320 |
3321 // Crash the renderer. | 3321 // Crash the renderer. |
3322 main_test_rfh()->GetProcess()->SimulateCrash(); | 3322 main_test_rfh()->GetProcess()->SimulateCrash(); |
3323 | 3323 |
3324 // Verify that all the power save blockers have been released. | 3324 // Verify that all the wake locks have been released. |
3325 EXPECT_FALSE(has_video_power_save_blocker()); | 3325 EXPECT_FALSE(has_video_wake_lock()); |
3326 EXPECT_FALSE(has_audio_power_save_blocker()); | 3326 EXPECT_FALSE(has_audio_wake_lock()); |
3327 } | 3327 } |
3328 | 3328 |
3329 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { | 3329 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { |
3330 TestWebContentsObserver observer(contents()); | 3330 TestWebContentsObserver observer(contents()); |
3331 TestRenderFrameHost* rfh = main_test_rfh(); | 3331 TestRenderFrameHost* rfh = main_test_rfh(); |
3332 rfh->InitializeRenderFrameIfNeeded(); | 3332 rfh->InitializeRenderFrameIfNeeded(); |
3333 | 3333 |
3334 SkColor transparent = SK_ColorTRANSPARENT; | 3334 SkColor transparent = SK_ColorTRANSPARENT; |
3335 | 3335 |
3336 EXPECT_EQ(transparent, contents()->GetThemeColor()); | 3336 EXPECT_EQ(transparent, contents()->GetThemeColor()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3443 // An automatic navigation. | 3443 // An automatic navigation. |
3444 main_test_rfh()->SendNavigateWithModificationCallback( | 3444 main_test_rfh()->SendNavigateWithModificationCallback( |
3445 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3445 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
3446 | 3446 |
3447 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3447 EXPECT_EQ(1u, dialog_manager.reset_count()); |
3448 | 3448 |
3449 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3449 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
3450 } | 3450 } |
3451 | 3451 |
3452 } // namespace content | 3452 } // namespace content |
OLD | NEW |