2012-04-30 07:13:01 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test that a MediaStream captured from one element plays back in another</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>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2015-09-01 01:47:48 +03:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2015-04-29 04:55:15 +03:00
|
|
|
|
|
|
|
// longer timeout for slow platforms
|
|
|
|
if (isSlowPlatform()) {
|
|
|
|
SimpleTest.requestLongerTimeout(3);
|
|
|
|
SimpleTest.requestCompleteLog();
|
|
|
|
}
|
|
|
|
|
2012-04-30 07:13:01 +04:00
|
|
|
function checkDrawImage(vout) {
|
|
|
|
var canvas = document.createElement("canvas");
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(vout, 0, 0);
|
|
|
|
var imgData = ctx.getImageData(0, 0, 1, 1);
|
|
|
|
is(imgData.data[3], 255, "Check video frame pixel has been drawn");
|
|
|
|
}
|
|
|
|
|
2015-09-01 01:47:48 +03:00
|
|
|
function isGreaterThanOrEqualEps(a, b, msg) {
|
|
|
|
ok(a >= b - 0.01,
|
|
|
|
"Got " + a + ", expected at least " + b + "; " + msg);
|
|
|
|
}
|
2012-04-30 07:13:01 +04:00
|
|
|
|
2015-09-01 01:47:48 +03:00
|
|
|
function startTest(test) {
|
2012-04-30 07:13:01 +04:00
|
|
|
var v = document.createElement('video');
|
|
|
|
var vout = document.createElement('video');
|
|
|
|
|
|
|
|
v.src = test.name;
|
2016-08-15 09:37:01 +03:00
|
|
|
var stream;
|
2012-04-30 07:13:01 +04:00
|
|
|
|
2016-08-15 09:37:01 +03:00
|
|
|
var checkEnded = function() {
|
2012-04-30 07:13:01 +04:00
|
|
|
is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime");
|
|
|
|
if (test.duration) {
|
2015-09-01 01:47:48 +03:00
|
|
|
isGreaterThanOrEqualEps(vout.currentTime, test.duration,
|
|
|
|
test.name + " current time at end");
|
2012-04-30 07:13:01 +04:00
|
|
|
}
|
|
|
|
is(vout.readyState, vout.HAVE_CURRENT_DATA, test.name + " checking readyState");
|
|
|
|
ok(vout.ended, test.name + " checking playback has ended");
|
|
|
|
if (test.type.match(/^video/)) {
|
|
|
|
checkDrawImage(vout);
|
|
|
|
}
|
2017-01-30 10:10:22 +03:00
|
|
|
vout.remove();
|
2015-02-03 03:05:00 +03:00
|
|
|
removeNodeAndSource(v);
|
2015-09-01 01:47:48 +03:00
|
|
|
SimpleTest.finish();
|
2016-08-15 09:37:01 +03:00
|
|
|
};
|
2017-01-17 13:50:25 +03:00
|
|
|
vout.addEventListener("ended", checkEnded);
|
2012-04-30 07:13:01 +04:00
|
|
|
|
|
|
|
document.body.appendChild(vout);
|
2016-08-15 09:37:01 +03:00
|
|
|
|
|
|
|
var onloadedmetadata = function (ev) {
|
|
|
|
stream = v.mozCaptureStreamUntilEnded();
|
|
|
|
is(stream.currentTime, 0, test.name + " stream initial currentTime");
|
|
|
|
vout.srcObject = stream;
|
|
|
|
is(vout.srcObject, stream, test.name + " set output element .srcObject correctly");
|
|
|
|
v.play();
|
|
|
|
vout.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
v.preload = 'metadata';
|
2017-01-17 13:50:25 +03:00
|
|
|
v.addEventListener('loadedmetadata', onloadedmetadata);
|
2015-01-26 20:52:00 +03:00
|
|
|
|
|
|
|
// Log events for debugging.
|
|
|
|
var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
|
|
|
|
"loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
|
|
|
|
"waiting", "pause"];
|
|
|
|
function logEvent(e) {
|
2015-04-29 04:55:15 +03:00
|
|
|
Log(e.target.name, "got " + e.type);
|
2015-01-26 20:52:00 +03:00
|
|
|
}
|
|
|
|
events.forEach(function(e) {
|
2017-01-17 13:50:25 +03:00
|
|
|
v.addEventListener(e, logEvent);
|
|
|
|
vout.addEventListener(e, logEvent);
|
2015-01-26 20:52:00 +03:00
|
|
|
});
|
|
|
|
|
2012-04-30 07:13:01 +04:00
|
|
|
}
|
|
|
|
|
2015-09-01 01:47:48 +03:00
|
|
|
// We only test one playable video because for some of the audio files
|
|
|
|
// --- small-shot.mp3.mp4 and small-shot.m4a --- GStreamer doesn't decode
|
|
|
|
// as much data as indicated by the duration, causing this test to fail on
|
|
|
|
// Linux. See bug 1084185.
|
|
|
|
var testVideo = getPlayableVideo(gSmallTests);
|
|
|
|
if (testVideo) {
|
|
|
|
startTest(testVideo);
|
|
|
|
} else {
|
|
|
|
todo(false, "No playable video");
|
|
|
|
}
|
2012-04-30 07:13:01 +04:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|