tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_decodeAudioError.html (2073B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test the decodeAudioData Errors</title>
      5 
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <script src="webaudio.js"></script>
      9 </head>
     10 <body>
     11 <pre id="test">
     12 <script class="testbody" type="text/javascript">
     13 
     14 SimpleTest.waitForExplicitFinish();
     15 addLoadEvent(function() {
     16 
     17 var finished = 0;
     18 
     19 var ctx = new AudioContext();
     20 
     21 function errorExpectedWithFile(file, errorMsg) {
     22  var xhr = new XMLHttpRequest();
     23  function test(e) {
     24    ok(e instanceof DOMException,
     25      "The exception should be an instance of DOMException");
     26    ok(e.name == "EncodingError",
     27      "The exception name should be EncodingError");
     28    ok(e.message == errorMsg,
     29       "The exception message is not the one intended.\n" +
     30       "\tExpected : " + errorMsg + "\n" +
     31       "\tGot      : " + e.message );
     32    finish();
     33  }
     34  xhr.open("GET", file, true);
     35  xhr.responseType = "arraybuffer";
     36  xhr.onload = function() {
     37    ctx.decodeAudioData(xhr.response, () => {
     38      ok(false, "You should not be able to decode that");
     39      finish();
     40    }, e => test(e))
     41    .then(() => {
     42      ok(false, "You should not be able to decode that");
     43      finish();
     44    })
     45    .catch(e => test(e));
     46  };
     47  xhr.send();
     48 }
     49 
     50 function finish() {
     51  if (++finished == 4) {
     52    SimpleTest.finish();
     53  }
     54 }
     55 
     56 // Unknown Content
     57 errorExpectedWithFile("404", "The buffer passed to decodeAudioData contains an unknown content type.");
     58 
     59 // Invalid Content
     60 errorExpectedWithFile("invalidContent.flac", "The buffer passed to decodeAudioData contains invalid content which cannot be decoded successfully.");
     61 
     62 // No Audio
     63 // # Bug 1656032
     64 // Think about increasing the finish counter to 6 when activating this line
     65 // errorExpectedWithFile("noaudio.webm", "The buffer passed to decodeAudioData does not contain any audio.");
     66 
     67 // Unknown Error
     68 // errorExpectedWithFile("There is no file we can't handle", "An unknown error occurred while processing decodeAudioData.");
     69 });
     70 
     71 </script>
     72 </pre>
     73 </body>
     74 </html>