Chromium Code Reviews| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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, SetVolumeCallsDidPlay) { | |
|
sandersd (OOO until July 31)
2016/10/04 23:53:04
We don't have tests that all the other triggers re
mlamouri (slow - plz ping)
2016/10/05 16:19:49
Added the comment and removed the test.
| |
| 666 InitializeDefaultWebMediaPlayerImpl(); | |
| 667 SetMetadata(true, true); | |
| 668 SetReadyState(blink::WebMediaPlayer::ReadyStateHaveFutureData); | |
| 669 SetPaused(false); | |
| 670 | |
| 671 EXPECT_CALL(delegate_, DidPlay(_, _, _, _, _)); | |
| 672 wmpi_->setVolume(1.0); | |
| 673 } | |
| 674 | |
| 675 TEST_F(WebMediaPlayerImplTest, AutoplayMuted_StartsAndStops) { | |
| 676 InitializeDefaultWebMediaPlayerImpl(); | |
| 677 WebMediaPlayerImpl::PlayState state; | |
| 678 SetMetadata(true, true); | |
| 679 SetReadyState(blink::WebMediaPlayer::ReadyStateHaveFutureData); | |
| 680 SetPaused(false); | |
| 681 | |
| 682 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); | |
| 683 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); | |
|
sandersd (OOO until July 31)
2016/10/04 23:53:04
Move these right before the respective SetDelegate
mlamouri (slow - plz ping)
2016/10/05 16:19:49
Done.
| |
| 684 | |
| 685 client_.set_is_autoplaying_muted(true); | |
| 686 state = ComputePlayState(); | |
| 687 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PLAYING, state.delegate_state); | |
| 688 SetDelegateState(state.delegate_state); | |
|
sandersd (OOO until July 31)
2016/10/04 23:53:04
This seems to be testing two different things. Pro
mlamouri (slow - plz ping)
2016/10/05 16:19:49
I'm not sure I'm following this. ComputePlayState(
sandersd (OOO until July 31)
2016/10/05 17:38:17
Sorry, I should have said UpdatePlayState().
| |
| 689 | |
| 690 client_.set_is_autoplaying_muted(false); | |
| 691 state = ComputePlayState(); | |
| 692 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PLAYING, state.delegate_state); | |
| 693 SetDelegateState(state.delegate_state); | |
| 694 } | |
| 695 | |
| 696 TEST_F(WebMediaPlayerImplTest, AutoplayMuted_SetVolume) { | |
| 697 InitializeDefaultWebMediaPlayerImpl(); | |
| 698 WebMediaPlayerImpl::PlayState state; | |
| 699 SetMetadata(true, true); | |
| 700 SetReadyState(blink::WebMediaPlayer::ReadyStateHaveFutureData); | |
| 701 SetPaused(false); | |
| 702 | |
| 703 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); | |
| 704 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); | |
| 705 | |
| 706 client_.set_is_autoplaying_muted(true); | |
| 707 state = ComputePlayState(); | |
| 708 EXPECT_EQ(WebMediaPlayerImpl::DelegateState::PLAYING, state.delegate_state); | |
| 709 SetDelegateState(state.delegate_state); | |
| 710 | |
| 711 client_.set_is_autoplaying_muted(false); | |
| 712 wmpi_->setVolume(1.0); | |
| 713 } | |
| 714 | |
| 656 } // namespace media | 715 } // namespace media |
| OLD | NEW |