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

Side by Side Diff: media/blink/webmediaplayer_impl_unittest.cc

Issue 2471373005: Pretend the video has no audio track if it is playing as part of autoplay muted. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 void removeVideoTrack(blink::WebMediaPlayer::TrackId) override {} 78 void removeVideoTrack(blink::WebMediaPlayer::TrackId) override {}
79 void addTextTrack(blink::WebInbandTextTrack*) override {} 79 void addTextTrack(blink::WebInbandTextTrack*) override {}
80 void removeTextTrack(blink::WebInbandTextTrack*) override {} 80 void removeTextTrack(blink::WebInbandTextTrack*) override {}
81 void mediaSourceOpened(blink::WebMediaSource*) override {} 81 void mediaSourceOpened(blink::WebMediaSource*) override {}
82 void requestSeek(double) override {} 82 void requestSeek(double) override {}
83 void remoteRouteAvailabilityChanged(bool) override {} 83 void remoteRouteAvailabilityChanged(bool) override {}
84 void connectedToRemoteDevice() override {} 84 void connectedToRemoteDevice() override {}
85 void disconnectedFromRemoteDevice() override {} 85 void disconnectedFromRemoteDevice() override {}
86 void cancelledRemotePlaybackRequest() override {} 86 void cancelledRemotePlaybackRequest() override {}
87 bool isAutoplayingMuted() override { return is_autoplaying_muted_; }
87 void requestReload(const blink::WebURL& newUrl) override {} 88 void requestReload(const blink::WebURL& newUrl) override {}
88 89
90 void set_is_autoplaying_muted(bool value) { is_autoplaying_muted_ = value; }
91
89 private: 92 private:
93 bool is_autoplaying_muted_ = false;
94
90 DISALLOW_COPY_AND_ASSIGN(DummyWebMediaPlayerClient); 95 DISALLOW_COPY_AND_ASSIGN(DummyWebMediaPlayerClient);
91 }; 96 };
92 97
93 class MockWebMediaPlayerDelegate 98 class MockWebMediaPlayerDelegate
94 : public WebMediaPlayerDelegate, 99 : public WebMediaPlayerDelegate,
95 public base::SupportsWeakPtr<MockWebMediaPlayerDelegate> { 100 public base::SupportsWeakPtr<MockWebMediaPlayerDelegate> {
96 public: 101 public:
97 MockWebMediaPlayerDelegate() = default; 102 MockWebMediaPlayerDelegate() = default;
98 ~MockWebMediaPlayerDelegate() = default; 103 ~MockWebMediaPlayerDelegate() = default;
99 104
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 wmpi_->must_suspend_ = false; 213 wmpi_->must_suspend_ = false;
209 return wmpi_->UpdatePlayState_ComputePlayState(false, true, false); 214 return wmpi_->UpdatePlayState_ComputePlayState(false, true, false);
210 } 215 }
211 216
212 WebMediaPlayerImpl::PlayState ComputeMustSuspendPlayState() { 217 WebMediaPlayerImpl::PlayState ComputeMustSuspendPlayState() {
213 wmpi_->is_idle_ = false; 218 wmpi_->is_idle_ = false;
214 wmpi_->must_suspend_ = true; 219 wmpi_->must_suspend_ = true;
215 return wmpi_->UpdatePlayState_ComputePlayState(false, false, false); 220 return wmpi_->UpdatePlayState_ComputePlayState(false, false, false);
216 } 221 }
217 222
223 void SetDelegateState(WebMediaPlayerImpl::DelegateState state) {
224 wmpi_->SetDelegateState(state);
225 }
226
218 bool IsSuspended() { return wmpi_->pipeline_controller_.IsSuspended(); } 227 bool IsSuspended() { return wmpi_->pipeline_controller_.IsSuspended(); }
219 228
220 void AddBufferedRanges() { 229 void AddBufferedRanges() {
221 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1); 230 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1);
222 } 231 }
223 232
224 void SetupForResumingBackgroundVideo() { 233 void SetupForResumingBackgroundVideo() {
225 #if !defined(OS_ANDROID) 234 #if !defined(OS_ANDROID)
226 // Need to enable media suspend to test resuming background videos. 235 // Need to enable media suspend to test resuming background videos.
227 base::CommandLine::ForCurrentProcess()->AppendSwitch( 236 base::CommandLine::ForCurrentProcess()->AppendSwitch(
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 655
647 EXPECT_CALL(delegate_, IsPlayingBackgroundVideo()).WillOnce(Return(false)); 656 EXPECT_CALL(delegate_, IsPlayingBackgroundVideo()).WillOnce(Return(false));
648 EXPECT_CALL(delegate_, IsHidden()).WillRepeatedly(Return(true)); 657 EXPECT_CALL(delegate_, IsHidden()).WillRepeatedly(Return(true));
649 658
650 state = ComputeBackgroundedPlayState(); 659 state = ComputeBackgroundedPlayState();
651 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PAUSED, state.delegate_state); 660 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PAUSED, state.delegate_state);
652 EXPECT_FALSE(state.is_memory_reporting_enabled); 661 EXPECT_FALSE(state.is_memory_reporting_enabled);
653 EXPECT_TRUE(state.is_suspended); 662 EXPECT_TRUE(state.is_suspended);
654 } 663 }
655 664
665 TEST_F(WebMediaPlayerImplTest, AutoplayMuted_StartsAndStops) {
666 InitializeDefaultWebMediaPlayerImpl();
667 SetMetadata(true, true);
668 SetReadyState(blink::WebMediaPlayer::ReadyStateHaveFutureData);
669 SetPaused(false);
670
671 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _));
672 client_.set_is_autoplaying_muted(true);
673 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING);
674
675 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _));
676 client_.set_is_autoplaying_muted(false);
677 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING);
678 }
679
680 TEST_F(WebMediaPlayerImplTest, AutoplayMuted_SetVolume) {
681 InitializeDefaultWebMediaPlayerImpl();
682 SetMetadata(true, true);
683 SetReadyState(blink::WebMediaPlayer::ReadyStateHaveFutureData);
684 SetPaused(false);
685
686 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _));
687 client_.set_is_autoplaying_muted(true);
688 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING);
689
690 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _));
691 client_.set_is_autoplaying_muted(false);
692 wmpi_->setVolume(1.0);
693 }
694
656 } // namespace media 695 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | third_party/WebKit/LayoutTests/media/autoplay-muted.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698