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

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

Issue 478543003: Use AudioStreamMonitor to control power save blocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 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 | Annotate | Revision Log
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/logging.h" 5 #include "base/logging.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/frame_host/cross_site_transferring_request.h" 7 #include "content/browser/frame_host/cross_site_transferring_request.h"
8 #include "content/browser/frame_host/interstitial_page_impl.h" 8 #include "content/browser/frame_host/interstitial_page_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/media/audio_stream_monitor.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 11 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/browser/site_instance_impl.h" 12 #include "content/browser/site_instance_impl.h"
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" 13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
13 #include "content/common/frame_messages.h" 14 #include "content/common/frame_messages.h"
14 #include "content/common/input/synthetic_web_input_event_builders.h" 15 #include "content/common/input/synthetic_web_input_event_builders.h"
15 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
16 #include "content/public/browser/global_request_id.h" 17 #include "content/public/browser/global_request_id.h"
17 #include "content/public/browser/interstitial_page_delegate.h" 18 #include "content/public/browser/interstitial_page_delegate.h"
18 #include "content/public/browser/navigation_details.h" 19 #include "content/public/browser/navigation_details.h"
19 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
(...skipping 2658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 // Commit and contents counts for the new one. 2679 // Commit and contents counts for the new one.
2679 contents->CommitPendingNavigation(); 2680 contents->CommitPendingNavigation();
2680 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2681 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2681 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); 2682 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount());
2682 2683
2683 contents.reset(); 2684 contents.reset();
2684 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2685 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2685 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); 2686 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount());
2686 } 2687 }
2687 2688
2689 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
2690 // PlayerIDs are actually pointers cast to int64, so verify that both negative
2691 // and positive player ids don't blow up.
2692 const int kPlayerAudioVideoId = 15;
2693 const int kPlayerAudioOnlyId = -15;
2694 const int kPlayerVideoOnlyId = 30;
2695
2696 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2697 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2698
2699 TestRenderFrameHost* rfh = contents()->GetMainFrame();
2700 AudioStreamMonitor::CreateForWebContents(contents());
2701 AudioStreamMonitor* monitor = AudioStreamMonitor::FromWebContents(contents());
2702
2703 // The audio power save blocker should not be based on having a media player
2704 // when audio stream monitoring is available.
2705 if (AudioStreamMonitor::monitoring_available()) {
2706 // Send a fake audio stream monitor notification. The audio power save
2707 // blocker should be created.
2708 monitor->set_was_recently_audible_for_testing(true);
2709 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
2710 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing());
2711
2712 // Send another fake notification, this time when WasRecentlyAudible() will
2713 // be false. The power save blocker should be released.
2714 monitor->set_was_recently_audible_for_testing(false);
2715 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
2716 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2717 }
2718
2719 // Start a player with both audio and video. A video power save blocker
2720 // should be created. If audio stream monitoring is available, an audio power
2721 // save blocker should be created too.
2722 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2723 0, kPlayerAudioVideoId, true, true));
2724 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2725 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2726 !AudioStreamMonitor::monitoring_available());
2727
2728 // Upon hiding the video power save blocker should be released.
2729 contents()->WasHidden();
2730 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2731
2732 // Start another player that only has video. There should be no change in
2733 // the power save blockers. The notification should take into account the
2734 // visibility state of the WebContents.
2735 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2736 0, kPlayerVideoOnlyId, true, false));
2737 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2738 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2739 !AudioStreamMonitor::monitoring_available());
2740
2741 // Showing the WebContents should result in the creation of the blocker.
2742 contents()->WasShown();
2743 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2744
2745 // Start another player that only has audio. There should be no change in
2746 // the power save blockers.
2747 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification(
2748 0, kPlayerAudioOnlyId, false, true));
2749 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2750 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2751 !AudioStreamMonitor::monitoring_available());
2752
2753 // Destroy the original audio video player. Both power save blockers should
2754 // remain.
2755 rfh->OnMessageReceived(
2756 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId));
2757 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2758 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(),
2759 !AudioStreamMonitor::monitoring_available());
2760
2761 // Destroy the audio only player. The video power save blocker should remain.
2762 rfh->OnMessageReceived(
2763 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId));
2764 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing());
2765 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2766
2767 // Destroy the video only player. No power save blockers should remain.
2768 rfh->OnMessageReceived(
2769 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId));
2770 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2771 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2772 }
2773
2688 } // namespace content 2774 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698