OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 void SetupForResumingBackgroundVideo() { | 243 void SetupForResumingBackgroundVideo() { |
244 #if !defined(OS_ANDROID) | 244 #if !defined(OS_ANDROID) |
245 // Need to enable media suspend to test resuming background videos. | 245 // Need to enable media suspend to test resuming background videos. |
246 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 246 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
247 switches::kEnableMediaSuspend); | 247 switches::kEnableMediaSuspend); |
248 #endif // !defined(OS_ANDROID) | 248 #endif // !defined(OS_ANDROID) |
249 scoped_feature_list_.InitAndEnableFeature(kResumeBackgroundVideo); | 249 scoped_feature_list_.InitAndEnableFeature(kResumeBackgroundVideo); |
250 } | 250 } |
251 | 251 |
| 252 void SetBackgroundVideoOptimization(bool enable) { |
| 253 if (enable) { |
| 254 scoped_feature_list_.InitAndEnableFeature( |
| 255 kBackgroundVideoTrackOptimization); |
| 256 } else { |
| 257 scoped_feature_list_.InitAndDisableFeature( |
| 258 kBackgroundVideoTrackOptimization); |
| 259 } |
| 260 } |
| 261 |
| 262 bool ShouldDisableVideoWhenHidden() const { |
| 263 return wmpi_->ShouldDisableVideoWhenHidden(); |
| 264 } |
| 265 |
252 // "Renderer" thread. | 266 // "Renderer" thread. |
253 base::MessageLoop message_loop_; | 267 base::MessageLoop message_loop_; |
254 | 268 |
255 // "Media" thread. This is necessary because WMPI destruction waits on a | 269 // "Media" thread. This is necessary because WMPI destruction waits on a |
256 // WaitableEvent. | 270 // WaitableEvent. |
257 base::Thread media_thread_; | 271 base::Thread media_thread_; |
258 | 272 |
259 // Blink state. | 273 // Blink state. |
260 blink::WebFrameClient web_frame_client_; | 274 blink::WebFrameClient web_frame_client_; |
261 blink::WebView* web_view_; | 275 blink::WebView* web_view_; |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 762 |
749 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); | 763 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); |
750 client_.set_is_autoplaying_muted(true); | 764 client_.set_is_autoplaying_muted(true); |
751 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); | 765 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); |
752 | 766 |
753 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); | 767 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); |
754 client_.set_is_autoplaying_muted(false); | 768 client_.set_is_autoplaying_muted(false); |
755 wmpi_->setVolume(1.0); | 769 wmpi_->setVolume(1.0); |
756 } | 770 } |
757 | 771 |
| 772 TEST_F(WebMediaPlayerImplTest, ShouldDisableVideoWhenHidden) { |
| 773 InitializeWebMediaPlayerImpl(); |
| 774 EXPECT_CALL(delegate_, IsHidden()).WillRepeatedly(Return(true)); |
| 775 SetBackgroundVideoOptimization(true); |
| 776 |
| 777 SetMetadata(true, true); |
| 778 EXPECT_TRUE(ShouldDisableVideoWhenHidden()); |
| 779 |
| 780 SetMetadata(false, true); |
| 781 EXPECT_FALSE(ShouldDisableVideoWhenHidden()); |
| 782 |
| 783 SetMetadata(true, false); |
| 784 EXPECT_FALSE(ShouldDisableVideoWhenHidden()); |
| 785 } |
| 786 |
| 787 TEST_F(WebMediaPlayerImplTest, ShouldDisableVideoWhenHiddenFeatureDisabled) { |
| 788 InitializeWebMediaPlayerImpl(); |
| 789 EXPECT_CALL(delegate_, IsHidden()).WillRepeatedly(Return(true)); |
| 790 SetBackgroundVideoOptimization(false); |
| 791 |
| 792 SetMetadata(true, true); |
| 793 EXPECT_FALSE(ShouldDisableVideoWhenHidden()); |
| 794 } |
| 795 |
758 } // namespace media | 796 } // namespace media |
OLD | NEW |