Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/constructor/new-audionodeoptions.js

Issue 2831953003: Convert constructor/analyser test to new Audit (Closed)
Patch Set: Address review comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/constructor/analyser.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Test that constructor for the node with name |nodeName| handles the
2 // various possible values for channelCount, channelCountMode, and
3 // channelInterpretation.
4
5 // The |should| parameter is the test function from new |Audit|.
6 function testAudioNodeOptions(should, context, nodeName, expectedNodeOptions) {
7 if (expectedNodeOptions === undefined)
8 expectedNodeOptions = {};
9 let node;
10
11 // Test that we can set channelCount and that errors are thrown for
12 // invalid values
13 let testChannelCount = 17;
14 if (expectedNodeOptions.ChannelCount) {
15 testChannelCount = expectedNodeOptions.ChannelCount.value;
16 }
17 should(
18 () => {
19 node = new window[nodeName](
20 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
21 channelCount: testChannelCount
22 }));
23 },
24 'new ' + nodeName + '(c, {channelCount: ' + testChannelCount + '}}')
25 .notThrow();
26 should(node.channelCount, 'node.channelCount').beEqualTo(testChannelCount);
27
28 if (expectedNodeOptions.ChannelCount &&
29 expectedNodeOptions.ChannelCount.isFixed) {
30 // The channel count is fixed. Verify that we throw an error if
31 // we try to change it. Arbitrarily set the count to be one more
32 // than the expected value.
33 testChannelCount = expectedNodeOptions.ChannelCount.value + 1;
34 should(
35 () => {
36 node = new window[nodeName](
37 context,
38 Object.assign(
39 {}, expectedNodeOptions.additionalOptions,
40 {channelCount: testChannelCount}));
41 },
42 'new ' + nodeName + '(c, {channelCount: ' + testChannelCount + '}}')
43 .throw(expectedNodeOptions.ChannelCount.errorType || 'TypeError');
44 } else {
45 // The channel count is not fixed. Try to set the count to invalid
46 // values and make sure an error is thrown.
47 let errorType = 'NotSupportedError';
48
49 should(() => {
50 node = new window[nodeName](
51 context,
52 Object.assign(
53 {}, expectedNodeOptions.additionalOptions, {channelCount: 0}));
54 }, 'new ' + nodeName + '(c, {channelCount: 0}}', ).throw(errorType);
55
56 should(() => {
57 node = new window[nodeName](
58 context,
59 Object.assign(
60 {}, expectedNodeOptions.additionalOptions, {channelCount: 99}));
61 }, 'new ' + nodeName + '(c, {channelCount: 99}}').throw(errorType);
62 }
63
64 // Test channelCountMode
65 let testChannelCountMode = 'max';
66 if (expectedNodeOptions.ChannelCountMode) {
67 testChannelCountMode = expectedNodeOptions.ChannelCountMode.value;
68 }
69 should(
70 () => {
71 node = new window[nodeName](
72 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
73 channelCountMode: testChannelCountMode
74 }));
75 },
76 'new ' + nodeName + '(c, {channelCountMode: "' + testChannelCountMode + '" }')
77 .notThrow();
78 should(node.channelCountMode, 'node.channelCountMode').beEqualTo(testChannelCo untMode);
79
80 if (expectedNodeOptions.ChannelCountMode &&
81 expectedNodeOptions.ChannelCountMode.isFixed) {
82 // Channel count mode is fixed. Test setting to something else throws.
83 let testChannelCountModeMap = {
84 'max': 'clamped-max',
85 'clamped-max': 'explicit',
86 'explicit': 'max'
87 };
88 testChannelCountMode = testChannelCountModeMap[expectedNodeOptions.ChannelCo untMode.value];
89 should(
90 () => {
91 node = new window[nodeName](
92 context,
93 Object.assign(
94 {}, expectedNodeOptions.additionalOptions,
95 {channelCountMode: testChannelCountMode}));
96 },
97 'new ' + nodeName + '(c, {channelCountMode: "' + testChannelCountMode + '"}')
98 .throw(expectedNodeOptions.ChannelCountMode.errorType);
99 } else {
100 // Mode is not fixed. Verify that we can set the mode to all valid
101 // values, and that we throw for invalid values.
102
103 should(() => {
104 node = new window[nodeName](
105 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
106 channelCountMode: 'clamped-max'
107 }));
108 }, 'new ' + nodeName + '(c, {channelCountMode: "clamped-max"}').notThrow();
109 should(node.channelCountMode, 'node.channelCountMode after invalid setter')
110 .beEqualTo('clamped-max');
111
112 should(() => {
113 node = new window[nodeName](
114 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
115 channelCountMode: 'explicit'
116 }));
117 }, 'new ' + nodeName + '(c, {channelCountMode: "explicit"}').notThrow();
118 should(node.channelCountMode, 'node.channelCountMode')
119 .beEqualTo('explicit');
120
121 should(
122 () => {
123 node = new window[nodeName](
124 context,
125 Object.assign(
126 {}, expectedNodeOptions.additionalOptions,
127 {channelCountMode: 'foobar'}));
128 },
129 'new ' + nodeName + '(c, {channelCountMode: "foobar"}')
130 .throw('TypeError');
131 should(node.channelCountMode, 'node.channelCountMode after invalid setter')
132 .beEqualTo('explicit');
133 }
134
135 // Test channelInterpretation
136 should(() => {
137 node = new window[nodeName](
138 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
139 channelInterpretation: 'speakers'
140 }));
141 }, 'new ' + nodeName + '(c, {channelInterpretation: "speakers"})').notThrow();
142 should(node.channelInterpretation, 'node.channelInterpretation')
143 .beEqualTo('speakers');
144
145 should(() => {
146 node = new window[nodeName](
147 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
148 channelInterpretation: 'discrete'
149 }));
150 }, 'new ' + nodeName + '(c, {channelInterpretation: "discrete"})').notThrow();
151 should(node.channelInterpretation, 'node.channelInterpretation')
152 .beEqualTo('discrete');
153
154 should(
155 () => {
156 node = new window[nodeName](
157 context, Object.assign({}, expectedNodeOptions.additionalOptions, {
158 channelInterpretation: 'foobar'
159 }));
160 },
161 'new ' + nodeName + '(c, {channelInterpretation: "foobar"})')
162 .throw('TypeError');
163 should(
164 node.channelInterpretation,
165 'node.channelInterpretation after invalid setter')
166 .beEqualTo('discrete');
167 }
168
169 function initializeContext(should) {
170 let c;
171 should(() => {
172 c = new OfflineAudioContext(1, 1, 48000);
173 }, 'context = new OfflineAudioContext(...)').notThrow();
174
175 return c;
176 }
177
178 function testInvalidConstructor(should, name, context) {
179 should(() => {
180 new window[name]();
181 }, 'new ' + name + '()').throw('TypeError');
182 should(() => {
183 new window[name](1);
184 }, 'new ' + name + '(1)').throw('TypeError');
185 should(() => {
186 new window[name](context, 42);
187 }, 'new ' + name + '(context, 42)').throw('TypeError');
188 }
189
190 function testDefaultConstructor(should, name, context, options) {
191 let node;
192
193 should(() => {
194 node = new window[name](context);
195 }, options.prefix + ' = new ' + name + '(context)').notThrow();
196 should(node instanceof window[name], options.prefix + ' instanceof ' + name)
197 .beEqualTo(true);
198
199 should(node.numberOfInputs, options.prefix + '.numberOfInputs')
200 .beEqualTo(options.numberOfInputs);
201 should(node.numberOfOutputs, options.prefix + '.numberOfOutputs')
202 .beEqualTo(options.numberOfOutputs);
203 should(node.channelCount, options.prefix + '.channelCount')
204 .beEqualTo(options.channelCount);
205 should(node.channelCountMode, options.prefix + '.channelCountMode')
206 .beEqualTo(options.channelCountMode);
207 should(node.channelInterpretation, options.prefix + '.channelInterpretation')
208 .beEqualTo(options.channelInterpretation);
209
210 return node;
211 }
212
213 function testDefaultAttributes(should, node, prefix, items) {
214 items.forEach((item) => {
215 let attr = node[item.name];
216 if (attr instanceof AudioParam) {
217 should(attr.value, prefix + '.' + item.name + '.value')
218 .beEqualTo(item.value);
219 } else {
220 should(attr, prefix + '.' + item.name).beEqualTo(item.value);
221 }
222 });
223 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/constructor/analyser.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698