| Index: third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp b/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
|
| index ed0bdaadd7a395a88f3b07e930732cf0a822788d..115567b7c682c3231d1b03a413184858f910608c 100644
|
| --- a/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
|
| +++ b/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
|
| @@ -48,6 +48,8 @@ public:
|
| .WillByDefault(Return(false));
|
|
|
| // Other handy defaults.
|
| + ON_CALL(*this, paused())
|
| + .WillByDefault(Return(true));
|
| ON_CALL(*this, ended())
|
| .WillByDefault(Return(false));
|
| ON_CALL(*this, pageVisibilityState())
|
| @@ -64,7 +66,7 @@ public:
|
| // state unless we explicitly expect it.
|
| EXPECT_CALL(*this, setMuted(_))
|
| .Times(0);
|
| - EXPECT_CALL(*this, removeUserGestureRequirement())
|
| + EXPECT_CALL(*this, unlockUserGesture())
|
| .Times(0);
|
| EXPECT_CALL(*this, setRequestPositionUpdates(true))
|
| .Times(0);
|
| @@ -76,12 +78,13 @@ public:
|
|
|
| MOCK_CONST_METHOD0(currentTime, double());
|
| MOCK_CONST_METHOD0(duration, double());
|
| + MOCK_CONST_METHOD0(paused, bool());
|
| MOCK_CONST_METHOD0(ended, bool());
|
| MOCK_CONST_METHOD0(muted, bool());
|
| MOCK_METHOD1(setMuted, void(bool));
|
| MOCK_METHOD0(playInternal, void());
|
| - MOCK_CONST_METHOD0(isUserGestureRequiredForPlay, bool());
|
| - MOCK_METHOD0(removeUserGestureRequirement, void());
|
| + MOCK_CONST_METHOD0(isLockedPendingUserGesture, bool());
|
| + MOCK_METHOD0(unlockUserGesture, void());
|
| MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics));
|
| MOCK_METHOD0(shouldAutoplay, bool());
|
| MOCK_CONST_METHOD0(isHTMLVideoElement, bool());
|
| @@ -164,7 +167,7 @@ public:
|
|
|
| void setUserGestureRequiredForPlay(bool required)
|
| {
|
| - ON_CALL(*m_client, isUserGestureRequiredForPlay())
|
| + ON_CALL(*m_client, isLockedPendingUserGesture())
|
| .WillByDefault(Return(required));
|
| }
|
|
|
| @@ -258,7 +261,7 @@ TEST_F(AutoplayExperimentTest, IsEligibleRequiresUserGesture)
|
| {
|
| setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
| // If a user gesture is not required, then we're not eligible.
|
| - ON_CALL(*m_client, isUserGestureRequiredForPlay())
|
| + ON_CALL(*m_client, isLockedPendingUserGesture())
|
| .WillByDefault(Return(false));
|
| EXPECT_FALSE(isEligible());
|
| }
|
| @@ -304,11 +307,10 @@ TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenBailout)
|
| {
|
| setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
|
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
|
| .Times(1);
|
| m_helper->becameReadyToPlay();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
|
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAutoplayFlagImmediately))
|
| .Times(1);
|
| @@ -321,11 +323,10 @@ TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenPause)
|
| {
|
| setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
|
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
|
| .Times(1);
|
| m_helper->becameReadyToPlay();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
|
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAutoplayFlagImmediately))
|
| .Times(1);
|
| @@ -338,11 +339,10 @@ TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenComplete)
|
| {
|
| setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
|
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
|
| .Times(1);
|
| m_helper->becameReadyToPlay();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
|
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAutoplayFlagImmediately))
|
| .Times(1);
|
| @@ -386,11 +386,10 @@ TEST_F(AutoplayExperimentTest, PlayMethodThenBailout)
|
| setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
| setShouldAutoplay(false); // No autoplay attribute.
|
|
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
|
| .Times(1);
|
| m_helper->playMethodCalled();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
|
|
| EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByPlayMethodImmediately))
|
| .Times(1);
|
| @@ -408,19 +407,10 @@ TEST_F(AutoplayExperimentTest, DeferAutoplayUntilMuted)
|
| .Times(1);
|
| m_helper->becameReadyToPlay();
|
|
|
| - // When we toggle the muted attribute, it should start.
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| - EXPECT_CALL(*m_client, playInternal())
|
| - .Times(1);
|
| + // When we toggle the muted attribute, it should become eligible to start.
|
| + EXPECT_FALSE(m_helper->isGestureRequirementOverridden());
|
| setIsMuted(true);
|
| - m_helper->mutedChanged();
|
| -
|
| - // When playback starts (in response to playInternal()), it should also
|
| - // record why. 'After scroll' isn't the best name, but this isn't a common case.
|
| - EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAutoplayFlagAfterScroll))
|
| - .Times(1);
|
| - startPlaybackWithoutUserGesture();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
| }
|
|
|
| TEST_F(AutoplayExperimentTest, DeferPlaybackUntilInViewport)
|
| @@ -434,13 +424,12 @@ TEST_F(AutoplayExperimentTest, DeferPlaybackUntilInViewport)
|
| .Times(1);
|
| m_helper->becameReadyToPlay();
|
|
|
| - EXPECT_CALL(*m_client, removeUserGestureRequirement())
|
| - .Times(1);
|
| EXPECT_CALL(*m_client, playInternal())
|
| .Times(1);
|
| EXPECT_CALL(*m_client, setRequestPositionUpdates(false))
|
| .Times(1);
|
| moveIntoViewport();
|
| + EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
|
| }
|
|
|
| TEST_F(AutoplayExperimentTest, WithSameOriginTests)
|
| @@ -473,4 +462,16 @@ TEST_F(AutoplayExperimentTest, AudioPageVisibility)
|
| EXPECT_FALSE(meetsVisibilityRequirements());
|
| }
|
|
|
| +TEST_F(AutoplayExperimentTest, PlayTwiceIsIgnored)
|
| +{
|
| + setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutoplayClient::Video));
|
| + setShouldAutoplay(false); // No autoplay attribute.
|
| +
|
| + EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
|
| + .Times(1);
|
| + m_helper->playMethodCalled();
|
| + ON_CALL(*m_client, paused()).WillByDefault(Return(false));
|
| + m_helper->playMethodCalled();
|
| +}
|
| +
|
| }
|
|
|