summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_streams_element_capture_createObjectURL.html
blob: d952c7142a18c915e34bcc312521caa9c82661be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!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">
SimpleTest.waitForExplicitFinish();

var manager = new MediaTestManager;

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");
}

function isGreaterThanOrEqualEps(a, b, msg) {
  ok(a >= b - 0.01,
     "Got " + a + ", expected at least " + b + "; " + msg);
}

function startTest(test, token) {
  manager.started(token);

  var v = document.createElement('video');
  var vout = document.createElement('video');
  vout.token = token;

  v.src = test.name;
  v.preload = "metadata"
  var stream;

  var checkEnded = function() {
    // We know the video time won't match up to the stream time
    // is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime");
    if (test.duration) {
      isGreaterThanOrEqualEps(vout.currentTime, test.duration,
         test.name + " current time at end");
    }
    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);
    }
    vout.parentNode.removeChild(vout);
    URL.revokeObjectURL(vout.src);
    manager.finished(vout.token);
  };
  vout.addEventListener("ended", checkEnded, false);

  document.body.appendChild(vout);
  v.onloadedmetadata = function () {
    stream = v.mozCaptureStreamUntilEnded();
    is(stream.currentTime, 0, test.name + " stream initial currentTime");
    vout.src = URL.createObjectURL(stream);
    v.play();
    vout.play();
  };
}

manager.runTests([getPlayableVideo(gSmallTests)], startTest);
</script>
</pre>
</body>
</html>