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

Side by Side 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: s/removeUserGestureRequirement/unlockUserGesture 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/dom/Document.h" 5 #include "core/dom/Document.h"
6 #include "core/html/AutoplayExperimentHelper.h" 6 #include "core/html/AutoplayExperimentHelper.h"
7 #include "platform/UserGestureIndicator.h" 7 #include "platform/UserGestureIndicator.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ON_CALL(*this, isAutoplayAllowedPerSettings()) 57 ON_CALL(*this, isAutoplayAllowedPerSettings())
58 .WillByDefault(Return(true)); 58 .WillByDefault(Return(true));
59 ON_CALL(*this, absoluteBoundingBoxRect()) 59 ON_CALL(*this, absoluteBoundingBoxRect())
60 .WillByDefault(Return( 60 .WillByDefault(Return(
61 IntRect(10, 10, 100, 100))); 61 IntRect(10, 10, 100, 100)));
62 62
63 // Normally, the autoplay experiment should not modify lots of other 63 // Normally, the autoplay experiment should not modify lots of other
64 // state unless we explicitly expect it. 64 // state unless we explicitly expect it.
65 EXPECT_CALL(*this, setMuted(_)) 65 EXPECT_CALL(*this, setMuted(_))
66 .Times(0); 66 .Times(0);
67 EXPECT_CALL(*this, removeUserGestureRequirement()) 67 EXPECT_CALL(*this, unlockUserGesture())
68 .Times(0); 68 .Times(0);
69 EXPECT_CALL(*this, setRequestPositionUpdates(true)) 69 EXPECT_CALL(*this, setRequestPositionUpdates(true))
70 .Times(0); 70 .Times(0);
71 EXPECT_CALL(*this, recordAutoplayMetric(_)) 71 EXPECT_CALL(*this, recordAutoplayMetric(_))
72 .Times(0); 72 .Times(0);
73 } 73 }
74 74
75 virtual ~MockAutoplayClient() {} 75 virtual ~MockAutoplayClient() {}
76 76
77 MOCK_CONST_METHOD0(currentTime, double()); 77 MOCK_CONST_METHOD0(currentTime, double());
78 MOCK_CONST_METHOD0(duration, double()); 78 MOCK_CONST_METHOD0(duration, double());
79 MOCK_CONST_METHOD0(ended, bool()); 79 MOCK_CONST_METHOD0(ended, bool());
80 MOCK_CONST_METHOD0(muted, bool()); 80 MOCK_CONST_METHOD0(muted, bool());
81 MOCK_METHOD1(setMuted, void(bool)); 81 MOCK_METHOD1(setMuted, void(bool));
82 MOCK_METHOD0(playInternal, void()); 82 MOCK_METHOD0(playInternal, void());
83 MOCK_CONST_METHOD0(isUserGestureRequiredForPlay, bool()); 83 MOCK_CONST_METHOD0(isLockedPendingUserGesture, bool());
84 MOCK_METHOD0(removeUserGestureRequirement, void()); 84 MOCK_METHOD0(unlockUserGesture, void());
85 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics)); 85 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics));
86 MOCK_METHOD0(shouldAutoplay, bool()); 86 MOCK_METHOD0(shouldAutoplay, bool());
87 MOCK_CONST_METHOD0(isHTMLVideoElement, bool()); 87 MOCK_CONST_METHOD0(isHTMLVideoElement, bool());
88 MOCK_CONST_METHOD0(isHTMLAudioElement, bool()); 88 MOCK_CONST_METHOD0(isHTMLAudioElement, bool());
89 MOCK_METHOD0(isLegacyViewportType, bool()); 89 MOCK_METHOD0(isLegacyViewportType, bool());
90 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState()); 90 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState());
91 MOCK_CONST_METHOD0(autoplayExperimentMode, String()); 91 MOCK_CONST_METHOD0(autoplayExperimentMode, String());
92 MOCK_CONST_METHOD0(isCrossOrigin, bool()); 92 MOCK_CONST_METHOD0(isCrossOrigin, bool());
93 MOCK_CONST_METHOD0(isAutoplayAllowedPerSettings, bool()); 93 MOCK_CONST_METHOD0(isAutoplayAllowedPerSettings, bool());
94 MOCK_METHOD1(setRequestPositionUpdates, void(bool)); 94 MOCK_METHOD1(setRequestPositionUpdates, void(bool));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 void startPlaybackWithUserGesture() 158 void startPlaybackWithUserGesture()
159 { 159 {
160 UserGestureIndicator indicator(DefinitelyProcessingUserGesture); 160 UserGestureIndicator indicator(DefinitelyProcessingUserGesture);
161 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); 161 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
162 startPlayback(); 162 startPlayback();
163 } 163 }
164 164
165 void setUserGestureRequiredForPlay(bool required) 165 void setUserGestureRequiredForPlay(bool required)
166 { 166 {
167 ON_CALL(*m_client, isUserGestureRequiredForPlay()) 167 ON_CALL(*m_client, isLockedPendingUserGesture())
168 .WillByDefault(Return(required)); 168 .WillByDefault(Return(required));
169 } 169 }
170 170
171 void setShouldAutoplay(bool should) 171 void setShouldAutoplay(bool should)
172 { 172 {
173 ON_CALL(*m_client, shouldAutoplay()) 173 ON_CALL(*m_client, shouldAutoplay())
174 .WillByDefault(Return(should)); 174 .WillByDefault(Return(should));
175 } 175 }
176 176
177 void setIsMuted(bool isMuted) 177 void setIsMuted(bool isMuted)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 { 251 {
252 // Audio should not be eligible for video mode. 252 // Audio should not be eligible for video mode.
253 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Audio)); 253 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Audio));
254 EXPECT_FALSE(isEligible()); 254 EXPECT_FALSE(isEligible());
255 } 255 }
256 256
257 TEST_F(AutoplayExperimentTest, IsEligibleRequiresUserGesture) 257 TEST_F(AutoplayExperimentTest, IsEligibleRequiresUserGesture)
258 { 258 {
259 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 259 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
260 // If a user gesture is not required, then we're not eligible. 260 // If a user gesture is not required, then we're not eligible.
261 ON_CALL(*m_client, isUserGestureRequiredForPlay()) 261 ON_CALL(*m_client, isLockedPendingUserGesture())
262 .WillByDefault(Return(false)); 262 .WillByDefault(Return(false));
263 EXPECT_FALSE(isEligible()); 263 EXPECT_FALSE(isEligible());
264 } 264 }
265 265
266 TEST_F(AutoplayExperimentTest, IsEligibleRequiresShouldAutoplay) 266 TEST_F(AutoplayExperimentTest, IsEligibleRequiresShouldAutoplay)
267 { 267 {
268 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 268 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
269 // If we shouldn't autoplay, then we're not eligible. 269 // If we shouldn't autoplay, then we're not eligible.
270 ON_CALL(*m_client, shouldAutoplay()) 270 ON_CALL(*m_client, shouldAutoplay())
271 .WillByDefault(Return(false)); 271 .WillByDefault(Return(false));
(...skipping 25 matching lines...) Expand all
297 297
298 ON_CALL(*m_client, muted()) 298 ON_CALL(*m_client, muted())
299 .WillByDefault(Return(true)); 299 .WillByDefault(Return(true));
300 EXPECT_TRUE(isEligible()); 300 EXPECT_TRUE(isEligible());
301 } 301 }
302 302
303 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenBailout) 303 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenBailout)
304 { 304 {
305 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 305 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
306 306
307 EXPECT_CALL(*m_client, removeUserGestureRequirement())
308 .Times(1);
309 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 307 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
310 .Times(1); 308 .Times(1);
311 m_helper->becameReadyToPlay(); 309 m_helper->becameReadyToPlay();
310 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
312 311
313 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately)) 312 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately))
314 .Times(1); 313 .Times(1);
315 startPlaybackWithoutUserGesture(); 314 startPlaybackWithoutUserGesture();
316 315
317 pausePlaybackExpectingBailout(true); 316 pausePlaybackExpectingBailout(true);
318 } 317 }
319 318
320 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenPause) 319 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenPause)
321 { 320 {
322 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 321 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
323 322
324 EXPECT_CALL(*m_client, removeUserGestureRequirement())
325 .Times(1);
326 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 323 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
327 .Times(1); 324 .Times(1);
328 m_helper->becameReadyToPlay(); 325 m_helper->becameReadyToPlay();
326 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
329 327
330 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately)) 328 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately))
331 .Times(1); 329 .Times(1);
332 startPlaybackWithoutUserGesture(); 330 startPlaybackWithoutUserGesture();
333 331
334 pausePlaybackNotExpectingBailout(true); 332 pausePlaybackNotExpectingBailout(true);
335 } 333 }
336 334
337 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenComplete) 335 TEST_F(AutoplayExperimentTest, BecameReadyAutoplayThenComplete)
338 { 336 {
339 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 337 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
340 338
341 EXPECT_CALL(*m_client, removeUserGestureRequirement())
342 .Times(1);
343 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 339 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
344 .Times(1); 340 .Times(1);
345 m_helper->becameReadyToPlay(); 341 m_helper->becameReadyToPlay();
342 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
346 343
347 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately)) 344 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagImmediately))
348 .Times(1); 345 .Times(1);
349 startPlaybackWithoutUserGesture(); 346 startPlaybackWithoutUserGesture();
350 347
351 // Now stop at the end. 348 // Now stop at the end.
352 endPlayback(true); 349 endPlayback(true);
353 } 350 }
354 351
355 TEST_F(AutoplayExperimentTest, NoUserGestureNeededShouldNotOverride) 352 TEST_F(AutoplayExperimentTest, NoUserGestureNeededShouldNotOverride)
(...skipping 23 matching lines...) Expand all
379 376
380 // Expect bailout, but not from autoplay. 377 // Expect bailout, but not from autoplay.
381 pausePlaybackExpectingBailout(false); 378 pausePlaybackExpectingBailout(false);
382 } 379 }
383 380
384 TEST_F(AutoplayExperimentTest, PlayMethodThenBailout) 381 TEST_F(AutoplayExperimentTest, PlayMethodThenBailout)
385 { 382 {
386 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 383 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
387 setShouldAutoplay(false); // No autoplay attribute. 384 setShouldAutoplay(false); // No autoplay attribute.
388 385
389 EXPECT_CALL(*m_client, removeUserGestureRequirement())
390 .Times(1);
391 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 386 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
392 .Times(1); 387 .Times(1);
393 m_helper->playMethodCalled(); 388 m_helper->playMethodCalled(false);
389 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
394 390
395 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByPlay MethodImmediately)) 391 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByPlay MethodImmediately))
396 .Times(1); 392 .Times(1);
397 startPlaybackWithoutUserGesture(); 393 startPlaybackWithoutUserGesture();
398 394
399 pausePlaybackExpectingBailout(true); 395 pausePlaybackExpectingBailout(true);
400 } 396 }
401 397
402 TEST_F(AutoplayExperimentTest, DeferAutoplayUntilMuted) 398 TEST_F(AutoplayExperimentTest, DeferAutoplayUntilMuted)
403 { 399 {
404 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifmuted", Mo ckAutoplayClient::Video)); 400 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifmuted", Mo ckAutoplayClient::Video));
405 401
406 // Should not override the gesture requirement yet. 402 // Should not override the gesture requirement yet.
407 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 403 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
408 .Times(1); 404 .Times(1);
409 m_helper->becameReadyToPlay(); 405 m_helper->becameReadyToPlay();
410 406
411 // When we toggle the muted attribute, it should start. 407 // When we toggle the muted attribute, it should become eligible to start.
412 EXPECT_CALL(*m_client, removeUserGestureRequirement()) 408 EXPECT_FALSE(m_helper->isGestureRequirementOverridden());
413 .Times(1);
414 EXPECT_CALL(*m_client, playInternal())
415 .Times(1);
416 setIsMuted(true); 409 setIsMuted(true);
417 m_helper->mutedChanged(); 410 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
418
419 // When playback starts (in response to playInternal()), it should also
420 // record why. 'After scroll' isn't the best name, but this isn't a common case.
421 EXPECT_CALL(*m_client, recordAutoplayMetric(GesturelessPlaybackStartedByAuto playFlagAfterScroll))
422 .Times(1);
423 startPlaybackWithoutUserGesture();
424 } 411 }
425 412
426 TEST_F(AutoplayExperimentTest, DeferPlaybackUntilInViewport) 413 TEST_F(AutoplayExperimentTest, DeferPlaybackUntilInViewport)
427 { 414 {
428 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifviewport", MockAutoplayClient::Video)); 415 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifviewport", MockAutoplayClient::Video));
429 416
430 // Should not override the gesture requirement yet. 417 // Should not override the gesture requirement yet.
431 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 418 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
432 .Times(1); 419 .Times(1);
433 EXPECT_CALL(*m_client, setRequestPositionUpdates(true)) 420 EXPECT_CALL(*m_client, setRequestPositionUpdates(true))
434 .Times(1); 421 .Times(1);
435 m_helper->becameReadyToPlay(); 422 m_helper->becameReadyToPlay();
436 423
437 EXPECT_CALL(*m_client, removeUserGestureRequirement())
438 .Times(1);
439 EXPECT_CALL(*m_client, playInternal()) 424 EXPECT_CALL(*m_client, playInternal())
440 .Times(1); 425 .Times(1);
441 EXPECT_CALL(*m_client, setRequestPositionUpdates(false)) 426 EXPECT_CALL(*m_client, setRequestPositionUpdates(false))
442 .Times(1); 427 .Times(1);
443 moveIntoViewport(); 428 moveIntoViewport();
429 EXPECT_TRUE(m_helper->isGestureRequirementOverridden());
444 } 430 }
445 431
446 TEST_F(AutoplayExperimentTest, WithSameOriginTests) 432 TEST_F(AutoplayExperimentTest, WithSameOriginTests)
447 { 433 {
448 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifsameorigin ", MockAutoplayClient::Video)); 434 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifsameorigin ", MockAutoplayClient::Video));
449 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false)); 435 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false));
450 EXPECT_TRUE(isEligible()); 436 EXPECT_TRUE(isEligible());
451 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true)); 437 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true));
452 EXPECT_FALSE(isEligible()); 438 EXPECT_FALSE(isEligible());
453 } 439 }
(...skipping 12 matching lines...) Expand all
466 setInterface(new NiceMock<MockAutoplayClient>("enabled-foraudio-ifpagevisibl e", MockAutoplayClient::Audio)); 452 setInterface(new NiceMock<MockAutoplayClient>("enabled-foraudio-ifpagevisibl e", MockAutoplayClient::Audio));
467 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit yStateVisible)); 453 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit yStateVisible));
468 EXPECT_TRUE(isEligible()); 454 EXPECT_TRUE(isEligible());
469 EXPECT_TRUE(meetsVisibilityRequirements()); 455 EXPECT_TRUE(meetsVisibilityRequirements());
470 456
471 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit yStateHidden)); 457 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit yStateHidden));
472 EXPECT_TRUE(isEligible()); 458 EXPECT_TRUE(isEligible());
473 EXPECT_FALSE(meetsVisibilityRequirements()); 459 EXPECT_FALSE(meetsVisibilityRequirements());
474 } 460 }
475 461
462 TEST_F(AutoplayExperimentTest, PlayTwiceIsIgnored)
463 {
464 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
465 setShouldAutoplay(false); // No autoplay attribute.
466
467 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
468 .Times(1);
469 m_helper->playMethodCalled(false);
470 m_helper->playMethodCalled(true);
476 } 471 }
472
473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698