summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_decodeAudioError.html
blob: f18b971ac418a5f67cd1b403a0a1c9d6e01d4ed8 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test the decodeAudioData Errors</title>

  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script src="webaudio.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {

var finished = 0;

var ctx = new AudioContext();

function errorExpectedWithFile(file, errorMsg) {
  var xhr = new XMLHttpRequest();
  function test(e) {
    ok(e instanceof DOMException,
      "The exception should be an instance of DOMException");
    ok(e.name == "EncodingError",
      "The exception name should be EncodingError");
    ok(e.message == errorMsg,
       "The exception message is not the one intended.\n" +
       "\tExpected : " + errorMsg + "\n" +
       "\tGot      : " + e.message );
    finish();
  }
  xhr.open("GET", file, true);
  xhr.responseType = "arraybuffer";
  xhr.onload = function() {
    ctx.decodeAudioData(xhr.response, buffer => {
      ok(false, "You should not be able to decode that");
      finish();
    }, e => test(e))
    .then(buffer => {
      ok(false, "You should not be able to decode that");
      finish();
    })
    .catch(e => test(e));
  };
  xhr.send();
}

function finish() {
  if (++finished == 4) {
    SimpleTest.finish();
  }
}

// Unknown Content
errorExpectedWithFile("404", "The buffer passed to decodeAudioData contains an unknown content type.");

// Invalid Content
errorExpectedWithFile("invalidContent.flac", "The buffer passed to decodeAudioData contains invalid content which cannot be decoded successfully.");

// No Audio
// # Bug 1656032
// Think about increasing the finish counter to 6 when activating this line
// errorExpectedWithFile("noaudio.webm", "The buffer passed to decodeAudioData does not contain any audio.");

// Unknown Error
// errorExpectedWithFile("There is no file we can't handle", "An unknown error occurred while processing decodeAudioData.");
});

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