<!DOCTYPE html>
<title>Test behavior of HTMLMediaElements with the media-playback-while-not-rendered permission policy</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<body>
<iframe id="video-iframe" allow="media-playback-while-not-visible 'none'; autoplay *" srcdoc="<!DOCTYPE html><video autoplay loop></video>"></iframe>
<iframe id="audio-iframe" allow="media-playback-while-not-visible 'none'; autoplay *" srcdoc="<!DOCTYPE html><audio autoplay loop></audio>"></iframe>
<script>
internals.settings.setAutoplayPolicy('no-user-gesture-required');
console.log(internals.runtimeFlags.mediaPlaybackWhileNotVisiblePermissionPolicyEnabled)
async_test(function(t) {
let iframe = document.getElementById('video-iframe');
iframe.onload = t.step_func(function() {
let video = iframe.contentDocument.querySelector("video")
assert_true(video.paused);
video.addEventListener('playing', t.step_func(function() {
assert_false(video.paused);
// Hiding the iframe should pause the embedded video element playback.
iframe.style.setProperty('display', 'none');
video.addEventListener('pause', t.step_func(function() {
assert_true(video.paused);
video.play().then(t.unreached_func("Unrendered video element should not be allowed to play."), (e) => {
assert_true(e.name == 'NotAllowedError');
t.done();
})
}))
}))
video.src = "content/test.ogv"
})
}, "Video playback should pause for hidden iframes when media-playback-while-not-visible permission policy is set");
async_test(function(t) {
let iframe = document.getElementById('audio-iframe');
iframe.onload = t.step_func(function() {
let audio = iframe.contentDocument.querySelector("audio")
assert_true(audio.paused);
audio.addEventListener('playing', t.step_func(function() {
assert_false(audio.paused);
// Hiding the iframe should pause the embedded audio element playback.
iframe.style.setProperty('display', 'none');
audio.addEventListener('pause', t.step_func(function() {
assert_true(audio.paused);
audio.play().then(t.unreached_func("Unrendered audio element should not be allowed to play."), (e) => {
assert_true(e.name == 'NotAllowedError');
t.done();
})
}))
}))
audio.src = "content/test.oga"
})
}, "Audio playback should pause for hidden iframes when media-playback-while-not-visible permission policy is set");
</script>
</body>