haikuwebkit/LayoutTests/media/audio-playback-restriction-...

40 lines
985 B
HTML
Raw Permalink Normal View History

Add a setting & restriction which prevents non-interactivte playback of audible media elements. https://bugs.webkit.org/show_bug.cgi?id=143486 Reviewed by Eric Carlson. Source/WebCore: Tests: media/audio-playback-restriction-autoplay.html media/audio-playback-restriction-play.html To allow clients who want to allow non-user-interactive video-only playback, but still restrict playback of audible media elements, add a new setting and matching restriction which disallows playback of media elements containing audible characteristics. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Set the RequireUserGestureForAudioRateChange restriction if the audioPlaybackRequiresUserGesture() setting is set. (WebCore::HTMLMediaElement::parseAttribute): Drive-by fix. Move the opening brace out of the #if, as this confuses the heck out of diff and makes all subsequent changes appear to be within HTMLMediaElement::parseAttribute. (WebCore::HTMLMediaElement::autoplay): Remove the restriction check from within autoplay(). It is checked again immediately after every autoplay() call site. (WebCore::HTMLMediaElement::pauseInternal): Remove the iOS-only #if. (WebCore::HTMLMediaElement::mediaPlayerDidAddAudioTrack): Check whether playback is permitted, and if not, pause. (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged): Ditto. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Ditto. * html/HTMLMediaSession.cpp: (WebCore::restrictionName): Since BehaviorRestrictions is a bitfield, check each bit individually. (WebCore::HTMLMediaSession::removeBehaviorRestriction): Handle RequireUserGestureForAudioRateChange. (WebCore::HTMLMediaSession::playbackPermitted): Check whether the element has audio and audio playback is restricted, and return false if so. * html/HTMLMediaSession.h: * page/Settings.cpp: * page/Settings.in: * testing/Internals.cpp: (WebCore::Internals::setMediaSessionRestrictions): Added. (WebCore::Internals::setMediaElementRestrictions): Added. * testing/Internals.h: * testing/Internals.idl: LayoutTests: * media/audio-playback-restriction-autoplay.html: Added. * media/audio-playback-restriction-play.html: Added. * media/video-test.js: (setCaptionDisplayMode): (runWithKeyDown.eventName.window.testRunner.eventSender.keyDown.string_appeared_here.string_appeared_here.thunk): (runWithKeyDown): Canonical link: https://commits.webkit.org/162292@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183428 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-27 22:08:43 +00:00
<!DOCTYPE html>
<html>
<head>
<title>audio-playback-restriction</title>
<script src=media-file.js></script>
<script src=video-test.js></script>
<script>
function runTest()
{
video = document.getElementsByTagName('audio')[0];
if (window.internals)
run('internals.setMediaElementRestrictions(video, "RequireUserGestureForAudioRateChange")');
waitForEventAndFail('error');
waitForEvent('canplaythrough', canplaythrough);
run("video.src = findMediaFile('audio', 'content/test')");
}
function canplaythrough()
{
run("setTimeout(timeout, 100)");
}
function timeout()
{
testExpected('video.paused', true);
endTest();
}
</script>
</head>
<body onload="runTest()">
<p>Test that, when RequireUserGestureForAudioRateChange is set, starting playback of an audio file requires a user gesture.</p>
<audio controls autoplay></audio>
</body>
</html>