content/media/webaudio/test/test_oscillatorNode.html

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test the OscillatorNode 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() {
    16   var context = new AudioContext();
    17   var osc = context.createOscillator();
    19   is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
    20   is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
    21   is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
    22   is(osc.type, "sine", "Correct default type");
    23   expectException(function() {
    24     osc.type = "custom";
    25   }, DOMException.INVALID_STATE_ERR);
    26   expectException(function() {
    27     osc.type = osc.CUSTOM;
    28   }, DOMException.INVALID_STATE_ERR);
    29   is(osc.type, "sine", "Cannot set the type to custom");
    30   is(osc.frequency.value, 440, "Correct default frequency value");
    31   is(osc.detune.value, 0, "Correct default detine value");
    33   // Make sure that we can set all of the valid type values
    34   var types = [
    35     "sine",
    36     "square",
    37     "sawtooth",
    38     "triangle",
    39   ];
    40   for (var i = 0; i < types.length; ++i) {
    41     osc.type = osc[types[i].toUpperCase()];
    42     is(osc.type, types[i], "Correct alternname type enum value");
    43     osc.type = types[i];
    44   }
    46   // Verify setPeriodicWave()
    47   var real = new Float32Array([1.0, 0.5, 0.25, 0.125]);
    48   var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]);
    49   osc.setPeriodicWave(context.createPeriodicWave(real, imag));
    50   is(osc.type, "custom", "Failed to set custom waveform");
    52   expectNoException(function() {
    53     osc.start();
    54   });
    55   expectNoException(function() {
    56     osc.stop();
    57   });
    59   SimpleTest.finish();
    60 });
    62 </script>
    63 </pre>
    64 </body>
    65 </html>

mercurial