diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc b/chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc index df41b7a211c..3fd83d9af3f 100644 --- a/chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc +++ b/chromium/third_party/blink/renderer/core/html/media/html_media_element_test.cc @@ -8,7 +8,9 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/mojom/autoplay/autoplay.mojom-blink.h" +#include "third_party/blink/public/platform/web_media_player.h" #include "third_party/blink/public/platform/web_media_player_source.h" +#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/html/media/html_audio_element.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h" @@ -32,12 +34,17 @@ using ::testing::Return; namespace blink { +namespace { + class MockWebMediaPlayer : public EmptyWebMediaPlayer { public: MOCK_CONST_METHOD0(HasAudio, bool()); MOCK_CONST_METHOD0(HasVideo, bool()); MOCK_CONST_METHOD0(Duration, double()); MOCK_CONST_METHOD0(CurrentTime, double()); + MOCK_CONST_METHOD0(IsEnded, bool()); + MOCK_CONST_METHOD0(GetNetworkState, NetworkState()); + MOCK_CONST_METHOD0(WouldTaintOrigin, bool()); MOCK_METHOD1(SetLatencyHint, void(double)); MOCK_METHOD1(EnabledAudioTracksChanged, void(const WebVector<TrackId>&)); MOCK_METHOD1(SelectedVideoTrackChanged, void(TrackId*)); @@ -70,6 +77,8 @@ class WebMediaStubLocalFrameClient : public EmptyLocalFrameClient { enum class MediaTestParam { kAudio, kVideo }; +} // namespace + class HTMLMediaElementTest : public testing::TestWithParam<MediaTestParam> { protected: void SetUp() override { @@ -79,19 +88,19 @@ class HTMLMediaElementTest : public testing::TestWithParam<MediaTestParam> { // Most tests do not care about this call, nor its return value. Those that // do will clear this expectation and set custom expectations/returns. - EXPECT_CALL(*mock_media_player, HasAudio()) - .WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*mock_media_player, HasVideo()) - .WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*mock_media_player, Duration()) - .WillRepeatedly(testing::Return(1.0)); - EXPECT_CALL(*mock_media_player, CurrentTime()) - .WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*mock_media_player, HasAudio()).WillRepeatedly(Return(true)); + EXPECT_CALL(*mock_media_player, HasVideo()).WillRepeatedly(Return(true)); + EXPECT_CALL(*mock_media_player, Duration()).WillRepeatedly(Return(1.0)); + EXPECT_CALL(*mock_media_player, CurrentTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*mock_media_player, Load(_, _, _)) .Times(AnyNumber()) .WillRepeatedly(Return(WebMediaPlayer::LoadTiming::kImmediate)); - EXPECT_CALL(*mock_media_player, DidLazyLoad) - .WillRepeatedly(testing::Return(false)); + EXPECT_CALL(*mock_media_player, DidLazyLoad).WillRepeatedly(Return(false)); + EXPECT_CALL(*mock_media_player, WouldTaintOrigin) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*mock_media_player, GetNetworkState) + .WillRepeatedly(Return(WebMediaPlayer::kNetworkStateIdle)); + EXPECT_CALL(*mock_media_player, SetLatencyHint(_)).Times(AnyNumber()); dummy_page_holder_ = std::make_unique<DummyPageHolder>( IntSize(), nullptr, @@ -125,6 +134,12 @@ class HTMLMediaElementTest : public testing::TestWithParam<MediaTestParam> { Media()->SetReadyState(state); } + void SetNetworkState(WebMediaPlayer::NetworkState state) { + Media()->SetNetworkState(state); + } + + bool MediaShouldBeOpaque() const { return Media()->MediaShouldBeOpaque(); } + void SetError(MediaError* err) { Media()->MediaEngineError(err); } void SimulateHighMediaEngagement() { @@ -137,7 +152,7 @@ class HTMLMediaElementTest : public testing::TestWithParam<MediaTestParam> { } ExecutionContext* GetExecutionContext() const { - return &dummy_page_holder_->GetDocument(); + return dummy_page_holder_->GetFrame().DomWindow(); } private: @@ -262,7 +277,8 @@ TEST_P(HTMLMediaElementTest, CouldPlayIfEnoughDataRespondsToEnded) { MockWebMediaPlayer* mock_wmpi = reinterpret_cast<MockWebMediaPlayer*>(Media()->GetWebMediaPlayer()); - EXPECT_NE(mock_wmpi, nullptr); + ASSERT_NE(mock_wmpi, nullptr); + EXPECT_CALL(*mock_wmpi, IsEnded()).WillRepeatedly(Return(false)); EXPECT_TRUE(CouldPlayIfEnoughData()); // Playback can only end once the ready state is above kHaveMetadata. @@ -274,7 +290,8 @@ TEST_P(HTMLMediaElementTest, CouldPlayIfEnoughDataRespondsToEnded) { // Now advance current time to duration and verify ended state. testing::Mock::VerifyAndClearExpectations(mock_wmpi); EXPECT_CALL(*mock_wmpi, CurrentTime()) - .WillRepeatedly(testing::Return(Media()->duration())); + .WillRepeatedly(Return(Media()->duration())); + EXPECT_CALL(*mock_wmpi, IsEnded()).WillRepeatedly(Return(true)); EXPECT_FALSE(CouldPlayIfEnoughData()); EXPECT_TRUE(Media()->ended()); } @@ -328,9 +345,9 @@ TEST_P(HTMLMediaElementTest, CouldPlayIfEnoughDataInfiniteStreamNeverEnds) { test::RunPendingTasks(); EXPECT_CALL(*MockMediaPlayer(), Duration()) - .WillRepeatedly(testing::Return(std::numeric_limits<double>::infinity())); + .WillRepeatedly(Return(std::numeric_limits<double>::infinity())); EXPECT_CALL(*MockMediaPlayer(), CurrentTime()) - .WillRepeatedly(testing::Return(std::numeric_limits<double>::infinity())); + .WillRepeatedly(Return(std::numeric_limits<double>::infinity())); SetReadyState(HTMLMediaElement::kHaveMetadata); EXPECT_FALSE(Media()->paused()); @@ -573,4 +590,20 @@ TEST_P(HTMLMediaElementTest, EmptyRedirectedSrcUsesOriginal) { EXPECT_EQ(Media()->downloadURL(), Media()->currentSrc()); } +TEST_P(HTMLMediaElementTest, NoPendingActivityEvenIfBeforeMetadata) { + Media()->SetSrc(SrcSchemeToURL(TestURLScheme::kHttp)); + test::RunPendingTasks(); + + MockWebMediaPlayer* mock_wmpi = + reinterpret_cast<MockWebMediaPlayer*>(Media()->GetWebMediaPlayer()); + EXPECT_CALL(*mock_wmpi, WouldTaintOrigin()).WillRepeatedly(Return(true)); + EXPECT_NE(mock_wmpi, nullptr); + + EXPECT_TRUE(MediaShouldBeOpaque()); + EXPECT_TRUE(Media()->HasPendingActivity()); + SetNetworkState(WebMediaPlayer::kNetworkStateIdle); + EXPECT_FALSE(Media()->HasPendingActivity()); + EXPECT_TRUE(MediaShouldBeOpaque()); +} + } // namespace blink |