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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-copy-channel.html

Issue 2782523002: Convert AudioBuffer tests to new Audit (Closed)
Patch Set: Indent some long lines 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 | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-getChannelData.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../resources/testharness.js"></script> 4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="../resources/audit-util.js"></script> 6 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audio-testing.js"></script> 7 <script src="../resources/audit.js"></script>
8 <title>Test Basic Functionality of AudioBuffer.copyFromChannel and AudioBuff er.copyToChannel</title> 8 <title>Test Basic Functionality of AudioBuffer.copyFromChannel and AudioBuff er.copyToChannel</title>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 13
14 14
15 // Define utility routines. 15 // Define utility routines.
16 16
17 // Initialize the AudioBuffer |buffer| with a ramp signal on each channel. The ramp starts at 17 // Initialize the AudioBuffer |buffer| with a ramp signal on each channel. The ramp starts at
(...skipping 22 matching lines...) Expand all
40 for (var k = 0; k < x.length; ++k) { 40 for (var k = 0; k < x.length; ++k) {
41 x[k] = k + 1; 41 x[k] = k + 1;
42 } 42 }
43 43
44 return x; 44 return x;
45 } 45 }
46 46
47 // Test that the array |x| is a ramp starting at value |start| of length | length|, starting at 47 // Test that the array |x| is a ramp starting at value |start| of length | length|, starting at
48 // |startIndex| in the array. |startIndex| is optional and defaults to 0. Any other values 48 // |startIndex| in the array. |startIndex| is optional and defaults to 0. Any other values
49 // must be -1. 49 // must be -1.
50 function shouldBeRamp(testName, x, startValue, length, startIndex) { 50 function shouldBeRamp(should, testName, x, startValue, length,
51 startIndex) {
51 var k; 52 var k;
52 var startingIndex = startIndex || 0; 53 var startingIndex = startIndex || 0;
53 var expected = Array(x.length); 54 var expected = Array(x.length);
54 55
55 // Fill the expected array with the correct results. 56 // Fill the expected array with the correct results.
56 57
57 // The initial part (if any) must be -1. 58 // The initial part (if any) must be -1.
58 for (k = 0; k < startingIndex; ++k) { 59 for (k = 0; k < startingIndex; ++k) {
59 expected[k] = -1; 60 expected[k] = -1;
60 } 61 }
61 62
62 // The second part should be a ramp starting with |startValue| 63 // The second part should be a ramp starting with |startValue|
63 for (; k < startingIndex + length; ++k) { 64 for (; k < startingIndex + length; ++k) {
64 expected[k] = startValue + k - startingIndex; 65 expected[k] = startValue + k - startingIndex;
65 } 66 }
66 67
67 // The last part (if any) should be -1. 68 // The last part (if any) should be -1.
68 for (; k < x.length; ++k) { 69 for (; k < x.length; ++k) {
69 expected[k] = -1; 70 expected[k] = -1;
70 } 71 }
71 72
72 Should(testName, x, {numberOfArrayLog: 32}).beEqualToArray(expected); 73 should(x, testName, {
74 numberOfArrayLog: 32
75 }).beEqualToArray(expected);
73 } 76 }
74 77
75 var audit = Audit.createTaskRunner(); 78 var audit = Audit.createTaskRunner();
76 79
77 var context = new AudioContext(); 80 var context = new AudioContext();
78 // Temp array for testing exceptions for copyToChannel/copyFromChannel. T he length is arbitrary. 81 // Temp array for testing exceptions for copyToChannel/copyFromChannel. T he length is arbitrary.
79 var x = new Float32Array(8); 82 var x = new Float32Array(8);
80 83
81 // Number of frames in the AudioBuffer for testing. This is pretty arbitr ary so choose a 84 // Number of frames in the AudioBuffer for testing. This is pretty arbitr ary so choose a
82 // fairly small value. 85 // fairly small value.
83 var bufferLength = 16; 86 var bufferLength = 16;
84 87
85 // Number of channels in the AudioBuffer. Also arbitrary, but it should b e greater than 1 for 88 // Number of channels in the AudioBuffer. Also arbitrary, but it should b e greater than 1 for
86 // test coverage. 89 // test coverage.
87 var numberOfChannels = 3; 90 var numberOfChannels = 3;
88 91
89 // AudioBuffer that will be used for testing copyFrom and copyTo. 92 // AudioBuffer that will be used for testing copyFrom and copyTo.
90 var buffer = context.createBuffer(numberOfChannels, bufferLength, context. sampleRate); 93 var buffer = context.createBuffer(numberOfChannels, bufferLength, context. sampleRate);
91 94
92 var initialValues = Array(numberOfChannels); 95 var initialValues = Array(numberOfChannels);
93 96
94 // Initialize things 97 // Initialize things
95 audit.defineTask("initialize", function (done) { 98 audit.define("initialize", (task, should) => {
96 // Initialize to -1. 99 // Initialize to -1.
97 for (var k = 0; k < numberOfChannels; ++k) { 100 initialValues.fill(-1);
98 initialValues[k] = -1; 101 should(initialValues, "Initialized values")
99 } 102 .beConstantValueOf(-1)
100 103 task.done();
101 done();
102 }); 104 });
103 105
104 // Test that expected exceptions are signaled for copyFrom. 106 // Test that expected exceptions are signaled for copyFrom.
105 audit.defineTask("copyFrom-exceptions", function (done) { 107 audit.define("copyFrom-exceptions", (task, should) => {
106 Should("AudioBuffer.prototype.copyFromChannel", 108 should(AudioBuffer.prototype.copyFromChannel,
107 AudioBuffer.prototype.copyFromChannel) 109 "AudioBuffer.prototype.copyFromChannel")
108 .exist(); 110 .exist();
109 111
110 Should("0: buffer = context.createBuffer(" + numberOfChannels + ", " + b ufferLength + ", context.sampleRate)", 112 should(() => {
111 function () { 113 buffer = context.createBuffer(numberOfChannels, bufferLength,
112 buffer = context.createBuffer(numberOfChannels, bufferLength, contex t.sampleRate); 114 context.sampleRate);
113 }).notThrow(); 115 },
114 Should("1: buffer.copyFromChannel(null, 0)", function () { 116 "0: buffer = context.createBuffer(" + numberOfChannels + ", " +
115 buffer.copyFromChannel(null, 0); 117 bufferLength + ", context.sampleRate)")
116 }).throw("TypeError"); 118 .notThrow();
117 Should("2: buffer.copyFromChannel(context, 0)", function () { 119 should(() => {
118 buffer.copyFromChannel(context, 0); 120 buffer.copyFromChannel(null, 0);
119 }).throw("TypeError"); 121 }, "1: buffer.copyFromChannel(null, 0)")
120 Should("3: buffer.copyFromChannel(x, -1)", function () { 122 .throw("TypeError");
121 buffer.copyFromChannel(x, -1); 123 should(() => {
122 }).throw("IndexSizeError"); 124 buffer.copyFromChannel(context, 0);
123 Should("4: buffer.copyFromChannel(x, " + numberOfChannels + ")", functio n () { 125 }, "2: buffer.copyFromChannel(context, 0)")
124 buffer.copyFromChannel(x, numberOfChannels); 126 .throw("TypeError");
125 }).throw("IndexSizeError");; 127 should(() => {
126 Should("5: buffer.copyFromChannel(x, 0, -1)", function () { 128 buffer.copyFromChannel(x, -1);
127 buffer.copyFromChannel(x, 0, -1); 129 }, "3: buffer.copyFromChannel(x, -1)")
128 }).throw("IndexSizeError"); 130 .throw("IndexSizeError");
129 Should("6: buffer.copyFromChannel(x, 0, " + bufferLength + ")", function () { 131 should(() => {
130 buffer.copyFromChannel(x, 0, bufferLength); 132 buffer.copyFromChannel(x, numberOfChannels);
131 }).throw("IndexSizeError"); 133 }, "4: buffer.copyFromChannel(x, " + numberOfChannels + ")")
134 .throw("IndexSizeError");;
135 should(() => {
136 buffer.copyFromChannel(x, 0, -1);
137 }, "5: buffer.copyFromChannel(x, 0, -1)")
138 .throw("IndexSizeError");
139 should(() => {
140 buffer.copyFromChannel(x, 0, bufferLength);
141 }, "6: buffer.copyFromChannel(x, 0, " + bufferLength + ")")
142 .throw("IndexSizeError");
132 143
133 Should("7: buffer.copyFromChannel(x, 3)", function () { 144 should(() => {
134 buffer.copyFromChannel(x, 3); 145 buffer.copyFromChannel(x, 3);
135 }).throw("IndexSizeError"); 146 }, "7: buffer.copyFromChannel(x, 3)")
147 .throw("IndexSizeError");
136 148
137 done(); 149 task.done();
138 }); 150 });
139 151
140 // Test that expected exceptions are signaled for copyTo. 152 // Test that expected exceptions are signaled for copyTo.
141 audit.defineTask("copyTo-exceptions", function (done) { 153 audit.define("copyTo-exceptions", (task, should) => {
142 Should("AudioBuffer.prototype.copyToChannel", 154 should(AudioBuffer.prototype.copyToChannel,
143 AudioBuffer.prototype.copyToChannel) 155 "AudioBuffer.prototype.copyToChannel")
144 .exist(); 156 .exist();
145 Should("0: buffer.copyToChannel(null, 0)", function () { 157 should(() => {
146 buffer.copyToChannel(null, 0); 158 buffer.copyToChannel(null, 0);
147 }).throw("TypeError"); 159 }, "0: buffer.copyToChannel(null, 0)")
148 Should("1: buffer.copyToChannel(context, 0)", function () { 160 .throw("TypeError");
149 buffer.copyToChannel(context, 0); 161 should(() => {
150 }).throw("TypeError"); 162 buffer.copyToChannel(context, 0);
151 Should("2: buffer.copyToChannel(x, -1)", function () { 163 }, "1: buffer.copyToChannel(context, 0)")
152 buffer.copyToChannel(x, -1); 164 .throw("TypeError");
153 }).throw("IndexSizeError"); 165 should(() => {
154 Should("3: buffer.copyToChannel(x, " + numberOfChannels + ")", function () { 166 buffer.copyToChannel(x, -1);
155 buffer.copyToChannel(x, numberOfChannels); 167 }, "2: buffer.copyToChannel(x, -1)")
156 }).throw("IndexSizeError"); 168 .throw("IndexSizeError");
157 Should("4: buffer.copyToChannel(x, 0, -1)", function () { 169 should(() => {
158 buffer.copyToChannel(x, 0, -1); 170 buffer.copyToChannel(x, numberOfChannels);
159 }).throw("IndexSizeError"); 171 }, "3: buffer.copyToChannel(x, " + numberOfChannels + ")")
160 Should("5: buffer.copyToChannel(x, 0, " + bufferLength + ")", function ( ) { 172 .throw("IndexSizeError");
161 buffer.copyToChannel(x, 0, bufferLength); 173 should(() => {
162 }).throw("IndexSizeError"); 174 buffer.copyToChannel(x, 0, -1);
175 }, "4: buffer.copyToChannel(x, 0, -1)")
176 .throw("IndexSizeError");
177 should(() => {
178 buffer.copyToChannel(x, 0, bufferLength);
179 }, "5: buffer.copyToChannel(x, 0, " + bufferLength + ")")
180 .throw("IndexSizeError");
163 181
164 Should("6: buffer.copyToChannel(x, 3)", function () { 182 should(() => {
165 buffer.copyToChannel(x, 3); 183 buffer.copyToChannel(x, 3);
166 }).throw("IndexSizeError"); 184 }, "6: buffer.copyToChannel(x, 3)")
185 .throw("IndexSizeError");
167 186
168 done(); 187 task.done();
169 }); 188 });
170 189
171 // Test copyFromChannel 190 // Test copyFromChannel
172 audit.defineTask("copyFrom-validate", function (done) { 191 audit.define("copyFrom-validate", (task, should) => {
173 // Initialize the AudioBuffer to a ramp for testing copyFrom. 192 // Initialize the AudioBuffer to a ramp for testing copyFrom.
174 initializeAudioBufferRamp(buffer); 193 initializeAudioBufferRamp(buffer);
175 194
176 // Test copyFrom operation with a short destination array, filling the d estination completely. 195 // Test copyFrom operation with a short destination array, filling the d estination completely.
177 for (var c = 0; c < numberOfChannels; ++c) { 196 for (var c = 0; c < numberOfChannels; ++c) {
178 var dst8 = createInitializedF32Array(8); 197 var dst8 = createInitializedF32Array(8);
179 buffer.copyFromChannel(dst8, c); 198 buffer.copyFromChannel(dst8, c);
180 shouldBeRamp("buffer.copyFromChannel(dst8, " + c + ")", dst8, c + 1, 8 ) 199 shouldBeRamp(should, "buffer.copyFromChannel(dst8, " + c + ")", dst8, c + 1, 8)
181 } 200 }
182 201
183 // Test copyFrom operation with a short destination array using a non-ze ro start index that 202 // Test copyFrom operation with a short destination array using a non-ze ro start index that
184 // still fills the destination completely. 203 // still fills the destination completely.
185 for (var c = 0; c < numberOfChannels; ++c) { 204 for (var c = 0; c < numberOfChannels; ++c) {
186 var dst8 = createInitializedF32Array(8); 205 var dst8 = createInitializedF32Array(8);
187 buffer.copyFromChannel(dst8, c, 1); 206 buffer.copyFromChannel(dst8, c, 1);
188 shouldBeRamp("buffer.copyFromChannel(dst8, " + c + ", 1)", dst8, c + 2 , 8) 207 shouldBeRamp(should, "buffer.copyFromChannel(dst8, " + c + ", 1)", dst 8, c + 2, 8)
189 } 208 }
190 209
191 // Test copyFrom operation with a short destination array using a non-ze ro start index that 210 // Test copyFrom operation with a short destination array using a non-ze ro start index that
192 // does not fill the destinatiom completely. The extra elements should be unchanged. 211 // does not fill the destinatiom completely. The extra elements should be unchanged.
193 for (var c = 0; c < numberOfChannels; ++c) { 212 for (var c = 0; c < numberOfChannels; ++c) {
194 var dst8 = createInitializedF32Array(8); 213 var dst8 = createInitializedF32Array(8);
195 var startInChannel = bufferLength - 5; 214 var startInChannel = bufferLength - 5;
196 buffer.copyFromChannel(dst8, c, startInChannel); 215 buffer.copyFromChannel(dst8, c, startInChannel);
197 shouldBeRamp("buffer.copyFromChannel(dst8, " + c + ", " + startInChann el + ")", dst8, 216 shouldBeRamp(should, "buffer.copyFromChannel(dst8, " + c + ", " + star tInChannel + ")", dst8,
198 c + 1 + startInChannel, bufferLength - startInChannel); 217 c + 1 + startInChannel, bufferLength - startInChannel);
199 } 218 }
200 219
201 // Copy operation with the destination longer than the buffer, leaving t he trailing elements 220 // Copy operation with the destination longer than the buffer, leaving t he trailing elements
202 // of the destination untouched. 221 // of the destination untouched.
203 for (var c = 0; c < numberOfChannels; ++c) { 222 for (var c = 0; c < numberOfChannels; ++c) {
204 var dst26 = createInitializedF32Array(bufferLength + 10); 223 var dst26 = createInitializedF32Array(bufferLength + 10);
205 buffer.copyFromChannel(dst26, c); 224 buffer.copyFromChannel(dst26, c);
206 shouldBeRamp("buffer.copyFromChannel(dst26, " + c + ")", dst26, 225 shouldBeRamp(should, "buffer.copyFromChannel(dst26, " + c + ")", dst26 ,
207 c + 1, bufferLength); 226 c + 1, bufferLength);
208 } 227 }
209 228
210 done(); 229 task.done();
211 }); 230 });
212 231
213 // Test copyTo 232 // Test copyTo
214 audit.defineTask("copyTo-validate", function (done) { 233 audit.define("copyTo-validate", (task, should) => {
215 // Create a source consisting of a ramp starting at 1, longer than the A udioBuffer 234 // Create a source consisting of a ramp starting at 1, longer than the A udioBuffer
216 var src = createFloat32RampArray(bufferLength + 10); 235 var src = createFloat32RampArray(bufferLength + 10);
217 236
218 // Test copyTo with AudioBuffer shorter than Float32Array. The AudioBuff er should be 237 // Test copyTo with AudioBuffer shorter than Float32Array. The AudioBuff er should be
219 // completely filled with the Float32Array. 238 // completely filled with the Float32Array.
220 Should("buffer = createConstantBuffer(context, " + bufferLength + ", [" + initialValues+ "])", 239 should(() => {
221 function () { 240 buffer = createConstantBuffer(context, bufferLength,
222 buffer = createConstantBuffer(context, bufferLength, initialValues); 241 initialValues);
223 }).notThrow();; 242 },
243 "buffer = createConstantBuffer(context, " + bufferLength + ", [" +
244 initialValues + "])")
245 .notThrow();
224 246
225 for (var c = 0; c < numberOfChannels; ++c) { 247 for (var c = 0; c < numberOfChannels; ++c) {
226 buffer.copyToChannel(src, c); 248 buffer.copyToChannel(src, c);
227 shouldBeRamp("buffer.copyToChannel(src, " + c + ")", buffer.getChannel Data(c), 1, bufferLength); 249 shouldBeRamp(should, "buffer.copyToChannel(src, " + c + ")",
250 buffer.getChannelData(c), 1, bufferLength);
228 } 251 }
229 252
230 // Test copyTo with AudioBuffer longer than the Float32Array. The tail of the AudioBuffer 253 // Test copyTo with AudioBuffer longer than the Float32Array. The tail of the AudioBuffer
231 // should be unchanged. 254 // should be unchanged.
232 buffer = createConstantBuffer(context, bufferLength, initialValues); 255 buffer = createConstantBuffer(context, bufferLength, initialValues);
233 var src10 = createFloat32RampArray(10); 256 var src10 = createFloat32RampArray(10);
234 for (var c = 0; c < numberOfChannels; ++c) { 257 for (var c = 0; c < numberOfChannels; ++c) {
235 buffer.copyToChannel(src10, c); 258 buffer.copyToChannel(src10, c);
236 shouldBeRamp("buffer.copyToChannel(src10, " + c + ")", buffer.getChann elData(c), 1, 10); 259 shouldBeRamp(should, "buffer.copyToChannel(src10, " + c + ")",
260 buffer.getChannelData(c), 1, 10);
237 } 261 }
238 262
239 // Test copyTo with non-default startInChannel. Part of the AudioBuffer should filled with 263 // Test copyTo with non-default startInChannel. Part of the AudioBuffer should filled with
240 // the beginning and end sections untouched. 264 // the beginning and end sections untouched.
241 buffer = createConstantBuffer(context, bufferLength, initialValues); 265 buffer = createConstantBuffer(context, bufferLength, initialValues);
242 for (var c = 0; c < numberOfChannels; ++c) { 266 for (var c = 0; c < numberOfChannels; ++c) {
243 var startInChannel = 5; 267 var startInChannel = 5;
244 buffer.copyToChannel(src10, c, startInChannel); 268 buffer.copyToChannel(src10, c, startInChannel);
245 269
246 shouldBeRamp("buffer.copyToChannel(src10, " + c + ", " + startInChanne l + ")", 270 shouldBeRamp(should, "buffer.copyToChannel(src10, " + c + ", " +
271 startInChannel + ")",
247 buffer.getChannelData(c), 1, src10.length, startInChannel); 272 buffer.getChannelData(c), 1, src10.length, startInChannel);
248 } 273 }
249 274
250 done(); 275 task.done();
251 }); 276 });
252 277
253 audit.defineTask("finish", function (done) { 278 audit.run();
254 done();
255 });
256
257 audit.runTasks(
258 "initialize",
259 "copyFrom-exceptions",
260 "copyTo-exceptions",
261 "copyFrom-validate",
262 "copyTo-validate",
263 "finish"
264 );
265
266 successfullyParsed = true;
267
268 </script> 279 </script>
269 280
270 </body> 281 </body>
271 </html> 282 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-getChannelData.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698