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/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 Loading... |
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 the tab audio indicator is available. |
| 2705 if (AudioStreamMonitor::tab_audio_indicator_available()) { |
| 2706 // Send a fake tab audio indicator 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 // Toggle the tab audio indicator off. |
| 2713 monitor->set_was_recently_audible_for_testing(false); |
| 2714 contents()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 2715 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
| 2716 } |
| 2717 |
| 2718 // Start a player with both audio and video. A video power save blocker |
| 2719 // should be created. If the tab audio indicator is available, an audio power |
| 2720 // save blocker should be created too. |
| 2721 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 2722 0, kPlayerAudioVideoId, true, true)); |
| 2723 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2724 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
| 2725 !AudioStreamMonitor::tab_audio_indicator_available()); |
| 2726 |
| 2727 // Start another player that only has audio. There should be no change in |
| 2728 // the power save blockers. |
| 2729 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 2730 0, kPlayerAudioOnlyId, false, true)); |
| 2731 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2732 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
| 2733 !AudioStreamMonitor::tab_audio_indicator_available()); |
| 2734 |
| 2735 // Start another player that only has video. There should be no change in |
| 2736 // the power save blockers. |
| 2737 rfh->OnMessageReceived(FrameHostMsg_MediaPlayingNotification( |
| 2738 0, kPlayerVideoOnlyId, true, false)); |
| 2739 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2740 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
| 2741 !AudioStreamMonitor::tab_audio_indicator_available()); |
| 2742 |
| 2743 // Destroy the original audio video player. Both power save blockers should |
| 2744 // remain. |
| 2745 rfh->OnMessageReceived( |
| 2746 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioVideoId)); |
| 2747 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2748 EXPECT_EQ(contents()->has_audio_power_save_blocker_for_testing(), |
| 2749 !AudioStreamMonitor::tab_audio_indicator_available()); |
| 2750 |
| 2751 // Destroy the audio only player. The video power save blocker should remain. |
| 2752 rfh->OnMessageReceived( |
| 2753 FrameHostMsg_MediaPausedNotification(0, kPlayerAudioOnlyId)); |
| 2754 EXPECT_TRUE(contents()->has_video_power_save_blocker_for_testing()); |
| 2755 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
| 2756 |
| 2757 // Destroy the video only player. No power save blockers should remain. |
| 2758 rfh->OnMessageReceived( |
| 2759 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); |
| 2760 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
| 2761 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
| 2762 } |
| 2763 |
2688 } // namespace content | 2764 } // namespace content |
OLD | NEW |