summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/ctor-analyser.html
blob: a9aa4831516c6a5cefa7c8b4f67f3ef246d24777 (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
<!DOCTYPE html>
<html>
  <head>
    <title>
      Test Constructor: AnalyserNode
    </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, 'AnalyserNode', context);
        task.done();
      });

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

        testDefaultAttributes(should, node, prefix, [
          {name: 'fftSize', value: 2048},
          {name: 'frequencyBinCount', value: 1024},
          {name: 'minDecibels', value: -100}, {name: 'maxDecibels', value: -30},
          {name: 'smoothingTimeConstant', value: 0.8}
        ]);

        task.done();
      });

      audit.define('test AudioNodeOptions', (task, should) => {
        testAudioNodeOptions(should, context, 'AnalyserNode');
        task.done();
      });

      audit.define('constructor with options', (task, should) => {
        let options = {
          fftSize: 32,
          maxDecibels: 1,
          minDecibels: -13,
          // Choose a value that can be represented the same as a float and as a
          // double.
          smoothingTimeConstant: 0.125
        };

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

        should(node instanceof AnalyserNode, 'node1 instanceof AnalyserNode')
            .beEqualTo(true);
        should(node.fftSize, 'node1.fftSize').beEqualTo(options.fftSize);
        should(node.maxDecibels, 'node1.maxDecibels')
            .beEqualTo(options.maxDecibels);
        should(node.minDecibels, 'node1.minDecibels')
            .beEqualTo(options.minDecibels);
        should(node.smoothingTimeConstant, 'node1.smoothingTimeConstant')
            .beEqualTo(options.smoothingTimeConstant);

        task.done();
      });

      audit.define('construct invalid options', (task, should) => {
        let node;

        should(
            () => {
              node = new AnalyserNode(context, {fftSize: 33});
            },
            'node = new AnalyserNode(c, { fftSize: 33 })')
            .throw(DOMException, 'IndexSizeError');
        should(
            () => {
              node = new AnalyserNode(context, {maxDecibels: -500});
            },
            'node = new AnalyserNode(c, { maxDecibels: -500 })')
            .throw(DOMException, 'IndexSizeError');
        should(
            () => {
              node = new AnalyserNode(context, {minDecibels: -10});
            },
            'node = new AnalyserNode(c, { minDecibels: -10 })')
            .throw(DOMException, 'IndexSizeError');
        should(
            () => {
              node = new AnalyserNode(context, {smoothingTimeConstant: 2});
            },
            'node = new AnalyserNode(c, { smoothingTimeConstant: 2 })')
            .throw(DOMException, 'IndexSizeError');
        should(function() {
          node = new AnalyserNode(context, {frequencyBinCount: 33});
        }, 'node = new AnalyserNode(c, { frequencyBinCount: 33 })').notThrow();
        should(node.frequencyBinCount, 'node.frequencyBinCount')
            .beEqualTo(1024);

        task.done();
      });

      audit.define('setting min/max', (task, should) => {
        let node;

        // Recall the default values of minDecibels and maxDecibels are -100,
        // and -30, respectively.  Setting both values in the constructor should
        // not signal an error in any of the following cases.
        let options = {minDecibels: -10, maxDecibels: 20};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .notThrow();

        options = {maxDecibels: 20, minDecibels: -10};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .notThrow();

        options = {minDecibels: -200, maxDecibels: -150};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .notThrow();

        options = {maxDecibels: -150, minDecibels: -200};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .notThrow();

        // But these should signal because minDecibel > maxDecibel
        options = {maxDecibels: -150, minDecibels: -10};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .throw(DOMException, 'IndexSizeError');

        options = {minDecibels: -10, maxDecibels: -150};
        should(
            () => {
              node = new AnalyserNode(context, options);
            },
            'node = new AnalyserNode(c, ' + JSON.stringify(options) + ')')
            .throw(DOMException, 'IndexSizeError');

        task.done();
      });

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