Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Audible autoplay videos should not get paused when outside the viewport
https://bugs.webkit.org/show_bug.cgi?id=170610
<rdar://problem/31505984>

Reviewed by Eric Carlson.

Source/WebCore:

Audible autoplay videos should not get paused when outside the viewport as this
would be observable by the user.

Test: media/video-restricted-invisible-autoplay-allowed-if-audible.html

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::autoplayPermitted):

LayoutTests:

Add layout test coverage.

* media/video-restricted-invisible-autoplay-allowed-if-audible-expected.txt: Added.
* media/video-restricted-invisible-autoplay-allowed-if-audible.html: Copied from LayoutTests/media/video-restricted-invisible-autoplay-not-allowed.html.
* media/video-restricted-invisible-autoplay-allowed-when-visible.html:
* media/video-restricted-invisible-autoplay-not-allowed.html:


Canonical link: https://commits.webkit.org/187548@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Apr 7, 2017
1 parent d668b0a commit 3bea2fc
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
2017-04-07 Chris Dumez <cdumez@apple.com>

Audible autoplay videos should not get paused when outside the viewport
https://bugs.webkit.org/show_bug.cgi?id=170610
<rdar://problem/31505984>

Reviewed by Eric Carlson.

Add layout test coverage.

* media/video-restricted-invisible-autoplay-allowed-if-audible-expected.txt: Added.
* media/video-restricted-invisible-autoplay-allowed-if-audible.html: Copied from LayoutTests/media/video-restricted-invisible-autoplay-not-allowed.html.
* media/video-restricted-invisible-autoplay-allowed-when-visible.html:
* media/video-restricted-invisible-autoplay-not-allowed.html:

2017-04-07 Chris Dumez <cdumez@apple.com>

Throttle / Align DOM Timers in cross-origin iframes to 30fps
Expand Down
@@ -0,0 +1,18 @@

Test that "invisible autoplay not allowed restriction" does not pause audible media when scrolled out of view.

** setting video.src

EVENT(play)
EXPECTED (video.paused == 'false') OK
RUN(video.style.display = "none")
EXPECTED (video.paused == 'false') OK
RUN(video.style.removeProperty("display"))
RUN(video.style.visibility = "hidden")
EXPECTED (video.paused == 'false') OK
RUN(video.style.removeProperty("visibility"))
RUN(document.documentElement.style.height = window.innerHeight + 20 + video.offsetHeight)
RUN(window.scrollBy(0, 20 + video.offsetHeight))
EXPECTED (video.paused == 'false') OK
END OF TEST

@@ -0,0 +1,58 @@
<html>
<head>
<script src="media-file.js"></script>
<script src="video-test.js"></script>
<script>
if (window.internals)
internals.settings.setInvisibleAutoplayNotPermitted(true);

function start()
{
findMediaElement();
consoleWrite('** setting video.src');
video.src = findMediaFile('video', 'content/test');
video.volume = 1;

waitForEventOnce('play', play1);
consoleWrite('');
}

function play1()
{
waitForEventAndFail('pause');

testExpected('video.paused', false);
run('video.style.display = "none"');
setTimeout(play2, 10);
}

function play2()
{
testExpected('video.paused', false);
run('video.style.removeProperty("display")');
run('video.style.visibility = "hidden"');
setTimeout(play3, 10);
}

function play3()
{
testExpected('video.paused', false);
run('video.style.removeProperty("visibility")');
run('document.documentElement.style.height = window.innerHeight + 20 + video.offsetHeight');
run('window.scrollBy(0, 20 + video.offsetHeight)');
setTimeout(play4, 10);
}

function play4()
{
testExpected('video.paused', false);
endTest();
}
</script>
</head>

<body onload="start()">
<video controls autoplay></video>
<p>Test that "invisible autoplay not allowed restriction" does not pause audible media when scrolled out of view.</p>
</body>
</html>
Expand Up @@ -8,6 +8,7 @@
video = document.createElement('video');
run('internals.setMediaElementRestrictions(video, "InvisibleAutoplayNotPermitted")');
video.autoplay = true;
video.volume = 0;
consoleWrite('** setting video.src');
video.src = findMediaFile('video', 'content/test');

Expand Down
Expand Up @@ -11,6 +11,7 @@
findMediaElement();
consoleWrite('** setting video.src');
video.src = findMediaFile('video', 'content/test');
video.volume = 0;

waitForEventOnce('play', play1);
consoleWrite('');
Expand Down
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2017-04-07 Chris Dumez <cdumez@apple.com>

Audible autoplay videos should not get paused when outside the viewport
https://bugs.webkit.org/show_bug.cgi?id=170610
<rdar://problem/31505984>

Reviewed by Eric Carlson.

Audible autoplay videos should not get paused when outside the viewport as this
would be observable by the user.

Test: media/video-restricted-invisible-autoplay-allowed-if-audible.html

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::autoplayPermitted):

2017-04-07 Myles C. Maxfield <mmaxfield@apple.com>

REGRESSION(r211382): Complex text with justification erroneously overflows containers
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/html/MediaElementSession.cpp
Expand Up @@ -193,6 +193,10 @@ bool MediaElementSession::autoplayPermitted() const
if (!hasBehaviorRestriction(MediaElementSession::InvisibleAutoplayNotPermitted))
return true;

// If the media element is audible, allow autoplay even when not visible as pausing it would be observable by the user.
if ((!m_element.isVideo() || m_element.hasAudio()) && !m_element.muted() && m_element.volume())
return true;

auto* renderer = m_element.renderer();
if (!renderer)
return false;
Expand Down

0 comments on commit 3bea2fc

Please sign in to comment.