content/media/test/test_bug879717.html
author Andreas Pehrson <pehrsons@gmail.com>
Mon, 06 Oct 2014 11:22:55 +0200
changeset 209019 353aee81348432381174cb0957fc8f84661dc8c1
permissions -rw-r--r--
Bug 879717: Part 4 - Add mochitest for bug 879717 r=roc

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for bug 879717, check that a video element can be drawn into a canvas directly on 'play' event</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="v1" autoplay />
<video id="v2" autoplay />
<canvas id="c1" />
<canvas id="c2" />
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();

var media = getPlayableVideo(gSmallTests);

var checkDrawImage = function(video, canvas, name) {
  var exception = null;
  var exceptionName = "nothing";
  try {
    var ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
  } catch (e) {
    exception = e;
    exceptionName = e.name;
  }
  ok(exception === null || video.ended,
    "drawImage shouldn't throw an exception on play of " + name + ", got " + exceptionName);
};

if (media == null) {
  todo(false, "No media supported.");
  SimpleTest.finish();
} else {
  v1.src = media.name;
  v2.mozSrcObject = v1.mozCaptureStream();

  var v1Tested = false;
  var v2Tested = false;

  v1.addEventListener('play', function() {
    checkDrawImage(v1, c1, media.name);

    v1Tested = true;
    if (v2Tested) {
      SimpleTest.finish();
    }
  });

  v2.addEventListener('play', function() {
    checkDrawImage(v2, c2, "stream of " + media.name);

    v2Tested = true;
    if (v1Tested) {
      SimpleTest.finish();
    }
  });
}
</script>
</pre>
</body>
</html>