77 lines
2.6 KiB
HTML
77 lines
2.6 KiB
HTML
<html>
|
|
<head>
|
|
<script src=media-file.js></script>
|
|
<script src=video-test.js></script>
|
|
<script>
|
|
var state = 0;
|
|
var retryCount = 0;
|
|
const maxRetryCount = 10;
|
|
|
|
function checkState()
|
|
{
|
|
switch (state) {
|
|
case "background":
|
|
if (!video.paused) {
|
|
if (++retryCount >= maxRetryCount)
|
|
failTest(`Video did not pause after switching to backgound.`);
|
|
else
|
|
setTimeout(checkState, 100);
|
|
return;
|
|
}
|
|
|
|
testExpected("video.paused", true);
|
|
state = "foreground";
|
|
consoleWrite("<br>** Simulate switch back to foreground, video should remain paused.");
|
|
run("internals.applicationWillEnterForeground()");
|
|
setTimeout(checkState, 100);
|
|
consoleWrite("");
|
|
break;
|
|
case "foreground":
|
|
testExpected("video.paused", true);
|
|
consoleWrite("");
|
|
testRunner.resetPageVisibility();
|
|
endTest();
|
|
break;
|
|
}
|
|
}
|
|
|
|
function playing(evt)
|
|
{
|
|
consoleWrite("<br>** Simulate switching the tab to background, video should pause.");
|
|
run("testRunner.setPageVisibility('hidden')");
|
|
setTimeout(checkState, 100);
|
|
state = "background";
|
|
consoleWrite("");
|
|
}
|
|
|
|
function canplaythrough(evt)
|
|
{
|
|
consoleWrite("");
|
|
run("video.play()");
|
|
}
|
|
|
|
function start()
|
|
{
|
|
if (!window.internals) {
|
|
failTest('This test requires window.internals.');
|
|
return;
|
|
}
|
|
|
|
findMediaElement();
|
|
video.src = findMediaFile("video", "content/test");
|
|
waitForEvent('canplaythrough', canplaythrough);
|
|
waitForEvent('playing', playing);
|
|
|
|
run("internals.setMediaSessionRestrictions('videoaudio', 'BackgroundTabPlaybackRestricted')");
|
|
state = "foreground";
|
|
consoleWrite("");
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body onload="start()">
|
|
<video controls></video>
|
|
<p>Test tab with <video> moving to background when playback is not allowed in background.</p>
|
|
</body>
|
|
</html>
|