Commit a431e565 authored by Wojciech Dzierżanowski's avatar Wojciech Dzierżanowski Committed by Commit Bot

Fix expectations in OnTimeUpdate() tests

After adding VerifyAndClearExpectations() to OnTimeUpdate* tests it
became clear that they didn't test the right code paths exactly due to
missing pieces of HTMLMediaElement setup.

Bug: 1075458
Change-Id: I4995b60fa6b4fada0476ce3a11b2e850ee3bb95d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256240Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Wojciech Dzierżanowski <wdzierzanowski@opera.com>
Cr-Commit-Position: refs/heads/master@{#781215}
parent 6d2a2771
......@@ -39,6 +39,7 @@ namespace {
class MockWebMediaPlayer : public EmptyWebMediaPlayer {
public:
MOCK_METHOD0(OnTimeUpdate, void());
MOCK_CONST_METHOD0(Seekable, WebTimeRanges());
MOCK_CONST_METHOD0(HasAudio, bool());
MOCK_CONST_METHOD0(HasVideo, bool());
MOCK_CONST_METHOD0(Duration, double());
......@@ -89,6 +90,8 @@ 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, Seekable())
.WillRepeatedly(Return(WebTimeRanges()));
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));
......@@ -610,49 +613,83 @@ TEST_P(HTMLMediaElementTest, NoPendingActivityEvenIfBeforeMetadata) {
}
TEST_P(HTMLMediaElementTest, OnTimeUpdate_DurationChange) {
// Prepare the player.
Media()->SetSrc(SrcSchemeToURL(TestURLScheme::kHttp));
test::RunPendingTasks();
// Change from no duration to 1s will trigger OnTimeUpdate().
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->DurationChanged(1, false);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
// Change from 1s to 2s will trigger OnTimeUpdate().
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->DurationChanged(2, false);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
// No duration change -> no OnTimeUpdate().
Media()->DurationChanged(2, false);
}
TEST_P(HTMLMediaElementTest, OnTimeUpdate_PlayPauseSetRate) {
// Prepare the player.
Media()->SetSrc(SrcSchemeToURL(TestURLScheme::kHttp));
test::RunPendingTasks();
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->Play();
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->setPlaybackRate(0.5);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate()).Times(testing::AtLeast(1));
Media()->pause();
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->setPlaybackRate(1.5);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->Play();
}
TEST_P(HTMLMediaElementTest, OnTimeUpdate_ReadyState) {
// Prepare the player.
Media()->SetSrc(SrcSchemeToURL(TestURLScheme::kHttp));
test::RunPendingTasks();
// The ready state affects the progress of media time, so the player should
// be kept informed.
EXPECT_CALL(*MockMediaPlayer(), GetSrcAfterRedirects)
.WillRepeatedly(Return(GURL()));
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
SetReadyState(HTMLMediaElement::kHaveCurrentData);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
SetReadyState(HTMLMediaElement::kHaveFutureData);
}
TEST_P(HTMLMediaElementTest, OnTimeUpdate_Seeking) {
// Prepare the player and seekable ranges -- setCurrentTime()'s prerequisites.
WebTimeRanges seekable;
seekable.Add(0, 3);
EXPECT_CALL(*MockMediaPlayer(), Seekable).WillRepeatedly(Return(seekable));
EXPECT_CALL(*MockMediaPlayer(), GetSrcAfterRedirects)
.WillRepeatedly(Return(GURL()));
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->SetSrc(SrcSchemeToURL(TestURLScheme::kHttp));
test::RunPendingTasks();
SetReadyState(HTMLMediaElement::kHaveCurrentData);
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->setCurrentTime(1);
testing::Mock::VerifyAndClearExpectations(MockMediaPlayer());
EXPECT_CALL(*MockMediaPlayer(), Seekable).WillRepeatedly(Return(seekable));
EXPECT_CALL(*MockMediaPlayer(), OnTimeUpdate());
Media()->setCurrentTime(2);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment