content/media/webaudio/test/test_singleSourceDest.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 whether we can create an AudioContext interface</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 context = new AudioContext();
    16   var buffer = context.createBuffer(1, 2048, context.sampleRate);
    17   for (var i = 0; i < 2048; ++i) {
    18     buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
    19   }
    21   var destination = context.destination;
    22   is(destination.context, context, "Destination node has proper context");
    23   is(destination.context, context, "Destination node has proper context");
    24   is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
    25   is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
    26   is(destination.channelCount, 2, "Destination node has 2 input channels by default");
    27   is(destination.channelCountMode, "explicit", "Correct channelCountMode for the destination node");
    28   is(destination.channelInterpretation, "speakers", "Correct channelCountInterpretation for the destination node");
    29   ok(destination instanceof EventTarget, "AudioNodes must be EventTargets");
    31   var source = context.createBufferSource();
    32   is(source.context, context, "Source node has proper context");
    33   is(source.numberOfInputs, 0, "Source node has 0 inputs");
    34   is(source.numberOfOutputs, 1, "Source node has 1 outputs");
    35   is(source.loop, false, "Source node is not looping");
    36   is(source.loopStart, 0, "Correct default value for loopStart");
    37   is(source.loopEnd, 0, "Correct default value for loopEnd");
    38   ok(!source.buffer, "Source node should not have a buffer when it's created");
    39   is(source.channelCount, 2, "source node has 2 input channels by default");
    40   is(source.channelCountMode, "max", "Correct channelCountMode for the source node");
    41   is(source.channelInterpretation, "speakers", "Correct channelCountInterpretation for the source node");
    43   expectException(function() {
    44     source.channelCount = 0;
    45   }, DOMException.NOT_SUPPORTED_ERR);
    47   source.buffer = buffer;
    48   ok(source.buffer, "Source node should have a buffer now");
    50   source.connect(destination);
    52   is(source.numberOfInputs, 0, "Source node has 0 inputs");
    53   is(source.numberOfOutputs, 1, "Source node has 0 outputs");
    54   is(destination.numberOfInputs, 1, "Destination node has 0 inputs");
    55   is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
    57   source.start(0);
    58   SimpleTest.executeSoon(function() {
    59     source.stop(0);
    60     source.disconnect();
    62     SpecialPowers.clearUserPref("media.webaudio.enabled");
    63     SimpleTest.finish();
    64   });
    65 });
    67 </script>
    68 </pre>
    69 </body>
    70 </html>

mercurial