summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_temporary_file_blob_video_plays.html
blob: 87f6b3c4e6f3df7f93db5d9da1d6ad82bac584b3 (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
73
74
75
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Recording canvas stream</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/dom/canvas/test/captureStream_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<div id="content">
</div>
<script class="testbody" type="text/javascript">

function startTest() {
  var canvas = document.createElement("canvas");
  canvas.width = canvas.height = 100;
  document.getElementById("content").appendChild(canvas);

  var helper = new CaptureStreamTestHelper2D(100, 100);
  helper.drawColor(canvas, helper.red);

  var stream = canvas.captureStream(0);

  var blob;

  let mediaRecorder = new MediaRecorder(stream);
  is(mediaRecorder.stream, stream,
     "Media recorder stream = canvas stream at the start of recording");

  mediaRecorder.onwarning = () => ok(false, "warning unexpectedly fired");

  mediaRecorder.onerror = () => ok(false, "Recording failed");

  mediaRecorder.ondataavailable = ev => {
    is(blob, undefined, "Should only get one dataavailable event");
    blob = ev.data;
  };

  mediaRecorder.onstart = () => {
    info("Got 'start' event");
    // We just want one frame encoded, to see that the recorder produces something readable.
    mediaRecorder.stop();
  };

  mediaRecorder.onstop = () => {
    info("Got 'stop' event");
    ok(blob, "Should have gotten a data blob");

    var video = document.createElement("video");
    video.id = "recorded-video";
    video.src = URL.createObjectURL(blob);
    video.play();
    video.onerror = err => {
      ok(false, "Should be able to play the recording. Got error. code=" + video.error.code);
      SimpleTest.finish();
    };
    document.getElementById("content").appendChild(video);
    helper.pixelMustBecome(video, helper.red, {
      threshold: 128,
      infoString: "Should become red",
    }).then(SimpleTest.finish);
  };

  mediaRecorder.start();
  is(mediaRecorder.state, "recording", "Media recorder should be recording");
}

SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({set:[["media.recorder.max_memory", 1]]}, startTest);

</script>
</pre>
</body>
</html>