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/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/media/audio_stream_monitor.h" |
(...skipping 2683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2694 } | 2694 } |
2695 | 2695 |
2696 // ChromeOS doesn't use WebContents based power save blocking. | 2696 // ChromeOS doesn't use WebContents based power save blocking. |
2697 #if !defined(OS_CHROMEOS) | 2697 #if !defined(OS_CHROMEOS) |
2698 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { | 2698 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { |
2699 // PlayerIDs are actually pointers cast to int64, so verify that both negative | 2699 // PlayerIDs are actually pointers cast to int64, so verify that both negative |
2700 // and positive player ids don't blow up. | 2700 // and positive player ids don't blow up. |
2701 const int kPlayerAudioVideoId = 15; | 2701 const int kPlayerAudioVideoId = 15; |
2702 const int kPlayerAudioOnlyId = -15; | 2702 const int kPlayerAudioOnlyId = -15; |
2703 const int kPlayerVideoOnlyId = 30; | 2703 const int kPlayerVideoOnlyId = 30; |
| 2704 const int kPlayerRemoteId = -30; |
2704 | 2705 |
2705 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2706 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2706 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2707 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2707 | 2708 |
2708 TestRenderFrameHost* rfh = contents()->GetMainFrame(); | 2709 TestRenderFrameHost* rfh = contents()->GetMainFrame(); |
2709 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); | 2710 AudioStreamMonitor* monitor = contents()->audio_stream_monitor(); |
2710 | 2711 |
2711 // The audio power save blocker should not be based on having a media player | 2712 // The audio power save blocker should not be based on having a media player |
2712 // when audio stream monitoring is available. | 2713 // when audio stream monitoring is available. |
2713 if (AudioStreamMonitor::monitoring_available()) { | 2714 if (AudioStreamMonitor::monitoring_available()) { |
2714 // Send a fake audio stream monitor notification. The audio power save | 2715 // Send a fake audio stream monitor notification. The audio power save |
2715 // blocker should be created. | 2716 // blocker should be created. |
2716 monitor->set_was_recently_audible_for_testing(true); | 2717 monitor->set_was_recently_audible_for_testing(true); |
2717 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 2718 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
2718 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing()); | 2719 EXPECT_TRUE(contents()->has_audio_power_save_blocker_for_testing()); |
2719 | 2720 |
2720 // Send another fake notification, this time when WasRecentlyAudible() will | 2721 // Send another fake notification, this time when WasRecentlyAudible() will |
2721 // be false. The power save blocker should be released. | 2722 // be false. The power save blocker should be released. |
2722 monitor->set_was_recently_audible_for_testing(false); | 2723 monitor->set_was_recently_audible_for_testing(false); |
2723 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 2724 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
2724 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2725 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2725 } | 2726 } |
2726 | 2727 |
2727 // Start a player with both audio and video. A video power save blocker | 2728 // Start a player with both audio and video. A video power save blocker |
2728 // should be created. If audio stream monitoring is available, an audio power | 2729 // should be created. If audio stream monitoring is available, an audio power |
2729 // save blocker should be created too. | 2730 // save blocker should be created too. |
2730 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 2731 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
2731 0, kPlayerAudioVideoId, true, true)); | 2732 0, kPlayerAudioVideoId, true, true, false)); |
2732 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 2733 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
2733 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 2734 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
2734 !AudioStreamMonitor::monitoring_available()); | 2735 !AudioStreamMonitor::monitoring_available()); |
2735 | 2736 |
2736 // Upon hiding the video power save blocker should be released. | 2737 // Upon hiding the video power save blocker should be released. |
2737 contents()->WasHidden(); | 2738 contents()->WasHidden(); |
2738 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2739 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2739 | 2740 |
2740 // Start another player that only has video. There should be no change in | 2741 // Start another player that only has video. There should be no change in |
2741 // the power save blockers. The notification should take into account the | 2742 // the power save blockers. The notification should take into account the |
2742 // visibility state of the WebContents. | 2743 // visibility state of the WebContents. |
2743 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 2744 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
2744 0, kPlayerVideoOnlyId, true, false)); | 2745 0, kPlayerVideoOnlyId, true, false, false)); |
2745 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2746 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2746 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 2747 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
2747 !AudioStreamMonitor::monitoring_available()); | 2748 !AudioStreamMonitor::monitoring_available()); |
2748 | 2749 |
2749 // Showing the WebContents should result in the creation of the blocker. | 2750 // Showing the WebContents should result in the creation of the blocker. |
2750 contents()->WasShown(); | 2751 contents()->WasShown(); |
2751 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 2752 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
2752 | 2753 |
2753 // Start another player that only has audio. There should be no change in | 2754 // Start another player that only has audio. There should be no change in |
2754 // the power save blockers. | 2755 // the power save blockers. |
2755 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( | 2756 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
2756 0, kPlayerAudioOnlyId, false, true)); | 2757 0, kPlayerAudioOnlyId, false, true, false)); |
2757 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 2758 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
2758 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 2759 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
2759 !AudioStreamMonitor::monitoring_available()); | 2760 !AudioStreamMonitor::monitoring_available()); |
| 2761 |
| 2762 // Start a remote player. There should be no change in the power save |
| 2763 // blockers. |
| 2764 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 2765 0, kPlayerRemoteId, true, true, true)); |
| 2766 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2767 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
| 2768 !AudioStreamMonitor::monitoring_available()); |
2760 | 2769 |
2761 // Destroy the original audio video player. Both power save blockers should | 2770 // Destroy the original audio video player. Both power save blockers should |
2762 // remain. | 2771 // remain. |
2763 rfh->OnMessageReceived( | 2772 rfh->OnMessageReceived( |
2764 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); | 2773 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); |
2765 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 2774 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
2766 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), | 2775 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
2767 !AudioStreamMonitor::monitoring_available()); | 2776 !AudioStreamMonitor::monitoring_available()); |
2768 | 2777 |
2769 // Destroy the audio only player. The video power save blocker should remain. | 2778 // Destroy the audio only player. The video power save blocker should remain. |
2770 rfh->OnMessageReceived( | 2779 rfh->OnMessageReceived( |
2771 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); | 2780 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); |
2772 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); | 2781 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
2773 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2782 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2774 | 2783 |
2775 // Destroy the video only player. No power save blockers should remain. | 2784 // Destroy the video only player. No power save blockers should remain. |
2776 rfh->OnMessageReceived( | 2785 rfh->OnMessageReceived( |
2777 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); | 2786 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); |
2778 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2787 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2779 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2788 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
| 2789 |
| 2790 // Destroy the remote player. No power save blockers should remain. |
| 2791 rfh->OnMessageReceived( |
| 2792 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); |
| 2793 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
| 2794 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2780 } | 2795 } |
2781 #endif | 2796 #endif |
2782 | 2797 |
2783 } // namespace content | 2798 } // namespace content |
OLD | NEW |