94 lines
3.2 KiB
HTML
94 lines
3.2 KiB
HTML
<html>
|
|
<head>
|
|
<script src=media-file.js></script>
|
|
<script src=video-test.js></script>
|
|
<script>
|
|
var playCount = 0;
|
|
var playThroughCount = 0;
|
|
var state = 0;
|
|
var audio;
|
|
var video
|
|
|
|
function logEvent(evt)
|
|
{
|
|
consoleWrite("EVENT(" + evt.type + ")");
|
|
}
|
|
|
|
function checkState()
|
|
{
|
|
consoleWrite("<br>** 100ms timer fired...");
|
|
switch (state) {
|
|
case "background":
|
|
testExpected("video.paused", true);
|
|
testExpected("audio.paused", false);
|
|
state = "foreground";
|
|
consoleWrite("<br>** Simulate switch back to foreground, video should resume.");
|
|
run("internals.applicationWillEnterForeground()");
|
|
setTimeout(checkState, 100);
|
|
consoleWrite("");
|
|
break;
|
|
case "foreground":
|
|
testExpected("video.paused", false);
|
|
testExpected("audio.paused", false);
|
|
consoleWrite("");
|
|
endTest();
|
|
break;
|
|
}
|
|
}
|
|
|
|
function playing(evt)
|
|
{
|
|
logEvent(evt);
|
|
if (++playCount != 2)
|
|
return;
|
|
|
|
consoleWrite("<br>** Simulate switch to background, video should pause.");
|
|
run("internals.applicationDidEnterBackground()");
|
|
setTimeout(checkState, 100);
|
|
state = "background";
|
|
consoleWrite("");
|
|
}
|
|
|
|
function canplaythrough(evt)
|
|
{
|
|
logEvent(evt);
|
|
if (++playThroughCount < 2)
|
|
return;
|
|
consoleWrite("");
|
|
run("audio.play()");
|
|
run("video.play()");
|
|
}
|
|
|
|
function start()
|
|
{
|
|
if (!window.internals) {
|
|
failTest('This test requires window.internals.');
|
|
return;
|
|
}
|
|
|
|
var elements = document.getElementsByTagName('video');
|
|
for (var i = 0; i < elements.length; ++i) {
|
|
elements[i].addEventListener("canplaythrough", canplaythrough);
|
|
elements[i].addEventListener('playing', playing);
|
|
elements[i].addEventListener('pause', logEvent);
|
|
}
|
|
video = elements[0];
|
|
video.src = findMediaFile("video", "content/test");
|
|
|
|
audio = elements[1];
|
|
audio.src = findMediaFile("audio", "content/silence");
|
|
|
|
run("internals.setMediaSessionRestrictions('videoaudio', 'BackgroundProcessPlaybackRestricted')");
|
|
state = "foreground";
|
|
consoleWrite("");
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body onload="start()">
|
|
<video controls id="one"></video>
|
|
<video controls id="two"></video>
|
|
<p>Test switching application state when <video> is not allowed to play in background.</p>
|
|
</body>
|
|
</html>
|