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

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

Issue 1215713021: Reverted the code for the non-interactive audible tab notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notification
Patch Set: Fixed indent Created 5 years, 3 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/frame_host/render_frame_proxy_host.h" 12 #include "content/browser/frame_host/render_frame_proxy_host.h"
13 #include "content/browser/media/audio_state_provider.h" 13 #include "content/browser/media/audio_stream_monitor.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h" 14 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
16 #include "content/browser/webui/content_web_ui_controller_factory.h" 16 #include "content/browser/webui/content_web_ui_controller_factory.h"
17 #include "content/browser/webui/web_ui_controller_factory_registry.h" 17 #include "content/browser/webui/web_ui_controller_factory_registry.h"
18 #include "content/common/frame_messages.h" 18 #include "content/common/frame_messages.h"
19 #include "content/common/input/synthetic_web_input_event_builders.h" 19 #include "content/common/input/synthetic_web_input_event_builders.h"
20 #include "content/common/site_isolation_policy.h" 20 #include "content/common/site_isolation_policy.h"
21 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
22 #include "content/public/browser/global_request_id.h" 22 #include "content/public/browser/global_request_id.h"
23 #include "content/public/browser/interstitial_page_delegate.h" 23 #include "content/public/browser/interstitial_page_delegate.h"
(...skipping 3140 matching lines...) Expand 10 before | Expand all | Expand 10 after
3164 // and positive player ids don't blow up. 3164 // and positive player ids don't blow up.
3165 const int kPlayerAudioVideoId = 15; 3165 const int kPlayerAudioVideoId = 15;
3166 const int kPlayerAudioOnlyId = -15; 3166 const int kPlayerAudioOnlyId = -15;
3167 const int kPlayerVideoOnlyId = 30; 3167 const int kPlayerVideoOnlyId = 30;
3168 const int kPlayerRemoteId = -30; 3168 const int kPlayerRemoteId = -30;
3169 3169
3170 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3170 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3171 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3171 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3172 3172
3173 TestRenderFrameHost* rfh = contents()->GetMainFrame(); 3173 TestRenderFrameHost* rfh = contents()->GetMainFrame();
3174 AudioStateProvider* audio_state = contents()->audio_state_provider(); 3174 AudioStreamMonitor* monitor = contents()->audio_stream_monitor();
3175 3175
3176 // Ensure RenderFrame is initialized before simulating events coming from it. 3176 // Ensure RenderFrame is initialized before simulating events coming from it.
3177 main_test_rfh()->InitializeRenderFrameIfNeeded(); 3177 main_test_rfh()->InitializeRenderFrameIfNeeded();
3178 3178
3179 // The audio power save blocker should not be based on having a media player 3179 // The audio power save blocker should not be based on having a media player
3180 // when audio stream monitoring is available. 3180 // when audio stream monitoring is available.
3181 if (audio_state->IsAudioStateAvailable()) { 3181 if (AudioStreamMonitor::monitoring_available()) {
3182 // Send a fake audio stream monitor notification. The audio power save 3182 // Send a fake audio stream monitor notification. The audio power save
3183 // blocker should be created. 3183 // blocker should be created.
3184 audio_state->set_was_recently_audible_for_testing(true); 3184 monitor->set_was_recently_audible_for_testing(true);
3185 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 3185 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
3186 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing()); 3186 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing());
3187 3187
3188 // Send another fake notification, this time when WasRecentlyAudible() will 3188 // Send another fake notification, this time when WasRecentlyAudible() will
3189 // be false. The power save blocker should be released. 3189 // be false. The power save blocker should be released.
3190 audio_state->set_was_recently_audible_for_testing(false); 3190 monitor->set_was_recently_audible_for_testing(false);
3191 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 3191 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
3192 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3192 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3193 } 3193 }
3194 3194
3195 // Start a player with both audio and video. A video power save blocker 3195 // Start a player with both audio and video. A video power save blocker
3196 // should be created. If audio stream monitoring is available, an audio power 3196 // should be created. If audio stream monitoring is available, an audio power
3197 // save blocker should be created too. 3197 // save blocker should be created too.
3198 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3198 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
3199 0, kPlayerAudioVideoId, true, true, false)); 3199 0, kPlayerAudioVideoId, true, true, false));
3200 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3200 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3201 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3201 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3202 !audio_state->IsAudioStateAvailable()); 3202 !AudioStreamMonitor::monitoring_available());
3203 3203
3204 // Upon hiding the video power save blocker should be released. 3204 // Upon hiding the video power save blocker should be released.
3205 contents()->WasHidden(); 3205 contents()->WasHidden();
3206 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3206 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3207 3207
3208 // Start another player that only has video. There should be no change in 3208 // Start another player that only has video. There should be no change in
3209 // the power save blockers. The notification should take into account the 3209 // the power save blockers. The notification should take into account the
3210 // visibility state of the WebContents. 3210 // visibility state of the WebContents.
3211 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3211 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
3212 0, kPlayerVideoOnlyId, true, false, false)); 3212 0, kPlayerVideoOnlyId, true, false, false));
3213 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3213 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3214 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3214 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3215 !audio_state->IsAudioStateAvailable()); 3215 !AudioStreamMonitor::monitoring_available());
3216 3216
3217 // Showing the WebContents should result in the creation of the blocker. 3217 // Showing the WebContents should result in the creation of the blocker.
3218 contents()->WasShown(); 3218 contents()->WasShown();
3219 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3219 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3220 3220
3221 // Start another player that only has audio. There should be no change in 3221 // Start another player that only has audio. There should be no change in
3222 // the power save blockers. 3222 // the power save blockers.
3223 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3223 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
3224 0, kPlayerAudioOnlyId, false, true, false)); 3224 0, kPlayerAudioOnlyId, false, true, false));
3225 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3225 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3226 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3226 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3227 !audio_state->IsAudioStateAvailable()); 3227 !AudioStreamMonitor::monitoring_available());
3228 3228
3229 // Start a remote player. There should be no change in the power save 3229 // Start a remote player. There should be no change in the power save
3230 // blockers. 3230 // blockers.
3231 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3231 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
3232 0, kPlayerRemoteId, true, true, true)); 3232 0, kPlayerRemoteId, true, true, true));
3233 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3233 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3234 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3234 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3235 !audio_state->IsAudioStateAvailable()); 3235 !AudioStreamMonitor::monitoring_available());
3236 3236
3237 // Destroy the original audio video player. Both power save blockers should 3237 // Destroy the original audio video player. Both power save blockers should
3238 // remain. 3238 // remain.
3239 rfh->OnMessageReceived( 3239 rfh->OnMessageReceived(
3240 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); 3240 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId));
3241 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3241 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3242 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3242 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3243 !audio_state->IsAudioStateAvailable()); 3243 !AudioStreamMonitor::monitoring_available());
3244 3244
3245 // Destroy the audio only player. The video power save blocker should remain. 3245 // Destroy the audio only player. The video power save blocker should remain.
3246 rfh->OnMessageReceived( 3246 rfh->OnMessageReceived(
3247 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); 3247 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId));
3248 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3248 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3249 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3249 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3250 3250
3251 // Destroy the video only player. No power save blockers should remain. 3251 // Destroy the video only player. No power save blockers should remain.
3252 rfh->OnMessageReceived( 3252 rfh->OnMessageReceived(
3253 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); 3253 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId));
3254 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3254 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3255 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3255 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3256 3256
3257 // Destroy the remote player. No power save blockers should remain. 3257 // Destroy the remote player. No power save blockers should remain.
3258 rfh->OnMessageReceived( 3258 rfh->OnMessageReceived(
3259 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 3259 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId));
3260 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3260 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3261 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3261 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3262 3262
3263 // Start a player with both audio and video. A video power save blocker 3263 // Start a player with both audio and video. A video power save blocker
3264 // should be created. If audio stream monitoring is available, an audio power 3264 // should be created. If audio stream monitoring is available, an audio power
3265 // save blocker should be created too. 3265 // save blocker should be created too.
3266 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( 3266 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
3267 0, kPlayerAudioVideoId, true, true, false)); 3267 0, kPlayerAudioVideoId, true, true, false));
3268 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); 3268 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
3269 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), 3269 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
3270 !audio_state->IsAudioStateAvailable()); 3270 !AudioStreamMonitor::monitoring_available());
3271 3271
3272 // Crash the renderer. 3272 // Crash the renderer.
3273 contents()->GetMainFrame()->GetProcess()->SimulateCrash(); 3273 contents()->GetMainFrame()->GetProcess()->SimulateCrash();
3274 3274
3275 // Verify that all the power save blockers have been released. 3275 // Verify that all the power save blockers have been released.
3276 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3276 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3277 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3277 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3278 } 3278 }
3279 3279
3280 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) { 3280 TEST_F(WebContentsImplTest, ThemeColorChangeDependingOnFirstVisiblePaint) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 MockRenderProcessHost* rph = contents()->GetMainFrame()->GetProcess(); 3320 MockRenderProcessHost* rph = contents()->GetMainFrame()->GetProcess();
3321 EXPECT_EQ(0, rph->bad_msg_count()); 3321 EXPECT_EQ(0, rph->bad_msg_count());
3322 3322
3323 contents()->OnDidLoadResourceFromMemoryCache( 3323 contents()->OnDidLoadResourceFromMemoryCache(
3324 GURL("http://example.test"), "not valid security info", "GET", 3324 GURL("http://example.test"), "not valid security info", "GET",
3325 "mime type", RESOURCE_TYPE_MAIN_FRAME); 3325 "mime type", RESOURCE_TYPE_MAIN_FRAME);
3326 EXPECT_EQ(1, rph->bad_msg_count()); 3326 EXPECT_EQ(1, rph->bad_msg_count());
3327 } 3327 }
3328 3328
3329 } // namespace content 3329 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698