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

Side by Side Diff: third_party/WebKit/Source/core/html/AutoplayExperimentTest.cpp

Issue 1938443002: Allow muted third-party autoplay with -ormuted experiment option. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed unused flag. 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 virtual ~MockAutoplayClient() {} 77 virtual ~MockAutoplayClient() {}
78 78
79 MOCK_CONST_METHOD0(currentTime, double()); 79 MOCK_CONST_METHOD0(currentTime, double());
80 MOCK_CONST_METHOD0(duration, double()); 80 MOCK_CONST_METHOD0(duration, double());
81 MOCK_CONST_METHOD0(paused, bool()); 81 MOCK_CONST_METHOD0(paused, bool());
82 MOCK_CONST_METHOD0(ended, bool()); 82 MOCK_CONST_METHOD0(ended, bool());
83 MOCK_CONST_METHOD0(muted, bool()); 83 MOCK_CONST_METHOD0(muted, bool());
84 MOCK_METHOD1(setMuted, void(bool)); 84 MOCK_METHOD1(setMuted, void(bool));
85 MOCK_METHOD0(playInternal, void()); 85 MOCK_METHOD0(playInternal, void());
86 MOCK_METHOD0(pauseInternal, void());
86 MOCK_CONST_METHOD0(isLockedPendingUserGesture, bool()); 87 MOCK_CONST_METHOD0(isLockedPendingUserGesture, bool());
87 MOCK_METHOD0(unlockUserGesture, void()); 88 MOCK_METHOD0(unlockUserGesture, void());
88 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics)); 89 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics));
89 MOCK_METHOD0(shouldAutoplay, bool()); 90 MOCK_METHOD0(shouldAutoplay, bool());
90 MOCK_CONST_METHOD0(isHTMLVideoElement, bool()); 91 MOCK_CONST_METHOD0(isHTMLVideoElement, bool());
91 MOCK_CONST_METHOD0(isHTMLAudioElement, bool()); 92 MOCK_CONST_METHOD0(isHTMLAudioElement, bool());
92 MOCK_METHOD0(isLegacyViewportType, bool()); 93 MOCK_METHOD0(isLegacyViewportType, bool());
93 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState()); 94 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState());
94 MOCK_CONST_METHOD0(autoplayExperimentMode, String()); 95 MOCK_CONST_METHOD0(autoplayExperimentMode, String());
95 MOCK_CONST_METHOD0(isCrossOrigin, bool()); 96 MOCK_CONST_METHOD0(isCrossOrigin, bool());
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video)); 468 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl ayClient::Video));
468 setShouldAutoplay(false); // No autoplay attribute. 469 setShouldAutoplay(false); // No autoplay attribute.
469 470
470 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound)) 471 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
471 .Times(1); 472 .Times(1);
472 m_helper->playMethodCalled(); 473 m_helper->playMethodCalled();
473 ON_CALL(*m_client, paused()).WillByDefault(Return(false)); 474 ON_CALL(*m_client, paused()).WillByDefault(Return(false));
474 m_helper->playMethodCalled(); 475 m_helper->playMethodCalled();
475 } 476 }
476 477
478 TEST_F(AutoplayExperimentTest, CrossOriginMutedTests)
479 {
480 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifsameorigin -ormuted", MockAutoplayClient::Video));
481 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true));
482
483 // Cross-orgin unmuted content should be eligible.
484 setIsMuted(true);
485 EXPECT_TRUE(isEligible());
486
487 // Cross-origin muted content should not be eligible.
488 setIsMuted(false);
489 EXPECT_FALSE(isEligible());
490
491 // Start playback.
492 EXPECT_CALL(*m_client, recordAutoplayMetric(AutoplayMediaFound))
493 .Times(1);
494 m_helper->becameReadyToPlay();
495 ON_CALL(*m_client, paused()).WillByDefault(Return(false));
496 setIsMuted(true);
497 m_helper->mutedChanged();
498
499 // Verify that unmuting pauses playback.
500 setIsMuted(false);
501 EXPECT_CALL(*m_client, pauseInternal())
502 .Times(1);
503 m_helper->mutedChanged();
477 } 504 }
505
506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698