OLD | NEW |
---|---|
(Empty) | |
1 // Test that constructor for the node with name |nodeName| handles the | |
2 // various possible values for channelCount, channelCountMode, and | |
3 // channelInterpretation. | |
hongchan
2017/04/20 19:04:19
Please mention that this method requires |Audit| a
Raymond Toy
2017/04/20 19:19:38
Here and everywhere, I assume.
| |
4 function testAudioNodeOptions(should, context, nodeName, nodeOptions) { | |
hongchan
2017/04/20 19:04:19
Can we name this |expectedNodeOptions| and remove
Raymond Toy
2017/04/20 21:00:00
Done.
| |
5 if (nodeOptions === undefined) | |
6 nodeOptions = {}; | |
7 var node; | |
hongchan
2017/04/20 19:04:19
I see the mixed usage of |var| and |let|. Let's be
Raymond Toy
2017/04/20 21:00:00
Done.
| |
8 | |
9 // Test that we can set channelCount and that errors are thrown for | |
10 // invalid values | |
11 var testCount = 17; | |
hongchan
2017/04/20 19:04:19
testChannelCount
Raymond Toy
2017/04/20 21:00:00
Done.
| |
12 if (nodeOptions.expectedChannelCount) { | |
13 testCount = nodeOptions.expectedChannelCount.value; | |
hongchan
2017/04/20 19:04:19
So |expectedChannelCount| is an object, not a valu
Raymond Toy
2017/04/20 19:19:38
Yes. Analyser doesn't show this usage, but, say, C
| |
14 } | |
15 should(() => { | |
16 node = new window[nodeName]( | |
17 context, | |
18 Object.assign( | |
19 {}, nodeOptions.additionalOptions, {channelCount: testCount})); | |
20 }, 'new ' + nodeName + '(c, {channelCount: ' + testCount + '}}').notThrow(); | |
21 should(node.channelCount, 'node.channelCount').beEqualTo(testCount); | |
22 | |
23 if (nodeOptions.expectedChannelCount && | |
24 nodeOptions.expectedChannelCount.isFixed) { | |
25 // The channel count is fixed. Verify that we throw an error if | |
26 // we try to change it. Arbitrarily set the count to be one more | |
27 // than the expected value. | |
28 testCount = nodeOptions.expectedChannelCount.value + 1; | |
29 should( | |
30 () => { | |
31 node = new window[nodeName]( | |
32 context, Object.assign({}, nodeOptions.additionalOptions, { | |
33 channelCount: testCount | |
34 })); | |
35 }, | |
36 'new ' + nodeName + '(c, {channelCount: ' + testCount + '}}') | |
37 .throw(nodeOptions.expectedChannelCount.errorType || 'TypeError'); | |
38 } else { | |
39 // The channel count is not fixed. Try to set the count to invalid | |
40 // values and make sure an error is thrown. | |
41 var errorType = 'NotSupportedError'; | |
42 | |
43 should(() => { | |
44 node = new window[nodeName]( | |
45 context, | |
46 Object.assign({}, nodeOptions.additionalOptions, {channelCount: 0})); | |
47 }, 'new ' + nodeName + '(c, {channelCount: 0}}', ).throw(errorType); | |
48 | |
49 should(() => { | |
50 node = new window[nodeName]( | |
51 context, | |
52 Object.assign({}, nodeOptions.additionalOptions, {channelCount: 99})); | |
53 }, 'new ' + nodeName + '(c, {channelCount: 99}}').throw(errorType); | |
54 } | |
55 | |
56 // Test channelCountMode | |
57 var testMode = 'max'; | |
58 if (nodeOptions && nodeOptions.expectedChannelCountMode) { | |
hongchan
2017/04/20 19:04:19
|nodeOptions| cannot be invalid at this point.
Raymond Toy
2017/04/20 21:00:00
Done.
| |
59 testMode = nodeOptions.expectedChannelCountMode.value; | |
60 } | |
61 should( | |
62 () => { | |
63 node = new window[nodeName]( | |
64 context, Object.assign({}, nodeOptions.additionalOptions, { | |
65 channelCountMode: testMode | |
66 })); | |
67 }, | |
68 'new ' + nodeName + '(c, {channelCountMode: "' + testMode + '"}') | |
69 .notThrow(); | |
70 should(node.channelCountMode, 'node.channelCountMode').beEqualTo(testMode); | |
71 | |
72 if (nodeOptions.expectedChannelCountMode && | |
73 nodeOptions.expectedChannelCountMode.isFixed) { | |
74 // Channel count mode is fixed. Test setting to something else throws. | |
75 var testModeMap = { | |
76 'max': 'clamped-max', | |
77 'clamped-max': 'explicit', | |
78 'explicit': 'max' | |
79 }; | |
80 testMode = testModeMap[nodeOptions.expectedChannelCountMode.value]; | |
81 should( | |
82 () => { | |
83 node = new window[nodeName]( | |
84 context, Object.assign({}, nodeOptions.additionalOptions, { | |
85 channelCountMode: testMode | |
86 })); | |
87 }, | |
88 'new ' + nodeName + '(c, {channelCountMode: "' + testMode + '"}') | |
89 .throw(nodeOptions.expectedChannelCountMode.errorType); | |
90 } else { | |
91 // Mode is not fixed. Verify that we can set the mode to all valid | |
92 // values, and that we throw for invalid values. | |
93 | |
94 should(() => { | |
95 node = new window[nodeName]( | |
96 context, Object.assign({}, nodeOptions.additionalOptions, { | |
97 channelCountMode: 'clamped-max' | |
98 })); | |
99 }, 'new ' + nodeName + '(c, {channelCountMode: "clamped-max"}').notThrow(); | |
100 should(node.channelCountMode, 'node.channelCountMode after invalid setter') | |
101 .beEqualTo('clamped-max'); | |
102 | |
103 should(() => { | |
104 node = new window[nodeName]( | |
105 context, Object.assign({}, nodeOptions.additionalOptions, { | |
106 channelCountMode: 'explicit' | |
107 })); | |
108 }, 'new ' + nodeName + '(c, {channelCountMode: "explicit"}').notThrow(); | |
109 should(node.channelCountMode, 'node.channelCountMode') | |
110 .beEqualTo('explicit'); | |
111 | |
112 should( | |
113 () => { | |
114 node = new window[nodeName]( | |
115 context, Object.assign({}, nodeOptions.additionalOptions, { | |
116 channelCountMode: 'foobar' | |
117 })); | |
118 }, | |
119 'new ' + nodeName + '(c, {channelCountMode: "foobar"}') | |
120 .throw('TypeError'); | |
121 should(node.channelCountMode, 'node.channelCountMode after invalid setter') | |
122 .beEqualTo('explicit'); | |
123 } | |
124 | |
125 // Test channelInterpretation | |
126 should(() => { | |
127 node = new window[nodeName]( | |
128 context, Object.assign({}, nodeOptions.additionalOptions, { | |
129 channelInterpretation: 'speakers' | |
130 })); | |
131 }, 'new ' + nodeName + '(c, {channelInterpretation: "speakers"})').notThrow(); | |
132 should(node.channelInterpretation, 'node.channelInterpretation') | |
133 .beEqualTo('speakers'); | |
134 | |
135 should(() => { | |
136 node = new window[nodeName]( | |
137 context, Object.assign({}, nodeOptions.additionalOptions, { | |
138 channelInterpretation: 'discrete' | |
139 })); | |
140 }, 'new ' + nodeName + '(c, {channelInterpretation: "discrete"})').notThrow(); | |
141 should(node.channelInterpretation, 'node.channelInterpretation') | |
142 .beEqualTo('discrete'); | |
143 | |
144 should( | |
145 () => { | |
146 node = new window[nodeName]( | |
147 context, Object.assign({}, nodeOptions.additionalOptions, { | |
148 channelInterpretation: 'foobar' | |
149 })); | |
150 }, | |
151 'new ' + nodeName + '(c, {channelInterpretation: "foobar"})') | |
152 .throw('TypeError'); | |
153 should( | |
154 node.channelInterpretation, | |
155 'node.channelInterpretation after invalid setter') | |
156 .beEqualTo('discrete'); | |
157 } | |
158 | |
159 function initializeContext(should) { | |
160 let c; | |
161 should(() => { | |
162 c = new OfflineAudioContext(1, 1, 48000); | |
163 }, 'context = new OfflineAudioContext(...)').notThrow(); | |
164 | |
165 return c; | |
166 } | |
167 | |
168 function testInvalidConstructor(should, name, context) { | |
169 should(() => { | |
170 new window[name](); | |
171 }, 'new ' + name + '()').throw('TypeError'); | |
172 should(() => { | |
173 new window[name](1); | |
174 }, 'new ' + name + '(1)').throw('TypeError'); | |
175 should(() => { | |
176 new window[name](context, 42); | |
177 }, 'new ' + name + '(context, 42)').throw('TypeError'); | |
178 } | |
179 | |
180 function testDefaultConstructor(should, name, context, options) { | |
181 let node; | |
182 | |
183 should(() => { | |
184 node = new window[name](context); | |
185 }, options.prefix + ' = new ' + name + '(context)').notThrow(); | |
186 should(node instanceof window[name], options.prefix + ' instanceof ' + name) | |
187 .beEqualTo(true); | |
188 | |
189 should(node.numberOfInputs, options.prefix + '.numberOfInputs') | |
190 .beEqualTo(options.numberOfInputs); | |
191 should(node.numberOfOutputs, options.prefix + '.numberOfOutputs') | |
192 .beEqualTo(options.numberOfOutputs); | |
193 should(node.channelCount, options.prefix + '.channelCount') | |
194 .beEqualTo(options.channelCount); | |
195 should(node.channelCountMode, options.prefix + '.channelCountMode') | |
196 .beEqualTo(options.channelCountMode); | |
197 should(node.channelInterpretation, options.prefix + '.channelInterpretation') | |
198 .beEqualTo(options.channelInterpretation); | |
199 | |
200 return node; | |
201 } | |
202 | |
203 function testDefaultAttributes(should, node, prefix, items) { | |
204 items.forEach((item) => { | |
205 let attr = node[item.name]; | |
206 if (attr instanceof AudioParam) { | |
207 should(attr.value, prefix + '.' + item.name + '.value') | |
208 .beEqualTo(item.value); | |
209 } else { | |
210 should(attr, prefix + '.' + item.name).beEqualTo(item.value); | |
211 } | |
212 }); | |
213 } | |
OLD | NEW |