summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_mediarecorder_creation_fail.html
blob: 903bf1cc70c53a1be4c8cbd2ce0d99c59d483053 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record with media.ogg.enabled = false</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">

function startTest() {
  // the expect sequence should be
  // 1. onerror
  // 2. ondataavailable
  // 3. onstop
  var callbackStep = 0;
  var stream = new AudioContext().createMediaStreamDestination().stream;
  var mediaRecorder = new MediaRecorder(stream);

  mediaRecorder.onerror = function (e) {
    is(callbackStep, 0, 'should fired onstop callback');
    is(e.name, 'GenericError', 'error name should be GenericError');
    is(mediaRecorder.mimeType, '', 'mimetype should be empty');
    is(mediaRecorder.state, 'recording', 'state is recording');
    info('onerror callback fired');
    callbackStep = 1;
  };

  mediaRecorder.onwarning = function () {
    ok(false, 'Unexpected onwarning callback fired');
  };

  mediaRecorder.onstop = function () {
    info('onstop callback fired');
    is(mediaRecorder.state, 'inactive', 'state should be inactive');
    is(callbackStep, 2, 'should fired onstop callback');
    SimpleTest.finish();
  };

  // This handler fires every 250ms to generate a blob.
  mediaRecorder.ondataavailable = function (evt) {
    info('ondataavailable callback fired');
    is(callbackStep, 1, 'should fired ondataavailable callback');
    is(evt.data.size, 0, 'data size should be zero');
    ok(evt instanceof BlobEvent,
       'Events fired from ondataavailable should be BlobEvent');
    is(evt.data.type, '', 'encoder start fail, blob miemType should be empty');
    callbackStep = 2;
  };

  // Start recording
  mediaRecorder.start(250);
  is(mediaRecorder.state, 'recording', 'Media recorder should be recording');
  is(mediaRecorder.stream, stream,
     'Media recorder stream = element stream at the start of recording');
}

SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["media.ogg.enabled", false]]}, startTest);

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