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

Unified Diff: third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp

Issue 1949633002: Don't remove the gesture requirement in the autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments. Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
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 9a8705a5a7f76fcce4738e044c9756bd830af50d..c9b3064905fa42970e6e7cf658aabed1daa58ede 100644
--- a/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
+++ b/third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp
@@ -80,7 +80,7 @@ public:
MOCK_CONST_METHOD0(muted, bool());
MOCK_METHOD1(setMuted, void(bool));
MOCK_METHOD0(playInternal, void());
- MOCK_CONST_METHOD0(isUserGestureRequiredForPlay, bool());
+ MOCK_CONST_METHOD0(isLockedPendingUserGesture, bool());
MOCK_METHOD0(removeUserGestureRequirement, void());
MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics));
MOCK_METHOD0(shouldAutoplay, bool());
@@ -159,7 +159,7 @@ public:
void setUserGestureRequiredForPlay(bool required)
{
- ON_CALL(*m_client, isUserGestureRequiredForPlay())
+ ON_CALL(*m_client, isLockedPendingUserGesture())
.WillByDefault(Return(required));
}
@@ -253,7 +253,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());
}
@@ -299,11 +299,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);
@@ -316,11 +315,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);
@@ -333,11 +331,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);
@@ -381,11 +378,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();
+ m_helper->playMethodCalled(false);
+ EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByPlayMethodImmediately))
.Times(1);
@@ -403,19 +399,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)
@@ -429,13 +416,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)
@@ -456,4 +442,15 @@ TEST_F(AutoplayExperimentTest, WithoutSameOriginTests)
EXPECT_TRUE(isEligible());
}
+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(false);
+ m_helper->playMethodCalled(true);
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698