content/media/test/test_streams_element_capture_createObjectURL.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_streams_element_capture_createObjectURL.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test that a MediaStream captured from one element plays back in another</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +  <script type="text/javascript" src="manifest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +SimpleTest.waitForExplicitFinish();
    1.16 +
    1.17 +var manager = new MediaTestManager;
    1.18 +
    1.19 +function checkDrawImage(vout) {
    1.20 +  var canvas = document.createElement("canvas");
    1.21 +  var ctx = canvas.getContext("2d");
    1.22 +  ctx.drawImage(vout, 0, 0);
    1.23 +  var imgData = ctx.getImageData(0, 0, 1, 1);
    1.24 +  is(imgData.data[3], 255, "Check video frame pixel has been drawn");
    1.25 +}
    1.26 +
    1.27 +function startTest(test, token) {
    1.28 +  manager.started(token);
    1.29 +
    1.30 +  var v = document.createElement('video');
    1.31 +  var vout = document.createElement('video');
    1.32 +  vout.token = token;
    1.33 +
    1.34 +  v.src = test.name;
    1.35 +  var stream = v.mozCaptureStreamUntilEnded();
    1.36 +  is(stream.currentTime, 0, test.name + " stream initial currentTime");
    1.37 +  vout.src = URL.createObjectURL(stream);
    1.38 +
    1.39 +  var checkEnded = function(test, vout, stream) { return function() {
    1.40 +    is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime");
    1.41 +    if (test.duration) {
    1.42 +      ok(Math.abs(vout.currentTime - test.duration) < 0.1,
    1.43 +         test.name + " current time at end: " + vout.currentTime + " should be: " + test.duration);
    1.44 +    }
    1.45 +    is(vout.readyState, vout.HAVE_CURRENT_DATA, test.name + " checking readyState");
    1.46 +    ok(vout.ended, test.name + " checking playback has ended");
    1.47 +    if (test.type.match(/^video/)) {
    1.48 +      checkDrawImage(vout);
    1.49 +    }
    1.50 +    vout.parentNode.removeChild(vout);
    1.51 +    URL.revokeObjectURL(vout.src);
    1.52 +    manager.finished(vout.token);
    1.53 +  }}(test, vout, stream);
    1.54 +  vout.addEventListener("ended", checkEnded, false);
    1.55 +
    1.56 +  document.body.appendChild(vout);
    1.57 +  v.play();
    1.58 +  vout.play();
    1.59 +}
    1.60 +
    1.61 +manager.runTests([getPlayableVideo(gSmallTests)], startTest);
    1.62 +</script>
    1.63 +</pre>
    1.64 +</body>
    1.65 +</html>

mercurial