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

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

Powered by Google App Engine
This is Rietveld 408576698