gecko/content/media/test/test_streams_element_capture_reset.html
2012-09-24 15:47:30 +12:00

100 lines
3.6 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test that reloading and seeking in a media element that's being captured doesn't crash</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<video id="v"></video>
<video id="vout"></video>
<video id="vout_untilended"></video>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var v = document.getElementById('v');
var vout = document.getElementById('vout');
var vout_untilended = document.getElementById('vout_untilended');
vout.mozSrcObject = v.mozCaptureStream();
vout_untilended.mozSrcObject = v.mozCaptureStreamUntilEnded();
function dumpEvent(event) {
dump("GOT EVENT " + event.type + " currentTime=" + event.target.currentTime +
" paused=" + event.target.paused + " ended=" + event.target.ended +
" readyState=" + event.target.readyState + "\n");
}
var events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
for (var i = 0; i < events.length; ++i) {
v.addEventListener(events[i], dumpEvent, false);
}
function isWithinEps(a, b, msg) {
ok(Math.abs(a - b) < 0.01,
"Got " + a + ", expected " + b + "; " + msg);
}
function startTest(test) {
var seekTime = test.duration/2;
function endedAfterReplay() {
isWithinEps(v.currentTime, test.duration, "checking v.currentTime at third 'ended' event");
isWithinEps(vout.currentTime, (v.currentTime - seekTime) + test.duration*2,
"checking vout.currentTime after seeking, playing through and reloading");
SimpleTest.finish();
};
function endedAfterSeek() {
isWithinEps(v.currentTime, test.duration, "checking v.currentTime at second 'ended' event");
isWithinEps(vout.currentTime, (v.currentTime - seekTime) + test.duration,
"checking vout.currentTime after seeking and playing through again");
v.removeEventListener("ended", endedAfterSeek, false);
v.addEventListener("ended", endedAfterReplay, false);
v.src = test.name + "?1";
v.play();
};
function seeked() {
isWithinEps(v.currentTime, seekTime, "Finished seeking");
isWithinEps(vout.currentTime, test.duration,
"checking vout.currentTime has not changed after seeking");
v.removeEventListener("seeked", seeked, false);
function dontPlayAgain() {
ok(false, "vout_untilended should not play again");
}
vout_untilended.addEventListener("playing", dontPlayAgain, false);
vout_untilended.addEventListener("ended", dontPlayAgain, false);
v.addEventListener("ended", endedAfterSeek, false);
v.play();
};
function ended() {
isWithinEps(vout.currentTime, test.duration, "checking vout.currentTime at first 'ended' event");
isWithinEps(v.currentTime, test.duration, "checking v.currentTime at first 'ended' event");
is(vout.ended, false, "checking vout has not ended");
is(vout_untilended.ended, true, "checking vout_untilended has actually ended");
vout_untilended.removeEventListener("ended", ended, false);
v.pause();
v.currentTime = seekTime;
v.addEventListener("seeked", seeked, false);
};
vout_untilended.addEventListener("ended", ended, false);
v.src = test.name;
v.play();
function checkNoEnded() {
ok(false, "ended event received unexpectedly");
};
vout.addEventListener("ended", checkNoEnded, false);
vout.play();
vout_untilended.play();
}
var testVideo = getPlayableVideo(gSmallTests);
if (testVideo) {
startTest(testVideo);
} else {
todo(false, "No playable video");
}
</script>
</pre>
</body>
</html>