tor-browser

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

ctor-analyser.html (6194B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test Constructor: AnalyserNode
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9    <script src="/webaudio/resources/audit-util.js"></script>
     10    <script src="/webaudio/resources/audit.js"></script>
     11    <script src="/webaudio/resources/audionodeoptions.js"></script>
     12  </head>
     13  <body>
     14    <script id="layout-test-code">
     15      let context;
     16 
     17      let audit = Audit.createTaskRunner();
     18 
     19      audit.define('initialize', (task, should) => {
     20        context = initializeContext(should);
     21        task.done();
     22      });
     23 
     24      audit.define('invalid constructor', (task, should) => {
     25        testInvalidConstructor(should, 'AnalyserNode', context);
     26        task.done();
     27      });
     28 
     29      audit.define('default constructor', (task, should) => {
     30        let prefix = 'node0';
     31        let node = testDefaultConstructor(should, 'AnalyserNode', context, {
     32          prefix: prefix,
     33          numberOfInputs: 1,
     34          numberOfOutputs: 1,
     35          channelCount: 2,
     36          channelCountMode: 'max',
     37          channelInterpretation: 'speakers'
     38        });
     39 
     40        testDefaultAttributes(should, node, prefix, [
     41          {name: 'fftSize', value: 2048},
     42          {name: 'frequencyBinCount', value: 1024},
     43          {name: 'minDecibels', value: -100}, {name: 'maxDecibels', value: -30},
     44          {name: 'smoothingTimeConstant', value: 0.8}
     45        ]);
     46 
     47        task.done();
     48      });
     49 
     50      audit.define('test AudioNodeOptions', (task, should) => {
     51        testAudioNodeOptions(should, context, 'AnalyserNode');
     52        task.done();
     53      });
     54 
     55      audit.define('constructor with options', (task, should) => {
     56        let options = {
     57          fftSize: 32,
     58          maxDecibels: 1,
     59          minDecibels: -13,
     60          // Choose a value that can be represented the same as a float and as a
     61          // double.
     62          smoothingTimeConstant: 0.125
     63        };
     64 
     65        let node;
     66        should(
     67            () => {
     68              node = new AnalyserNode(context, options);
     69            },
     70            'node1 = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
     71            .notThrow();
     72 
     73        should(node instanceof AnalyserNode, 'node1 instanceof AnalyserNode')
     74            .beEqualTo(true);
     75        should(node.fftSize, 'node1.fftSize').beEqualTo(options.fftSize);
     76        should(node.maxDecibels, 'node1.maxDecibels')
     77            .beEqualTo(options.maxDecibels);
     78        should(node.minDecibels, 'node1.minDecibels')
     79            .beEqualTo(options.minDecibels);
     80        should(node.smoothingTimeConstant, 'node1.smoothingTimeConstant')
     81            .beEqualTo(options.smoothingTimeConstant);
     82 
     83        task.done();
     84      });
     85 
     86      audit.define('construct invalid options', (task, should) => {
     87        let node;
     88 
     89        should(
     90            () => {
     91              node = new AnalyserNode(context, {fftSize: 33});
     92            },
     93            'node = new AnalyserNode(c, { fftSize: 33 })')
     94            .throw(DOMException, 'IndexSizeError');
     95        should(
     96            () => {
     97              node = new AnalyserNode(context, {maxDecibels: -500});
     98            },
     99            'node = new AnalyserNode(c, { maxDecibels: -500 })')
    100            .throw(DOMException, 'IndexSizeError');
    101        should(
    102            () => {
    103              node = new AnalyserNode(context, {minDecibels: -10});
    104            },
    105            'node = new AnalyserNode(c, { minDecibels: -10 })')
    106            .throw(DOMException, 'IndexSizeError');
    107        should(
    108            () => {
    109              node = new AnalyserNode(context, {smoothingTimeConstant: 2});
    110            },
    111            'node = new AnalyserNode(c, { smoothingTimeConstant: 2 })')
    112            .throw(DOMException, 'IndexSizeError');
    113        should(function() {
    114          node = new AnalyserNode(context, {frequencyBinCount: 33});
    115        }, 'node = new AnalyserNode(c, { frequencyBinCount: 33 })').notThrow();
    116        should(node.frequencyBinCount, 'node.frequencyBinCount')
    117            .beEqualTo(1024);
    118 
    119        task.done();
    120      });
    121 
    122      audit.define('setting min/max', (task, should) => {
    123        let node;
    124 
    125        // Recall the default values of minDecibels and maxDecibels are -100,
    126        // and -30, respectively.  Setting both values in the constructor should
    127        // not signal an error in any of the following cases.
    128        let options = {minDecibels: -10, maxDecibels: 20};
    129        should(
    130            () => {
    131              node = new AnalyserNode(context, options);
    132            },
    133            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    134            .notThrow();
    135 
    136        options = {maxDecibels: 20, minDecibels: -10};
    137        should(
    138            () => {
    139              node = new AnalyserNode(context, options);
    140            },
    141            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    142            .notThrow();
    143 
    144        options = {minDecibels: -200, maxDecibels: -150};
    145        should(
    146            () => {
    147              node = new AnalyserNode(context, options);
    148            },
    149            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    150            .notThrow();
    151 
    152        options = {maxDecibels: -150, minDecibels: -200};
    153        should(
    154            () => {
    155              node = new AnalyserNode(context, options);
    156            },
    157            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    158            .notThrow();
    159 
    160        // But these should signal because minDecibel > maxDecibel
    161        options = {maxDecibels: -150, minDecibels: -10};
    162        should(
    163            () => {
    164              node = new AnalyserNode(context, options);
    165            },
    166            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    167            .throw(DOMException, 'IndexSizeError');
    168 
    169        options = {minDecibels: -10, maxDecibels: -150};
    170        should(
    171            () => {
    172              node = new AnalyserNode(context, options);
    173            },
    174            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
    175            .throw(DOMException, 'IndexSizeError');
    176 
    177        task.done();
    178      });
    179 
    180      audit.run();
    181    </script>
    182  </body>
    183 </html>