tor-browser

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

ctor-stereopanner.html (4235B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test Constructor: StereoPanner
      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, 'StereoPannerNode', context);
     26        task.done();
     27      });
     28 
     29      audit.define('default constructor', (task, should) => {
     30        let prefix = 'node0';
     31        let node = testDefaultConstructor(should, 'StereoPannerNode', context, {
     32          prefix: prefix,
     33          numberOfInputs: 1,
     34          numberOfOutputs: 1,
     35          channelCount: 2,
     36          channelCountMode: 'clamped-max',
     37          channelInterpretation: 'speakers'
     38        });
     39 
     40        testDefaultAttributes(should, node, prefix, [{name: 'pan', value: 0}]);
     41 
     42        task.done();
     43      });
     44 
     45      audit.define('test AudioNodeOptions', (task, should) => {
     46        // Can't use testAudioNodeOptions because the constraints for this node
     47        // are not supported there.
     48        let node;
     49 
     50        // An array of tests.
     51        [{
     52          // Test that we can set the channel count to 1 or 2 and that other
     53          // channel counts throw an error.
     54          attribute: 'channelCount',
     55          tests: [
     56            {value: 1}, {value: 2}, {value: 0, error: 'NotSupportedError'},
     57            {value: 3, error: 'NotSupportedError'},
     58            {value: 99, error: 'NotSupportedError'}
     59          ]
     60        },
     61         {
     62           // Test channelCountMode.  A mode of "max" is illegal, but others are
     63           // ok.  But also throw an error of unknown values.
     64           attribute: 'channelCountMode',
     65           tests: [
     66             {value: 'clamped-max'}, {value: 'explicit'},
     67             {value: 'max', error: 'NotSupportedError'},
     68             {value: 'foobar', error: TypeError}
     69           ]
     70         },
     71         {
     72           // Test channelInterpretation can be set for valid values and an
     73           // error is thrown for others.
     74           attribute: 'channelInterpretation',
     75           tests: [
     76             {value: 'speakers'}, {value: 'discrete'},
     77             {value: 'foobar', error: TypeError}
     78           ]
     79         }].forEach(entry => {
     80          entry.tests.forEach(testItem => {
     81            let options = {};
     82            options[entry.attribute] = testItem.value;
     83 
     84            const testFunction = () => {
     85              node = new StereoPannerNode(context, options);
     86            };
     87            const testDescription =
     88                `new StereoPannerNode(c, ${JSON.stringify(options)})`;
     89 
     90            if (testItem.error) {
     91              testItem.error === TypeError
     92              ? should(testFunction, testDescription).throw(TypeError)
     93              : should(testFunction, testDescription)
     94                  .throw(DOMException, 'NotSupportedError');
     95            } else {
     96              should(testFunction, testDescription).notThrow();
     97              should(node[entry.attribute], `node.${entry.attribute}`)
     98                  .beEqualTo(options[entry.attribute]);
     99            }
    100          });
    101        });
    102 
    103        task.done();
    104      });
    105 
    106      audit.define('constructor with options', (task, should) => {
    107        let node;
    108        let options = {
    109          pan: 0.75,
    110        };
    111 
    112        should(
    113            () => {
    114              node = new StereoPannerNode(context, options);
    115            },
    116            'node1 = new StereoPannerNode(, ' + JSON.stringify(options) + ')')
    117            .notThrow();
    118        should(
    119            node instanceof StereoPannerNode,
    120            'node1 instanceof StereoPannerNode')
    121            .beEqualTo(true);
    122 
    123        should(node.pan.value, 'node1.pan.value').beEqualTo(options.pan);
    124 
    125        task.done();
    126      });
    127 
    128      audit.run();
    129    </script>
    130  </body>
    131 </html>