| 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 "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/frame_host/render_frame_proxy_host.h" | 12 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 13 #include "content/browser/media/audio_stream_monitor.h" | 13 #include "content/browser/media/audio_stream_monitor.h" |
| 14 #include "content/browser/media/media_web_contents_observer.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/site_instance_impl.h" | 16 #include "content/browser/site_instance_impl.h" |
| 16 #include "content/browser/webui/content_web_ui_controller_factory.h" | 17 #include "content/browser/webui/content_web_ui_controller_factory.h" |
| 17 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 18 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 18 #include "content/common/frame_messages.h" | 19 #include "content/common/frame_messages.h" |
| 19 #include "content/common/input/synthetic_web_input_event_builders.h" | 20 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 20 #include "content/common/site_isolation_policy.h" | 21 #include "content/common/site_isolation_policy.h" |
| 21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 22 #include "content/public/browser/global_request_id.h" | 23 #include "content/public/browser/global_request_id.h" |
| 23 #include "content/public/browser/interstitial_page_delegate.h" | 24 #include "content/public/browser/interstitial_page_delegate.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 RenderViewHostImplTestHarness::SetUp(); | 239 RenderViewHostImplTestHarness::SetUp(); |
| 239 WebUIControllerFactory::RegisterFactory( | 240 WebUIControllerFactory::RegisterFactory( |
| 240 ContentWebUIControllerFactory::GetInstance()); | 241 ContentWebUIControllerFactory::GetInstance()); |
| 241 } | 242 } |
| 242 | 243 |
| 243 void TearDown() override { | 244 void TearDown() override { |
| 244 WebUIControllerFactory::UnregisterFactoryForTesting( | 245 WebUIControllerFactory::UnregisterFactoryForTesting( |
| 245 ContentWebUIControllerFactory::GetInstance()); | 246 ContentWebUIControllerFactory::GetInstance()); |
| 246 RenderViewHostImplTestHarness::TearDown(); | 247 RenderViewHostImplTestHarness::TearDown(); |
| 247 } | 248 } |
| 249 |
| 250 bool has_audio_power_save_blocker() { |
| 251 return contents() |
| 252 ->media_web_contents_observer() |
| 253 ->has_audio_power_save_blocker_for_testing(); |
| 254 } |
| 255 |
| 256 bool has_video_power_save_blocker() { |
| 257 return contents() |
| 258 ->media_web_contents_observer() |
| 259 ->has_video_power_save_blocker_for_testing(); |
| 260 } |
| 248 }; | 261 }; |
| 249 | 262 |
| 250 class TestWebContentsObserver : public WebContentsObserver { | 263 class TestWebContentsObserver : public WebContentsObserver { |
| 251 public: | 264 public: |
| 252 explicit TestWebContentsObserver(WebContents* contents) | 265 explicit TestWebContentsObserver(WebContents* contents) |
| 253 : WebContentsObserver(contents), | 266 : WebContentsObserver(contents), |
| 254 last_theme_color_(SK_ColorTRANSPARENT) { | 267 last_theme_color_(SK_ColorTRANSPARENT) { |
| 255 } | 268 } |
| 256 ~TestWebContentsObserver() override {} | 269 ~TestWebContentsObserver() override {} |
| 257 | 270 |
| (...skipping 2930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3188 } | 3201 } |
| 3189 | 3202 |
| 3190 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { | 3203 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { |
| 3191 // PlayerIDs are actually pointers cast to int64, so verify that both negative | 3204 // PlayerIDs are actually pointers cast to int64, so verify that both negative |
| 3192 // and positive player ids don't blow up. | 3205 // and positive player ids don't blow up. |
| 3193 const int kPlayerAudioVideoId = 15; | 3206 const int kPlayerAudioVideoId = 15; |
| 3194 const int kPlayerAudioOnlyId = -15; | 3207 const int kPlayerAudioOnlyId = -15; |
| 3195 const int kPlayerVideoOnlyId = 30; | 3208 const int kPlayerVideoOnlyId = 30; |
| 3196 const int kPlayerRemoteId = -30; | 3209 const int kPlayerRemoteId = -30; |
| 3197 | 3210 |
| 3198 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3211 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3199 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3212 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3200 | 3213 |
| 3201 TestRenderFrameHost* rfh = contents()->GetMainFrame(); | 3214 TestRenderFrameHost* rfh = contents()->GetMainFrame(); |
| 3202 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); | 3215 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); |
| 3203 | 3216 |
| 3204 // Ensure RenderFrame is initialized before simulating events coming from it. | 3217 // Ensure RenderFrame is initialized before simulating events coming from it. |
| 3205 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 3218 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 3206 | 3219 |
| 3207 // The audio power save blocker should not be based on having a media player | 3220 // The audio power save blocker should not be based on having a media player |
| 3208 // when audio stream monitoring is available. | 3221 // when audio stream monitoring is available. |
| 3209 if (AudioStreamMonitor::monitoring_available()) { | 3222 if (AudioStreamMonitor::monitoring_available()) { |
| 3210 // Send a fake audio stream monitor notification. The audio power save | 3223 // Send a fake audio stream monitor notification. The audio power save |
| 3211 // blocker should be created. | 3224 // blocker should be created. |
| 3212 monitor->set_was_recently_audible_for_testing(true); | 3225 monitor->set_was_recently_audible_for_testing(true); |
| 3213 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 3226 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 3214 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing()); | 3227 EXPECT_TRUE(has_audio_power_save_blocker()); |
| 3215 | 3228 |
| 3216 // Send another fake notification, this time when WasRecentlyAudible() will | 3229 // Send another fake notification, this time when WasRecentlyAudible() will |
| 3217 // be false. The power save blocker should be released. | 3230 // be false. The power save blocker should be released. |
| 3218 monitor->set_was_recently_audible_for_testing(false); | 3231 monitor->set_was_recently_audible_for_testing(false); |
| 3219 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 3232 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 3220 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3233 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3221 } | 3234 } |
| 3222 | 3235 |
| 3223 // Start a player with both audio and video. A video power save blocker | 3236 // Start a player with both audio and video. A video power save blocker |
| 3224 // should be created. If audio stream monitoring is available, an audio power | 3237 // should be created. If audio stream monitoring is available, an audio power |
| 3225 // save blocker should be created too. | 3238 // save blocker should be created too. |
| 3226 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 3239 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 3227 0, kPlayerAudioVideoId, true, true, false)); | 3240 0, kPlayerAudioVideoId, true, true, false)); |
| 3228 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3241 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3229 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3242 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3230 !AudioStreamMonitor::monitoring_available()); | 3243 !AudioStreamMonitor::monitoring_available()); |
| 3231 | 3244 |
| 3232 // Upon hiding the video power save blocker should be released. | 3245 // Upon hiding the video power save blocker should be released. |
| 3233 contents()->WasHidden(); | 3246 contents()->WasHidden(); |
| 3234 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3247 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3235 | 3248 |
| 3236 // Start another player that only has video. There should be no change in | 3249 // Start another player that only has video. There should be no change in |
| 3237 // the power save blockers. The notification should take into account the | 3250 // the power save blockers. The notification should take into account the |
| 3238 // visibility state of the WebContents. | 3251 // visibility state of the WebContents. |
| 3239 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 3252 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 3240 0, kPlayerVideoOnlyId, true, false, false)); | 3253 0, kPlayerVideoOnlyId, true, false, false)); |
| 3241 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3254 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3242 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3255 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3243 !AudioStreamMonitor::monitoring_available()); | 3256 !AudioStreamMonitor::monitoring_available()); |
| 3244 | 3257 |
| 3245 // Showing the WebContents should result in the creation of the blocker. | 3258 // Showing the WebContents should result in the creation of the blocker. |
| 3246 contents()->WasShown(); | 3259 contents()->WasShown(); |
| 3247 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3260 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3248 | 3261 |
| 3249 // Start another player that only has audio. There should be no change in | 3262 // Start another player that only has audio. There should be no change in |
| 3250 // the power save blockers. | 3263 // the power save blockers. |
| 3251 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 3264 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 3252 0, kPlayerAudioOnlyId, false, true, false)); | 3265 0, kPlayerAudioOnlyId, false, true, false)); |
| 3253 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3266 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3254 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3267 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3255 !AudioStreamMonitor::monitoring_available()); | 3268 !AudioStreamMonitor::monitoring_available()); |
| 3256 | 3269 |
| 3257 // Start a remote player. There should be no change in the power save | 3270 // Start a remote player. There should be no change in the power save |
| 3258 // blockers. | 3271 // blockers. |
| 3259 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 3272 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 3260 0, kPlayerRemoteId, true, true, true)); | 3273 0, kPlayerRemoteId, true, true, true)); |
| 3261 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3274 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3262 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3275 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3263 !AudioStreamMonitor::monitoring_available()); | 3276 !AudioStreamMonitor::monitoring_available()); |
| 3264 | 3277 |
| 3265 // Destroy the original audio video player. Both power save blockers should | 3278 // Destroy the original audio video player. Both power save blockers should |
| 3266 // remain. | 3279 // remain. |
| 3267 rfh->OnMessageReceived( | 3280 rfh->OnMessageReceived( |
| 3268 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); | 3281 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); |
| 3269 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3282 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3270 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3283 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3271 !AudioStreamMonitor::monitoring_available()); | 3284 !AudioStreamMonitor::monitoring_available()); |
| 3272 | 3285 |
| 3273 // Destroy the audio only player. The video power save blocker should remain. | 3286 // Destroy the audio only player. The video power save blocker should remain. |
| 3274 rfh->OnMessageReceived( | 3287 rfh->OnMessageReceived( |
| 3275 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); | 3288 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); |
| 3276 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3289 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3277 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3290 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3278 | 3291 |
| 3279 // Destroy the video only player. No power save blockers should remain. | 3292 // Destroy the video only player. No power save blockers should remain. |
| 3280 rfh->OnMessageReceived( | 3293 rfh->OnMessageReceived( |
| 3281 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); | 3294 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); |
| 3282 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3295 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3283 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3296 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3284 | 3297 |
| 3285 // Destroy the remote player. No power save blockers should remain. | 3298 // Destroy the remote player. No power save blockers should remain. |
| 3286 rfh->OnMessageReceived( | 3299 rfh->OnMessageReceived( |
| 3287 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); | 3300 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); |
| 3288 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3301 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3289 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3302 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3290 | 3303 |
| 3291 // Start a player with both audio and video. A video power save blocker | 3304 // Start a player with both audio and video. A video power save blocker |
| 3292 // should be created. If audio stream monitoring is available, an audio power | 3305 // should be created. If audio stream monitoring is available, an audio power |
| 3293 // save blocker should be created too. | 3306 // save blocker should be created too. |
| 3294 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 3307 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 3295 0, kPlayerAudioVideoId, true, true, false)); | 3308 0, kPlayerAudioVideoId, true, true, false)); |
| 3296 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 3309 EXPECT_TRUE(has_video_power_save_blocker()); |
| 3297 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 3310 EXPECT_EQ(has_audio_power_save_blocker(), |
| 3298 !AudioStreamMonitor::monitoring_available()); | 3311 !AudioStreamMonitor::monitoring_available()); |
| 3299 | 3312 |
| 3300 // Crash the renderer. | 3313 // Crash the renderer. |
| 3301 contents()->GetMainFrame()->GetProcess()->SimulateCrash(); | 3314 contents()->GetMainFrame()->GetProcess()->SimulateCrash(); |
| 3302 | 3315 |
| 3303 // Verify that all the power save blockers have been released. | 3316 // Verify that all the power save blockers have been released. |
| 3304 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 3317 EXPECT_FALSE(has_video_power_save_blocker()); |
| 3305 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 3318 EXPECT_FALSE(has_audio_power_save_blocker()); |
| 3306 } | 3319 } |
| 3307 | 3320 |
| 3308 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { | 3321 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { |
| 3309 TestWebContentsObserver observer(contents()); | 3322 TestWebContentsObserver observer(contents()); |
| 3310 TestRenderFrameHost* rfh = contents()->GetMainFrame(); | 3323 TestRenderFrameHost* rfh = contents()->GetMainFrame(); |
| 3311 | 3324 |
| 3312 SkColor transparent = SK_ColorTRANSPARENT; | 3325 SkColor transparent = SK_ColorTRANSPARENT; |
| 3313 | 3326 |
| 3314 EXPECT_EQ(transparent, contents()->GetThemeColor()); | 3327 EXPECT_EQ(transparent, contents()->GetThemeColor()); |
| 3315 EXPECT_EQ(transparent, observer.last_theme_color()); | 3328 EXPECT_EQ(transparent, observer.last_theme_color()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3366 backend->AllowCertForHost(*cert, test_url.host(), 1); | 3379 backend->AllowCertForHost(*cert, test_url.host(), 1); |
| 3367 EXPECT_TRUE(backend->HasAllowException(test_url.host())); | 3380 EXPECT_TRUE(backend->HasAllowException(test_url.host())); |
| 3368 | 3381 |
| 3369 contents()->OnDidLoadResourceFromMemoryCache(test_url, "", "GET", "mime type", | 3382 contents()->OnDidLoadResourceFromMemoryCache(test_url, "", "GET", "mime type", |
| 3370 RESOURCE_TYPE_MAIN_FRAME); | 3383 RESOURCE_TYPE_MAIN_FRAME); |
| 3371 | 3384 |
| 3372 EXPECT_TRUE(backend->HasAllowException(test_url.host())); | 3385 EXPECT_TRUE(backend->HasAllowException(test_url.host())); |
| 3373 } | 3386 } |
| 3374 | 3387 |
| 3375 } // namespace content | 3388 } // namespace content |
| OLD | NEW |