summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-convolvernode-interface/ctor-convolver.html
blob: 28a0fc1c3c75e5b5804d892798ad8f38aa3216e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
  <head>
    <title>
      Test Constructor: Convolver
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit-util.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
    <script src="/webaudio/resources/audionodeoptions.js"></script>
  </head>
  <body>
    <script id="layout-test-code">
      let context;

      let audit = Audit.createTaskRunner();

      audit.define('initialize', (task, should) => {
        context = initializeContext(should);
        task.done();
      });

      audit.define('invalid constructor', (task, should) => {
        testInvalidConstructor(should, 'ConvolverNode', context);
        task.done();
      });

      audit.define('default constructor', (task, should) => {
        let prefix = 'node0';
        let node = testDefaultConstructor(should, 'ConvolverNode', context, {
          prefix: prefix,
          numberOfInputs: 1,
          numberOfOutputs: 1,
          channelCount: 2,
          channelCountMode: 'clamped-max',
          channelInterpretation: 'speakers'
        });

        testDefaultAttributes(
            should, node, prefix,
            [{name: 'normalize', value: true}, {name: 'buffer', value: null}]);

        task.done();
      });

      audit.define('test AudioNodeOptions', (task, should) => {
        // Can't use testAudioNodeOptions because the constraints for this node
        // are not supported there.
        let node;

        // An array of tests.
        [{
          // Test that we can set the channel count to 1 or 2 and that other
          // channel counts throw an error.
          attribute: 'channelCount',
          tests: [
            {value: 1}, {value: 2}, {value: 0, error: 'NotSupportedError'},
            {value: 3, error: 'NotSupportedError'},
            {value: 99, error: 'NotSupportedError'}
          ]
        },
         {
           // Test channelCountMode.  A mode of "max" is illegal, but others are
           // ok.  But also throw an error of unknown values.
           attribute: 'channelCountMode',
           tests: [
             {value: 'clamped-max'}, {value: 'explicit'},
             {value: 'max', error: 'NotSupportedError'},
             {value: 'foobar', error: TypeError}
           ]
         },
         {
           // Test channelInterpretation can be set for valid values and an
           // error is thrown for others.
           attribute: 'channelInterpretation',
           tests: [
             {value: 'speakers'}, {value: 'discrete'},
             {value: 'foobar', error: TypeError}
           ]
         }].forEach(entry => {
          entry.tests.forEach(testItem => {
            let options = {};
            options[entry.attribute] = testItem.value;

            const testFunction = () => {
              node = new ConvolverNode(context, options);
            };
            const testDescription =
                `new ConvolverNode(c, ${JSON.stringify(options)})`;

            if (testItem.error) {
              testItem.error === TypeError
              ? should(testFunction, testDescription).throw(TypeError)
              : should(testFunction, testDescription)
                  .throw(DOMException, 'NotSupportedError');
            } else {
              should(testFunction, testDescription).notThrow();
              should(node[entry.attribute], `node.${entry.attribute}`)
                  .beEqualTo(options[entry.attribute]);
            }
          });
        });

        task.done();
      });

      audit.define('nullable buffer', (task, should) => {
        let node;
        let options = {buffer: null};

        should(
            () => {
              node = new ConvolverNode(context, options);
            },
            'node1 = new ConvolverNode(c, ' + JSON.stringify(options))
            .notThrow();

        should(node.buffer, 'node1.buffer').beEqualTo(null);

        task.done();
      });
      audit.define('illegal sample-rate', (task, should) => {
        let node;
        let options = {buffer: context.createBuffer(1, 1, context.sampleRate / 2)};

        should(
            () => {
              node = new ConvolverNode(context, options);
            },
            'node1 = new ConvolverNode(c, ' + JSON.stringify(options))
            .throw(DOMException, 'NotSupportedError');

        task.done();
      });

      audit.define('construct with options', (task, should) => {
        let buf = context.createBuffer(1, 1, context.sampleRate);
        let options = {buffer: buf, disableNormalization: false};

        let message =
            'node = new ConvolverNode(c, ' + JSON.stringify(options) + ')';

        let node;
        should(() => {
          node = new ConvolverNode(context, options);
        }, message).notThrow();

        should(node instanceof ConvolverNode, 'node1 instanceOf ConvolverNode')
            .beEqualTo(true);
        should(node.buffer === options.buffer, 'node1.buffer === <buf>')
            .beEqualTo(true);
        should(node.normalize, 'node1.normalize')
            .beEqualTo(!options.disableNormalization);

        options.buffer = null;
        options.disableNormalization = true;

        message =
            'node2 = new ConvolverNode(, ' + JSON.stringify(options) + ')';

        should(() => {
          node = new ConvolverNode(context, options);
        }, message).notThrow();
        should(node.buffer, 'node2.buffer').beEqualTo(null);
        should(node.normalize, 'node2.normalize')
            .beEqualTo(!options.disableNormalization);

        options.disableNormalization = false;
        message = 'node3 = new ConvolverNode(context, ' +
            JSON.stringify(options) + ')';

        should(() => {
          node = new ConvolverNode(context, options);
        }, message).notThrow();
        should(node.buffer, 'node3.buffer').beEqualTo(null);
        should(node.normalize, 'node3.normalize')
            .beEqualTo(!options.disableNormalization);

        task.done();
      });

      audit.run();
    </script>
  </body>
</html>