summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_mediarecorder_record_stopms.html
blob: 0dad5ba61796770188d20abccb4e94ba51fe4646 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record Stopped Stream</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<div id="content" style="display: none">
  <audio id="testAudio"></audio>
</div>
<script class="testbody" type="text/javascript">

function startTest() {
  navigator.mozGetUserMedia({audio: true, fake: true}, function(stream) {
    var testAudio = document.getElementById('testAudio');

    testAudio.onended = function() {
      var mediaRecorder = new MediaRecorder(stream);
      try {
        mediaRecorder.start();
        ok(false, 'Recording a stopped stream failed to throw an exception');
      } catch (e) {
        is(e.name, 'InvalidStateError',
           'Recording a stopped stream threw an InvalidStateError');
      } finally {
        SimpleTest.finish();
      }
    };

    testAudio.mozSrcObject = stream;
    testAudio.play();
    stream.stop();
  }, function(err) {
    ok(false, 'Unexpected error fired with: ' + err);
    SimpleTest.finish();
  });
}

SimpleTest.waitForExplicitFinish();
startTest();
</script>
</pre>
</body>
</html>