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