content/media/webaudio/test/test_OfflineAudioContext.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test OfflineAudioContext</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="webaudio.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8 </head>
     9 <body>
    10 <pre id="test">
    11 <script class="testbody" type="text/javascript">
    13 SimpleTest.waitForExplicitFinish();
    14 addLoadEvent(function() {
    15   var ctx = new OfflineAudioContext(2, 100, 22050);
    16   ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
    18   var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
    19   for (var i = 0; i < 2; ++i) {
    20     for (var j = 0; j < 100; ++j) {
    21       buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate);
    22     }
    23   }
    25   expectException(function() {
    26     ctx.createMediaStreamDestination();
    27   }, DOMException.NOT_SUPPORTED_ERR);
    29   expectException(function() {
    30     new OfflineAudioContext(2, 100, 0);
    31   }, DOMException.NOT_SUPPORTED_ERR);
    32   expectException(function() {
    33     new OfflineAudioContext(2, 100, -1);
    34   }, DOMException.NOT_SUPPORTED_ERR);
    35   expectException(function() {
    36     new OfflineAudioContext(0, 100, 44100);
    37   }, DOMException.NOT_SUPPORTED_ERR);
    38   new OfflineAudioContext(32, 100, 44100);
    39   expectException(function() {
    40     new OfflineAudioContext(33, 100, 44100);
    41   }, DOMException.NOT_SUPPORTED_ERR);
    42   expectException(function() {
    43     new OfflineAudioContext(2, 0, 44100);
    44   }, DOMException.NOT_SUPPORTED_ERR);
    46   var src = ctx.createBufferSource();
    47   src.buffer = buf;
    48   src.start(0);
    49   src.connect(ctx.destination);
    50   ctx.startRendering();
    51   ctx.addEventListener("complete", function(e) {
    52     ok(e instanceof OfflineAudioCompletionEvent, "Correct event received");
    53     is(e.renderedBuffer.numberOfChannels, 2, "Correct expected number of buffers");
    54     compareBuffers(e.renderedBuffer, buf);
    56     expectException(function() {
    57       ctx.startRendering();
    58     }, DOMException.INVALID_STATE_ERR);
    60     SimpleTest.finish();
    61   }, false);
    62 });
    64 </script>
    65 </pre>
    66 </body>
    67 </html>

mercurial