haikuwebkit/LayoutTests/media/video-page-visibility-restr...

38 lines
1.1 KiB
HTML
Raw Permalink Normal View History

[iOS] All home screen web apps resume when any home screen web app is foregrounded https://bugs.webkit.org/show_bug.cgi?id=228246 <rdar://72949281> Reviewed by Eric Carlson. Source/WebCore: Test: media/video-page-visibility-restriction.html On iOS, home screen web apps all run from the same UIProcess, SafariViewService. So when one Web App is foregrounded, the SafariViewService itself is foregrounded, and all WKWebViews (one for each Web App) are foregrounded as well, allowing all Web Apps to resume audio playback. This is not ideal; ideally, all Web Apps will be allowed to continue to play audio in the background. But until we can fix that bug, the current behavior of pausing audio from Web App A when A is backgrounded, and resuming audio from A when Web App B is foregrounded feels super broken. Add a new WKPreference/WebPreference/Setting and matching MediaElementSession restriction that will block playback of audible media elements when the media element's page is not visible. When adopted by SafariViewService, this would keep multiple Web Apps (and indeed SafariViewController pages) from starting playback when any other is foregrounded. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::initializeMediaSession): (WebCore::HTMLMediaElement::visibilityStateChanged): * html/MediaElementSession.cpp: (WebCore::MediaElementSession::visibilityChanged): (WebCore::MediaElementSession::playbackStateChangePermitted const): * html/MediaElementSession.h: * platform/audio/PlatformMediaSession.h: * testing/Internals.cpp: (WebCore::Internals::setMediaElementRestrictions): Source/WebKit: Add a private WKPreference for setting the new WebPreference. * UIProcess/API/Cocoa/WKPreferences.mm: (-[WKPreferences _requiresPageVisibilityToPlayAudio]): (-[WKPreferences _setRequiresPageVisibilityToPlayAudio:]): * UIProcess/API/Cocoa/WKPreferencesPrivate.h: Source/WTF: * Scripts/Preferences/WebPreferences.yaml: LayoutTests: * media/video-page-visibility-restriction-expected.txt: Added. * media/video-page-visibility-restriction.html: Added. Canonical link: https://commits.webkit.org/239951@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-26 17:51:09 +00:00
<html>
<head>
<script src=media-file.js></script>
<script src=video-test.js></script>
<script>
window.addEventListener('load', async event => {
if (!window.internals) {
failTest('This test requires window.internals.');
return;
}
findMediaElement();
run('internals.setMediaElementRestrictions(video, "RequirePageVisibilityToPlayAudio")');
run('video.src = findMediaFile("video", "content/test")');
await waitFor(video, 'canplaythrough');
run('internals.setPageVisibility(false)');
run('promise = video.play()');
await shouldReject(promise);
run('internals.setPageVisibility(true)');
run('promise = video.play()');
await shouldResolve(promise);
run('internals.setPageVisibility(false)');
await waitFor(video, 'pause');
endTest();
});
</script>
</head>
<body>
<video controls loop></video>
</body>
</html>